aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/FlatCostFunction.java
blob: ce2a75bd569b12879db4190705590819ed024ebf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.store.query.viatra.internal.localsearch;

import tools.refinery.viatra.runtime.localsearch.planner.cost.IConstraintEvaluationContext;
import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.StatisticsBasedConstraintCostFunction;
import tools.refinery.viatra.runtime.matchers.context.IInputKey;
import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.TypeConstraint;
import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
import tools.refinery.viatra.runtime.matchers.util.Accuracy;

import java.util.Optional;

public class FlatCostFunction extends StatisticsBasedConstraintCostFunction {
	public FlatCostFunction() {
		// No inverse navigation penalty thanks to relational storage.
		super(0);
	}

	@Override
	public Optional<Long> projectionSize(IConstraintEvaluationContext input, IInputKey supplierKey, TupleMask groupMask, Accuracy requiredAccuracy) {
		// We always start from an empty model, where every projection is of size 0.
		// Therefore, projection size estimation is meaningless.
		return Optional.empty();
	}

	@Override
	protected double _calculateCost(TypeConstraint constraint, IConstraintEvaluationContext input) {
		// Assume a flat cost for each relation. Maybe adjust in the future if we perform indexing?
		return DEFAULT_COST;
	}
}