Class OptimizationProblem
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- java.util.HashSet<OptProbElement>
-
- org.tweetyproject.math.opt.problem.GeneralConstraintSatisfactionProblem
-
- org.tweetyproject.math.opt.problem.ConstraintSatisfactionProblem
-
- org.tweetyproject.math.opt.problem.OptimizationProblem
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<OptProbElement>,java.util.Collection<OptProbElement>,java.util.Set<OptProbElement>
public class OptimizationProblem extends ConstraintSatisfactionProblem
This class models a general optimization problem.- Author:
- Matthias Thimm
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description OptimizationProblem()Creates an empty optimization problem.OptimizationProblem(int type)Creates an empty optimization problem of the given type.
-
Method Summary
Modifier and Type Method Description OptimizationProblemclone()voidcollapseAssociativeOperations()This method collapses all associative operations appearing in the target function and the constraints, e.g.java.lang.StringconvertToCplexLpFormat()Converts the this optimization problem into a string in the commonly used CPLEX LP-format for mixed integer linear programming.java.lang.StringconvertToLpFormat()Converts the this optimization problem into a string in the commonly used LP-format for mixed integer linear programming.java.util.Set<Minimum>getMinimums()Returns all minimums appearing in this problem.TermgetTargetFunction()Returns the target function of this problem.intgetType()Returns the type of this problem.java.util.Set<Variable>getVariables()Returns all variables of this problem.booleanisLinear()Checks whether every constraint of this problem is linear.booleanisMinimumFree()Checks whether this problem uses no minimum function.booleanisTargetLinear()Checks whether the target function is linear.voidresolveAbsoluteValues()Resolves all occurrences of absolute values "abs(X)" by replacing "abs(X)" by a new variable "TMPABS" adding constraints "TMPABS - X>= 0" and "TMPABS + X >= 0" (yielding "TMPABS <= abs(X)") introducing a new variable "TMPABSB" adding constraints "X+PENALTY*TMPABSB - TMPABS >= 0" and "-X-TMPABSB*PENALTY - TMPABS >= -PENALTY" (yielding "TMPABS >= abs(X)") adding constraints "TMPABSB<=1"voidresolveMaximums()Resolves all occurrences of maximums by substituting a maximum "max{a,b}" by "0.5 a + 0.5 b + abs(a-b)".voidresolveMinimums()Resolves all occurrences of minimums by substituting a minimum "min{a,b}" by "0.5 a + 0.5 b - abs(a-b)".voidsetPenalty(int penalty)Sets the penalty for violated minimum.voidsetTargetFunction(Term targetFunction)Sets the target function of this problem.voidsetType(int type)Sets the type of this problem, either OptimizationProblem.MINIMIZE or OptimizationProblem.MAXIMIZE.java.lang.StringtoString()-
Methods inherited from class org.tweetyproject.math.opt.problem.ConstraintSatisfactionProblem
isInteger, toNormalizedForm
-
Methods inherited from class java.util.HashSet
add, clear, contains, isEmpty, iterator, remove, size, spliterator
-
-
-
-
Field Detail
-
EPSILON
public static final double EPSILON
Some value to represent a very small number- See Also:
- Constant Field Values
-
MINIMIZE
public static final int MINIMIZE
Static constant for the type "minimization"- See Also:
- Constant Field Values
-
MAXIMIZE
public static final int MAXIMIZE
Static constant for the type "maximization"- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OptimizationProblem
public OptimizationProblem()
Creates an empty optimization problem.
-
OptimizationProblem
public OptimizationProblem(int type)
Creates an empty optimization problem of the given type.- Parameters:
type- the type of the problem; either OptimizationProblem.MINIMIZE or OptimizationProblem.MAXIMIZE.
-
-
Method Detail
-
setTargetFunction
public void setTargetFunction(Term targetFunction)
Sets the target function of this problem.- Parameters:
targetFunction- a term.
-
isTargetLinear
public boolean isTargetLinear()
Checks whether the target function is linear.- Returns:
- "true" if the target function is linear.
-
isLinear
public boolean isLinear()
Description copied from class:ConstraintSatisfactionProblemChecks whether every constraint of this problem is linear.- Overrides:
isLinearin classConstraintSatisfactionProblem- Returns:
- "true" if every constraint of this problem is linear.
-
isMinimumFree
public boolean isMinimumFree()
Description copied from class:ConstraintSatisfactionProblemChecks whether this problem uses no minimum function.- Overrides:
isMinimumFreein classConstraintSatisfactionProblem- Returns:
- "true" if this problem uses no minimum function.
-
resolveMinimums
public void resolveMinimums()
Description copied from class:ConstraintSatisfactionProblemResolves all occurrences of minimums by substituting a minimum "min{a,b}" by "0.5 a + 0.5 b - abs(a-b)".- Overrides:
resolveMinimumsin classConstraintSatisfactionProblem
-
resolveMaximums
public void resolveMaximums()
Description copied from class:ConstraintSatisfactionProblemResolves all occurrences of maximums by substituting a maximum "max{a,b}" by "0.5 a + 0.5 b + abs(a-b)".- Overrides:
resolveMaximumsin classConstraintSatisfactionProblem
-
resolveAbsoluteValues
public void resolveAbsoluteValues()
Resolves all occurrences of absolute values "abs(X)" by- replacing "abs(X)" by a new variable "TMPABS"
- adding constraints "TMPABS - X>= 0" and "TMPABS + X >= 0" (yielding "TMPABS <= abs(X)")
- introducing a new variable "TMPABSB"
- adding constraints "X+PENALTY*TMPABSB - TMPABS >= 0" and "-X-TMPABSB*PENALTY - TMPABS >= -PENALTY" (yielding "TMPABS >= abs(X)")
- adding constraints "TMPABSB<=1"
-
convertToLpFormat
public java.lang.String convertToLpFormat()
Converts the this optimization problem into a string in the commonly used LP-format for mixed integer linear programming.- Returns:
- A string representing this problem in LP-format
-
convertToCplexLpFormat
public java.lang.String convertToCplexLpFormat()
Converts the this optimization problem into a string in the commonly used CPLEX LP-format for mixed integer linear programming.- Returns:
- A string representing this problem in CPLEX LP-format
-
getVariables
public java.util.Set<Variable> getVariables()
Description copied from class:ConstraintSatisfactionProblemReturns all variables of this problem.- Overrides:
getVariablesin classConstraintSatisfactionProblem- Returns:
- all variables of this problem.
-
getMinimums
public java.util.Set<Minimum> getMinimums()
Description copied from class:ConstraintSatisfactionProblemReturns all minimums appearing in this problem.- Overrides:
getMinimumsin classConstraintSatisfactionProblem- Returns:
- all minimums appearing in this problem.
-
collapseAssociativeOperations
public void collapseAssociativeOperations()
Description copied from class:ConstraintSatisfactionProblemThis method collapses all associative operations appearing in the target function and the constraints, e.g. every min{min{a,b},c} becomes min{a,b,c}- Overrides:
collapseAssociativeOperationsin classConstraintSatisfactionProblem
-
setType
public void setType(int type)
Sets the type of this problem, either OptimizationProblem.MINIMIZE or OptimizationProblem.MAXIMIZE.- Parameters:
type- the type of this problem.
-
setPenalty
public void setPenalty(int penalty)
Sets the penalty for violated minimum.- Parameters:
penalty- some penalty
-
getType
public int getType()
Returns the type of this problem.- Returns:
- the type of this problem.
-
getTargetFunction
public Term getTargetFunction()
Returns the target function of this problem.- Returns:
- the target function of this problem.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classConstraintSatisfactionProblem
-
clone
public OptimizationProblem clone()
- Overrides:
clonein classConstraintSatisfactionProblem
-
-