Package com.opttek.optquest
Class COptQuestConstraint
java.lang.Object
com.opttek.optquest.COptQuestConstraint
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
COptQuestEQConstraint
,COptQuestGEConstraint
,COptQuestLEConstraint
COptQuestConstraint is a pure virtual class that defines a linear constraint.
-
Constructor Summary
ConstructorDescriptionDefault constructorCOptQuestConstraint
(double rhs) Constructor that assigns a value for the right hand side.COptQuestConstraint
(String name, double rhs) Constructor that assigns a name and value for the right hand side. -
Method Summary
Modifier and TypeMethodDescriptionvoid
AddVariable
(COptQuestVariable variable, double coefficient) Adds a variable and its coefficient to the linear expression.void
ChangeVariableCoefficient
(COptQuestVariable findVar, double coefficient) Changes the coefficient of the variable to the value specified by the input parameter.clone()
double
GetCoefficientAt
(int index) Returns the coefficient at the specified 0 based index.double
Evaluate the left side of the constraint and return the valueGetName()
Returns the name assigned to the constraint.int
Returns the number of variables that were added to the constraint by calls to the AddVariable() method.double
GetRHS()
Returns the right hand side value.GetVariableAt
(int index) Returns the COptQuestVariable at the specified 0 based index.void
RemoveVariable
(COptQuestVariable variable) Modifies the constraint by removing the variable.void
Assigns a name to the constraint.void
SetRHS
(double val) Sets the right hand side value of a linear constraint.void
SetTolerance
(double tolerance) Set the tolerance per variable for the constraint
-
Constructor Details
-
COptQuestConstraint
public COptQuestConstraint()Default constructor -
COptQuestConstraint
Constructor that assigns a name and value for the right hand side.- Parameters:
name
- - Alpha numeric constraint name.rhs
- - right hand side value for the constraint.
-
COptQuestConstraint
public COptQuestConstraint(double rhs) Constructor that assigns a value for the right hand side.- Parameters:
rhs
- - right hand side value for the constraint.
-
-
Method Details
-
clone
-
AddVariable
Adds a variable and its coefficient to the linear expression. This method is called for each variable that is used in the left hand side expression. For example, the constraint 2*Var1 + 3*Var2 + 1.5*Var3 ≤ 100 would call AddVariable(Var1,2), AddVariable(Var2, 3) and AddVariable(Var3,1.5).- Parameters:
variable
- - COptQuestVariable object that is in the linear expressioncoefficient
- - coefficient of the variable- Throws:
COptQuestException
- if variable type not valid for constraint
-
RemoveVariable
Modifies the constraint by removing the variable. -
GetNumberOfVariables
public int GetNumberOfVariables()Returns the number of variables that were added to the constraint by calls to the AddVariable() method.- Returns:
- count of the number of variables in the left hand side of the linear expression.
-
GetVariableAt
Returns the COptQuestVariable at the specified 0 based index. For example, the constraint 2*Var1 + 3*Var2 + 1.5*Var3 ≤ 100 called AddVariable(Var1,2), AddVariable(Var2, 3) and AddVariable(Var3,1.5). GetVariableAt(1) would return the COptQuestVariable object for Var2.- Parameters:
index
- 0 based index- Returns:
- COptQuestVariable at the specified index
-
ChangeVariableCoefficient
Changes the coefficient of the variable to the value specified by the input parameter.- Parameters:
findVar
- - variable to changecoefficient
- - new coefficient value
-
GetCoefficientAt
public double GetCoefficientAt(int index) Returns the coefficient at the specified 0 based index. For example, the constraint 2*Var1 + 3*Var2 + 1.5*Var3 ≤ 100 called AddVariable(Var1,2), AddVariable(Var2, 3) and AddVariable(Var3,1.5). GetCoefficientAt(1) would return 3, the coefficient for Var2.- Parameters:
index
- 0 based index- Returns:
- coefficient at the specified index
-
SetRHS
public void SetRHS(double val) Sets the right hand side value of a linear constraint.- Parameters:
val
- - right hand side value
-
GetRHS
public double GetRHS()Returns the right hand side value. The default value is 0.0.- Returns:
- the right hand side value.
-
GetName
Returns the name assigned to the constraint. Returns an empty string if the constraint is not named.- Returns:
- the name assigned to the constraint
-
GetLHSValue
Evaluate the left side of the constraint and return the value- Parameters:
sol
- - solution to be used for evaluation- Returns:
- - value of the left hand side.
-
SetName
Assigns a name to the constraint. Names must be alphanumeric and cannot be a function name recognized by the COptQuestEquationSolver.- Parameters:
value
- = name of the variable.
-
SetTolerance
public void SetTolerance(double tolerance) Set the tolerance per variable for the constraint
-