org.eclipse.viatra.dse.objectives.impl

## Class ConstraintsObjective

- java.lang.Object
- - org.eclipse.viatra.dse.objectives.impl.BaseObjective
  - - org.eclipse.viatra.dse.objectives.impl.ConstraintsObjective

- All Implemented Interfaces:
    IObjective

      public class ConstraintsObjective
      extends BaseObjective

  This objective serves as soft and as hard objective at the same time by defining two lists of VIATRA Query specifications. As a soft objective, it collects a list of VIATRA Query specifications, which have predefined weights. Then the fitness value of an arbitrary solution is calculated in the following way:

  `fitness = sum( pattern[i].countMatches() * weight[i] )`

  As a hard objective it collects a separate list of VIATRA Query specifications. If every one of them has a match the hard constraint is considered to be fulfilled.

  See Also:
    `IObjective`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ConstraintsObjective.QueryConstraint`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `DEFAULT_NAME`
    `protected java.util.List<ConstraintsObjective.QueryConstraint>` | `hardConstraints`
    `protected java.util.List<ViatraQueryMatcher<? extends IPatternMatch>>` | `hardMatchers`
    `protected java.util.List<java.lang.Integer>` | `hardMatches`
    `protected java.util.List<ConstraintsObjective.QueryConstraint>` | `softConstraints`
    `protected java.util.List<ViatraQueryMatcher<? extends IPatternMatch>>` | `softMatchers`
    `protected java.util.List<java.lang.Integer>` | `softMatches`

    - ### Fields inherited from class org.eclipse.viatra.dse.objectives.impl.BaseObjective

      `comparator, fitnessConstraint, fitnessConstraintComparator, isThereFitnessConstraint, level, name`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConstraintsObjective()`
    `ConstraintsObjective(java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints)`
    `ConstraintsObjective(java.lang.String name)`
    `ConstraintsObjective(java.lang.String name, java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints)`
    `ConstraintsObjective(java.lang.String name, java.util.List<ConstraintsObjective.QueryConstraint> softConstraints, java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `IObjective` | `createNew()` Returns an instance of the `IObjective`.
    `java.lang.Double` | `getFitness(ThreadContext context)` Calculates the value of the objective on a given solution (trajectory).
    `java.util.List<ConstraintsObjective.QueryConstraint>` | `getHardConstraints()`
    `java.util.List<java.lang.Integer>` | `getHardMatches()`
    `java.lang.String` | `getHardName(int index)`
    `java.util.List<ConstraintsObjective.QueryConstraint>` | `getSoftConstraints()`
    `java.util.List<java.lang.Integer>` | `getSoftMatches()`
    `java.lang.String` | `getSoftName(int index)`
    `java.util.List<java.lang.String>` | `getSoftNames()`
    `void` | `init(ThreadContext context)` Initializes the objective.
    `boolean` | `isHardObjective()` Returns true if the objective is a hard objective.
    `boolean` | `satisifiesHardObjective(java.lang.Double fitness)` Determines if the given fitness value satisfies the hard objective.
    `ConstraintsObjective` | `withHardConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint)` Adds a new hard constraint with the name of the query specification's fully qualified name and the default `ModelQueryType.MUST_HAVE_MATCH`.
    `ConstraintsObjective` | `withHardConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint, ModelQueryType type)` Adds a new hard constraint with the name of the query specification's fully qualified name.
    `ConstraintsObjective` | `withHardConstraint(java.lang.String name, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint)` Adds a new hard constraint with the default `ModelQueryType.MUST_HAVE_MATCH`.
    `ConstraintsObjective` | `withHardConstraint(java.lang.String name, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint, ModelQueryType type)` Adds a new hard constraint.
    `ConstraintsObjective` | `withSoftConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> softConstraint, double weight)` Adds a new soft constraint with the name of the query specification's fully qualified name.
    `ConstraintsObjective` | `withSoftConstraint(java.lang.String name, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> softConstraint, double weight)` Adds a new soft constraint.

    - ### Methods inherited from class org.eclipse.viatra.dse.objectives.impl.BaseObjective

      `equals, getComparator, getLevel, getName, hashCode, setComparator, setLevel, toString, withComparator, withHardConstraintOnFitness, withHardConstraintOnFitness, withLevel`

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_NAME

          public static final java.lang.String DEFAULT_NAME

      See Also:
        Constant Field Values

    - #### softConstraints

          protected java.util.List<ConstraintsObjective.QueryConstraint> softConstraints

    - #### hardConstraints

          protected java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints

    - #### softMatchers

          protected java.util.List<ViatraQueryMatcher<? extends IPatternMatch>> softMatchers

    - #### hardMatchers

          protected java.util.List<ViatraQueryMatcher<? extends IPatternMatch>> hardMatchers

    - #### softMatches

          protected java.util.List<java.lang.Integer> softMatches

    - #### hardMatches

          protected java.util.List<java.lang.Integer> hardMatches

  - ### Constructor Detail

    - #### ConstraintsObjective

          public ConstraintsObjective(java.lang.String name,
                                      java.util.List<ConstraintsObjective.QueryConstraint> softConstraints,
                                      java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints)

    - #### ConstraintsObjective

          public ConstraintsObjective(java.lang.String name,
                                      java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints)

    - #### ConstraintsObjective

          public ConstraintsObjective(java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints)

    - #### ConstraintsObjective

          public ConstraintsObjective(java.lang.String name)

    - #### ConstraintsObjective

          public ConstraintsObjective()

  - ### Method Detail

    - #### withSoftConstraint

          public ConstraintsObjective withSoftConstraint(java.lang.String name,
                                                         IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> softConstraint,
                                                         double weight)

      Adds a new soft constraint.
      Parameters:
        `name` - A name for the soft constraint.
        `softConstraint` - A VIATRA Query pattern specification.
        `weight` - The weight of the pattern.
      Returns:
        The actual instance to enable builder pattern like usage.

    - #### withSoftConstraint

          public ConstraintsObjective withSoftConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> softConstraint,
                                                         double weight)

      Adds a new soft constraint with the name of the query specification's fully qualified name.
      Parameters:
        `softConstraint` - A VIATRA Query pattern specification.
        `weight` - The weight of the pattern.
      Returns:
        The actual instance to enable builder pattern like usage.

    - #### withHardConstraint

          public ConstraintsObjective withHardConstraint(java.lang.String name,
                                                         IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint,
                                                         ModelQueryType type)

      Adds a new hard constraint.
      Parameters:
        `name` - A name for the hard constraint.
        `softConstraint` - A VIATRA Query pattern specification.
        `type` - `ModelQueryType`, which determines whether the constraint should have at least one match or none at all.
      Returns:
        The actual instance to enable builder pattern like usage.

    - #### withHardConstraint

          public ConstraintsObjective withHardConstraint(java.lang.String name,
                                                         IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint)

      Adds a new hard constraint with the default `ModelQueryType.MUST_HAVE_MATCH`.
      Parameters:
        `name` - A name for the hard constraint.
        `softConstraint` - A VIATRA Query pattern specification.
      Returns:
        The actual instance to enable builder pattern like usage.

    - #### withHardConstraint

          public ConstraintsObjective withHardConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint)

      Adds a new hard constraint with the name of the query specification's fully qualified name and the default `ModelQueryType.MUST_HAVE_MATCH`.
      Parameters:
        `softConstraint` - A VIATRA Query pattern specification.
      Returns:
        The actual instance to enable builder pattern like usage.

    - #### withHardConstraint

          public ConstraintsObjective withHardConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint,
                                                         ModelQueryType type)

      Adds a new hard constraint with the name of the query specification's fully qualified name.
      Parameters:
        `softConstraint` - A VIATRA Query pattern specification.
        `type` - `ModelQueryType`, which determines whether the constraint should have at least one match or none at all.
      Returns:
        The actual instance to enable builder pattern like usage.

    - #### getFitness

          public java.lang.Double getFitness(ThreadContext context)

      Description copied from interface: `IObjective`
      Calculates the value of the objective on a given solution (trajectory).
      Parameters:
        `context` - The `ThreadContext`
      Returns:
        The objective value in double.

    - #### init

          public void init(ThreadContext context)

      Description copied from interface: `IObjective`
      Initializes the objective. It is called exactly once for every thread starts.
      Specified by:
        `init` in interface `IObjective`
      Overrides:
        `init` in class `BaseObjective`
      Parameters:
        `context` - The `ThreadContext`.

    - #### createNew

          public IObjective createNew()

      Description copied from interface: `IObjective`
      Returns an instance of the `IObjective`. If it returns the same instance, all the methods has to be thread save as they are called concurrently.
      Returns:
        An instance of the objective.

    - #### isHardObjective

          public boolean isHardObjective()

      Description copied from interface: `IObjective`
      Returns true if the objective is a hard objective. In such a case the method `IObjective.satisifiesHardObjective(Double)` is called.
      Specified by:
        `isHardObjective` in interface `IObjective`
      Overrides:
        `isHardObjective` in class `BaseObjective`
      Returns:
        True if the objective is a hard objective.
      See Also:
        `IObjective.satisifiesHardObjective(Double)`, `IObjective`

    - #### satisifiesHardObjective

          public boolean satisifiesHardObjective(java.lang.Double fitness)

      Description copied from interface: `IObjective`
      Determines if the given fitness value satisfies the hard objective.
      Specified by:
        `satisifiesHardObjective` in interface `IObjective`
      Overrides:
        `satisifiesHardObjective` in class `BaseObjective`
      Parameters:
        `fitness` - The fitness value of a solution.
      Returns:
        True if it satisfies the hard objective or it is a soft constraint.
      See Also:
        `IObjective`

    - #### getSoftConstraints

          public java.util.List<ConstraintsObjective.QueryConstraint> getSoftConstraints()

    - #### getHardConstraints

          public java.util.List<ConstraintsObjective.QueryConstraint> getHardConstraints()

    - #### getSoftName

          public java.lang.String getSoftName(int index)

    - #### getHardName

          public java.lang.String getHardName(int index)

    - #### getSoftMatches

          public java.util.List<java.lang.Integer> getSoftMatches()

    - #### getHardMatches

          public java.util.List<java.lang.Integer> getHardMatches()

    - #### getSoftNames

          public java.util.List<java.lang.String> getSoftNames()