Class SumOfConstraintsPenaltyFunction

java.lang.Object
org.moeaframework.core.penalty.SumOfConstraintsPenaltyFunction
All Implemented Interfaces:
PenaltyFunction

public class SumOfConstraintsPenaltyFunction extends Object implements PenaltyFunction
Penalty function based on a fixed offset plus the sum of constraint violations.
  • Constructor Details

    • SumOfConstraintsPenaltyFunction

      public SumOfConstraintsPenaltyFunction()
      Constructs a new penalty function based on the sum of constraint violations.
    • SumOfConstraintsPenaltyFunction

      public SumOfConstraintsPenaltyFunction(double offset)
      Constructs a new penalty function based on the sum of constraint violations.
      Parameters:
      offset - the base offset applied to all penalties
  • Method Details

    • setOffset

      public void setOffset(double offset)
      Sets the base penalty applied to all infeasible solutions.
      Parameters:
      offset - the base offset applied to all penalties
    • getOffset

      public double getOffset()
      Returns the base penalty applied to all infeasible solutions.
      Returns:
      the base offset applied to all penalties
    • calculate

      public double calculate(Solution solution)
      Description copied from interface: PenaltyFunction
      Calculates the penalty for the given solution. In addition to returning the value to the caller, this method also sets the Penalty attribute on the solution.

      Calling this method does not alter the objectives or constraints of the solution. It is the responsibility of the caller to use the penalty value, such as during selection. We encourage implementations to return a value of 0.0 for feasible solutions and > 0.0 for solutions violating constraints.

      Specified by:
      calculate in interface PenaltyFunction
      Parameters:
      solution - the solution
      Returns:
      the penalty for the solution