org.eclipse.viatra.dse.objectives.impl

## Class BaseObjective

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

- All Implemented Interfaces:
    IObjective
  Direct Known Subclasses:
    AlwaysSatisfiedDummyHardObjective, CompositeObjective, ConstraintsObjective, DepthHardObjective, NeverSatisfiedDummyHardObjective, NoRuleActivationsHardObjective, TrajectoryCostSoftObjective

      public abstract class BaseObjective
      extends java.lang.Object
      implements IObjective

  This abstract class implements the basic functionality of an objective (`IObjective` namely its name, comparator, level and fitness hard constraint.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Comparator<java.lang.Double>` | `comparator`
    `protected double` | `fitnessConstraint`
    `protected java.util.Comparator<java.lang.Double>` | `fitnessConstraintComparator`
    `protected boolean` | `isThereFitnessConstraint`
    `protected int` | `level`
    `protected java.lang.String` | `name`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BaseObjective(java.lang.String name)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(java.lang.Object obj)`
    `java.util.Comparator<java.lang.Double>` | `getComparator()` Returns a `Comparator` which is used to compare fitness (doubles).
    `int` | `getLevel()` Gets the level of the objective.
    `java.lang.String` | `getName()` Returns the name of the objective.
    `int` | `hashCode()`
    `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.
    `void` | `setComparator(java.util.Comparator<java.lang.Double> comparator)` Sets the `Comparator` which is used to compare fitness (doubles).
    `void` | `setLevel(int level)` Set the level of the objective.
    `java.lang.String` | `toString()`
    `BaseObjective` | `withComparator(java.util.Comparator<java.lang.Double> comparator)`
    `BaseObjective` | `withHardConstraintOnFitness(double fitnessConstraint)` Adds a hard constraint on the fitness value.
    `BaseObjective` | `withHardConstraintOnFitness(double fitnessConstraint, java.util.Comparator<java.lang.Double> fitnessConstraintComparator)` Adds a hard constraint on the fitness value.
    `BaseObjective` | `withLevel(int level)`

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

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

    - ### Methods inherited from interface org.eclipse.viatra.dse.objectives.IObjective

      `createNew, getFitness`

- - ### Field Detail

    - #### name

          protected final java.lang.String name

    - #### comparator

          protected java.util.Comparator<java.lang.Double> comparator

    - #### level

          protected int level

    - #### fitnessConstraint

          protected double fitnessConstraint

    - #### isThereFitnessConstraint

          protected boolean isThereFitnessConstraint

    - #### fitnessConstraintComparator

          protected java.util.Comparator<java.lang.Double> fitnessConstraintComparator

  - ### Constructor Detail

    - #### BaseObjective

          public BaseObjective(java.lang.String name)

  - ### Method Detail

    - #### getName

          public java.lang.String getName()

      Description copied from interface: `IObjective`
      Returns the name of the objective.
      Specified by:
        `getName` in interface `IObjective`
      Returns:
        The name of the objective.

    - #### setComparator

          public void setComparator(java.util.Comparator<java.lang.Double> comparator)

      Description copied from interface: `IObjective`
      Sets the `Comparator` which is used to compare fitness (doubles). It determines whether the objective is to minimize or maximize (or minimize or maximize a delta from a given number).
      Specified by:
        `setComparator` in interface `IObjective`
      Parameters:
        `comparator` - The comparator.

    - #### getComparator

          public java.util.Comparator<java.lang.Double> getComparator()

      Description copied from interface: `IObjective`
      Returns a `Comparator` which is used to compare fitness (doubles). It determines whether the objective is to minimize or maximize (or minimize or maximize a delta from a given number).
      Specified by:
        `getComparator` in interface `IObjective`
      Returns:
        The comparator.

    - #### setLevel

          public void setLevel(int level)

      Description copied from interface: `IObjective`
      Set the level of the objective.
      Specified by:
        `setLevel` in interface `IObjective`

    - #### getLevel

          public int getLevel()

      Description copied from interface: `IObjective`
      Gets the level of the objective.
      Specified by:
        `getLevel` in interface `IObjective`

    - #### withLevel

          public BaseObjective withLevel(int level)

    - #### withComparator

          public BaseObjective withComparator(java.util.Comparator<java.lang.Double> comparator)

    - #### withHardConstraintOnFitness

          public BaseObjective withHardConstraintOnFitness(double fitnessConstraint,
                                                           java.util.Comparator<java.lang.Double> fitnessConstraintComparator)

      Adds a hard constraint on the fitness value. For example, the fitness value must be better than 10 to accept the current state as a solution.
      Parameters:
        `fitnessConstraint` - Solutions should be better than this value.
        `fitnessConstraintComparator` - `Comparator` to determine if the current state is better than the given value.
      Returns:
        The actual instance to enable builder pattern like usage.

    - #### withHardConstraintOnFitness

          public BaseObjective withHardConstraintOnFitness(double fitnessConstraint)

      Adds a hard constraint on the fitness value. For example, the fitness value must be better than 10 to accept the current state as a solution. The provided comparator will be used.
      Parameters:
        `fitnessConstraint` - Solutions should be better than this value.
      Returns:
        The actual instance to enable builder pattern like usage.

    - #### 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`
      Parameters:
        `context` - The `ThreadContext`.

    - #### 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`
      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`
      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`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### equals

          public boolean equals(java.lang.Object obj)

      Overrides:
        `equals` in class `java.lang.Object`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`