org.eclipse.viatra.query.runtime.localsearch.planner.cost.impl

## Class StatisticsBasedConstraintCostFunction

- java.lang.Object
- - org.eclipse.viatra.query.runtime.localsearch.planner.cost.impl.StatisticsBasedConstraintCostFunction

- All Implemented Interfaces:
    ICostFunction
  Direct Known Subclasses:
    IndexerBasedConstraintCostFunction

      public abstract class StatisticsBasedConstraintCostFunction
      extends java.lang.Object
      implements ICostFunction

  Cost function which calculates cost based on the cardinality of items in the runtime model

  To provide custom statistics, override `projectionSize(IConstraintEvaluationContext, IInputKey, TupleMask, Accuracy)` and `bucketSize(IQueryReference, IConstraintEvaluationContext, TupleMask)`.

  Since:
    1.4

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static double` | `DEFAULT_COST`
    `static double` | `EVAL_UNWIND_EXTENSION_FACTOR`
    `static double` | `INVERSE_NAVIGATION_PENALTY_DEFAULT`
    `static double` | `INVERSE_NAVIGATION_PENALTY_GENERIC`
    `protected static double` | `MAX_COST`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StatisticsBasedConstraintCostFunction()`
    `StatisticsBasedConstraintCostFunction(double inverseNavigationPenalty)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected double` | `_calculateCost(AggregatorConstraint aggregator, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(BinaryReflexiveTransitiveClosure closure, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(BinaryTransitiveClosure closure, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(ConstantValue constant, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(ExportedParameter exportedParam, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(ExpressionEvaluation evaluation, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(Inequality inequality, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(NegativePatternCall call, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(PatternMatchCounter counter, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(PConstraint constraint, IConstraintEvaluationContext input)` Default cost calculation strategy
    `protected double` | `_calculateCost(PositivePatternCall patternCall, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(TypeConstraint constraint, IConstraintEvaluationContext input)`
    `protected double` | `_calculateCost(TypeFilterConstraint exportedParam, IConstraintEvaluationContext input)`
    `double` | `apply(IConstraintEvaluationContext input)`
    `java.util.Optional<java.lang.Double>` | `bucketSize(IQueryReference patternCall, IConstraintEvaluationContext input, TupleMask projMask)` Override this to provide custom estimates for match set sizes of called patterns.
    `protected double` | `calculateBinaryCost(IInputKey supplierKey, PVariable srcVariable, PVariable dstVariable, boolean isInverse, IConstraintEvaluationContext input)`
    `protected double` | `calculateBinaryExtendCost(IInputKey supplierKey, PVariable srcVariable, PVariable dstVariable, boolean isInverse, long edgeCount, IConstraintEvaluationContext input)` Deprecated. use/implement `calculateBinaryCost(IInputKey, PVariable, PVariable, boolean, IConstraintEvaluationContext)` instead
    `double` | `calculateCost(PConstraint constraint, IConstraintEvaluationContext input)`
    `protected double` | `calculateUnaryConstraintCost(TypeConstraint constraint, IConstraintEvaluationContext input)`
    `long` | `countTuples(IConstraintEvaluationContext input, IInputKey supplierKey)` Deprecated. call and implement `projectionSize(IConstraintEvaluationContext, IInputKey, TupleMask, Accuracy)` instead
    `protected boolean` | `navigatesThroughFunctionalDependency(IConstraintEvaluationContext input, PConstraint constraint)`
    `protected boolean` | `navigatesThroughFunctionalDependency(IConstraintEvaluationContext input, PConstraint constraint, java.util.Collection<PVariable> determining, java.util.Collection<PVariable> determined)`
    `protected boolean` | `navigatesThroughFunctionalDependencyInverse(IConstraintEvaluationContext input, PConstraint constraint)`
    `java.util.Optional<java.lang.Long>` | `projectionSize(IConstraintEvaluationContext input, IInputKey supplierKey, TupleMask groupMask, Accuracy requiredAccuracy)` Override this to provide custom statistics on edge/node counts.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MAX_COST

          protected static final double MAX_COST

      See Also:
        Constant Field Values

    - #### DEFAULT_COST

          protected static final double DEFAULT_COST

      See Also:
        Constant Field Values

    - #### INVERSE_NAVIGATION_PENALTY_DEFAULT

          public static final double INVERSE_NAVIGATION_PENALTY_DEFAULT

      Since:
        2.1
      See Also:
        Constant Field Values

    - #### INVERSE_NAVIGATION_PENALTY_GENERIC

          public static final double INVERSE_NAVIGATION_PENALTY_GENERIC

      Since:
        2.1
      See Also:
        Constant Field Values

    - #### EVAL_UNWIND_EXTENSION_FACTOR

          public static final double EVAL_UNWIND_EXTENSION_FACTOR

      Since:
        2.7
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### StatisticsBasedConstraintCostFunction

          public StatisticsBasedConstraintCostFunction(double inverseNavigationPenalty)

      Since:
        2.1

    - #### StatisticsBasedConstraintCostFunction

          public StatisticsBasedConstraintCostFunction()

  - ### Method Detail

    - #### countTuples

          @Deprecated
          public long countTuples(IConstraintEvaluationContext input,
                                              IInputKey supplierKey)

      Deprecated. call and implement `projectionSize(IConstraintEvaluationContext, IInputKey, TupleMask, Accuracy)` instead

    - #### projectionSize

          public java.util.Optional<java.lang.Long> projectionSize(IConstraintEvaluationContext input,
                                                                   IInputKey supplierKey,
                                                                   TupleMask groupMask,
                                                                   Accuracy requiredAccuracy)

      Override this to provide custom statistics on edge/node counts. New implementors shall implement this instead of `countTuples(IConstraintEvaluationContext, IInputKey)`
      Since:
        2.1

    - #### bucketSize

          public java.util.Optional<java.lang.Double> bucketSize(IQueryReference patternCall,
                                                                 IConstraintEvaluationContext input,
                                                                 TupleMask projMask)

      Override this to provide custom estimates for match set sizes of called patterns.
      Since:
        2.1

    - #### apply

          public double apply(IConstraintEvaluationContext input)

      Specified by:
        `apply` in interface `ICostFunction`

    - #### _calculateCost

          protected double _calculateCost(ConstantValue constant,
                                          IConstraintEvaluationContext input)

    - #### _calculateCost

          protected double _calculateCost(TypeConstraint constraint,
                                          IConstraintEvaluationContext input)

    - #### calculateBinaryExtendCost

          @Deprecated
          protected double calculateBinaryExtendCost(IInputKey supplierKey,
                                                                 PVariable srcVariable,
                                                                 PVariable dstVariable,
                                                                 boolean isInverse,
                                                                 long edgeCount,
                                                                 IConstraintEvaluationContext input)

      Deprecated. use/implement `calculateBinaryCost(IInputKey, PVariable, PVariable, boolean, IConstraintEvaluationContext)` instead

    - #### calculateBinaryCost

          protected double calculateBinaryCost(IInputKey supplierKey,
                                               PVariable srcVariable,
                                               PVariable dstVariable,
                                               boolean isInverse,
                                               IConstraintEvaluationContext input)

      Since:
        2.1

    - #### navigatesThroughFunctionalDependency

          protected boolean navigatesThroughFunctionalDependency(IConstraintEvaluationContext input,
                                                                 PConstraint constraint)

      Since:
        1.7

    - #### navigatesThroughFunctionalDependencyInverse

          protected boolean navigatesThroughFunctionalDependencyInverse(IConstraintEvaluationContext input,
                                                                        PConstraint constraint)

      Since:
        2.1

    - #### navigatesThroughFunctionalDependency

          protected boolean navigatesThroughFunctionalDependency(IConstraintEvaluationContext input,
                                                                 PConstraint constraint,
                                                                 java.util.Collection<PVariable> determining,
                                                                 java.util.Collection<PVariable> determined)

      Since:
        2.1

    - #### calculateUnaryConstraintCost

          protected double calculateUnaryConstraintCost(TypeConstraint constraint,
                                                        IConstraintEvaluationContext input)

    - #### _calculateCost

          protected double _calculateCost(ExportedParameter exportedParam,
                                          IConstraintEvaluationContext input)

    - #### _calculateCost

          protected double _calculateCost(TypeFilterConstraint exportedParam,
                                          IConstraintEvaluationContext input)

    - #### _calculateCost

          protected double _calculateCost(PositivePatternCall patternCall,
                                          IConstraintEvaluationContext input)

    - #### _calculateCost

          protected double _calculateCost(ExpressionEvaluation evaluation,
                                          IConstraintEvaluationContext input)

      Since:
        1.7

    - #### _calculateCost

          protected double _calculateCost(Inequality inequality,
                                          IConstraintEvaluationContext input)

      Since:
        1.7

    - #### _calculateCost

          protected double _calculateCost(AggregatorConstraint aggregator,
                                          IConstraintEvaluationContext input)

      Since:
        1.7

    - #### _calculateCost

          protected double _calculateCost(NegativePatternCall call,
                                          IConstraintEvaluationContext input)

      Since:
        1.7

    - #### _calculateCost

          protected double _calculateCost(PatternMatchCounter counter,
                                          IConstraintEvaluationContext input)

      Since:
        1.7

    - #### _calculateCost

          protected double _calculateCost(BinaryTransitiveClosure closure,
                                          IConstraintEvaluationContext input)

      Since:
        1.7

    - #### _calculateCost

          protected double _calculateCost(BinaryReflexiveTransitiveClosure closure,
                                          IConstraintEvaluationContext input)

      Since:
        2.0

    - #### _calculateCost

          protected double _calculateCost(PConstraint constraint,
                                          IConstraintEvaluationContext input)

      Default cost calculation strategy

    - #### calculateCost

          public double calculateCost(PConstraint constraint,
                                      IConstraintEvaluationContext input)

      Throws:
        `ViatraQueryRuntimeException`