com.opttek.optquest
Class COptQuestStringConstraint

java.lang.Object
  extended bycom.opttek.optquest.COptQuestStringConstraint

public class COptQuestStringConstraint
extends java.lang.Object

The COptQuestStringConstraint class is used to define linear and non-linear constraints using a mathematical expression. For example, "2*Var1 + 3*Var2 + 1.5*Var3 <= 100" could be used to define a budget constraint. "Var1", "Var2" and "Var3" must be names that were assigned to COptQuestVariable objects. If a variable name contains non-alphanumeric characters such as blanks, the names should be enclosed in square brackets in the equation string. For example, "2*[Var 1] + 3*[Var 2] + 1.5*[Var 3] <= 100"

The constraint expression can define an efficient frontier by specifying a comma separated list of right hand side values. For example, "2*Var1 + 3*Var2 + 1.5*Var3 <= 100,200,300"

The following mathematical functions are supported and can be used in the mathematical expression:


Constructor Summary
COptQuestStringConstraint()
          Default constructor
COptQuestStringConstraint(java.lang.String equation)
          Constructor that accepts the string expression that defines the constraint.
COptQuestStringConstraint(java.lang.String name, java.lang.String equation)
          Constructor that assigns a name to the constraint and the string expression that defines the constraint.
 
Method Summary
 boolean GetCheckLinear()
          Returns true if the constraint equation should be checked for linearity.
 java.lang.String GetEquation()
          Returns the mathematical expression of the constraint.
 java.lang.String GetLHSString(int clause)
          Returns the left hand side string expression associated with the clause indicated by the input parameter.
 java.lang.String GetName()
          Returns the constraint name.
 int GetNumberOfClauses()
          Returns the number of clauses in the string equation.
 java.lang.String GetOperatorString(int clause)
          Returns the operator as a string expression for the clause indicated by the input parameter.
 java.lang.String GetRHSString(int clause)
          Returns the right hand side string expression associated with the clause indicated by the input parameter.
 boolean IsAndClauses()
           
 boolean IsLinear()
          Returns true if the expression is linear.
 boolean IsOrClauses()
           
 boolean IsVariable()
          Returns true if the constraint equation defines variable bounds.
 void SetCheckLinear(boolean checkLinear)
          If true, the constraint should be checked for linearity.
 void SetEquation(java.lang.String equation)
          Sets the mathematical expression that defines the constraint.
 void SetName(java.lang.String name)
          Assigns an alphanumeric name to the constraint.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

COptQuestStringConstraint

public COptQuestStringConstraint(java.lang.String name,
                                 java.lang.String equation)
Constructor that assigns a name to the constraint and the string expression that defines the constraint.

Parameters:
name - - alphanumeric name
equation - - linear or non-linear expression defining the constraint

COptQuestStringConstraint

public COptQuestStringConstraint(java.lang.String equation)
Constructor that accepts the string expression that defines the constraint.

Parameters:
equation - - linear or non-linear expression defining the constraint

COptQuestStringConstraint

public COptQuestStringConstraint()
Default constructor

Method Detail

SetName

public void SetName(java.lang.String name)
Assigns an alphanumeric name to the constraint.

Parameters:
name - - alphanumeric string name

GetName

public java.lang.String GetName()
Returns the constraint name.

Returns:
alphanumeric constraint name

SetEquation

public void SetEquation(java.lang.String equation)
Sets the mathematical expression that defines the constraint.

Parameters:
equation - - mathematical expression

GetEquation

public java.lang.String GetEquation()
Returns the mathematical expression of the constraint.

Returns:
- the mathematical expression of the constraint.

SetCheckLinear

public void SetCheckLinear(boolean checkLinear)
If true, the constraint should be checked for linearity. Linear constraints can be evaluated before the Evaluate() method is called and solutions that violate the linear constraint can be rejected. The default value is true.

Parameters:
checkLinear - - true if the mathematical expression should be checked for linearity. False if it should not be checked.

GetCheckLinear

public boolean GetCheckLinear()
Returns true if the constraint equation should be checked for linearity. Returns false if the linearity check has been turned off by calling SetCheckLinear(false)

Returns:
boolean indicating the whether linearity checking is turned on or off.

IsLinear

public boolean IsLinear()
Returns true if the expression is linear. Returns false if it is not. This method should be called after the optmization has started or after calling COptQuestOptmization::ValidateEquation(). IsLinear() will return false if it is called before one of these methods.

Returns:
true if the constraints equation is linear. Returns false if it is not linear or it's state has not been checked.

IsVariable

public boolean IsVariable()
Returns true if the constraint equation defines variable bounds. For example, the expression "2*Var1 + 3*Var2 + 1.5*Var3 <= 100, 200, 300" defines variable bounds for the right hand side.

Returns:
true if the constraint equation defines variable bounds. return false if it does not.

GetNumberOfClauses

public int GetNumberOfClauses()
Returns the number of clauses in the string equation. Constraints that use the logical operator "or" and constraints that use the implied "and" operator have multiple clauses. For constraints of the form “var1< var2 or var1 < 4”, this method returns the number of constraints in the “or” relationship. In this example, it returns 2. For constraints for the form “10 < var2+var3 < 20”, it returns 2 indicating that there are 2 constraints in an implied “and” relationship. Constraints without any logical operators, return 1.

Returns:
the number of clauses in the constraint equation.

IsAndClauses

public boolean IsAndClauses()

IsOrClauses

public boolean IsOrClauses()

GetRHSString

public java.lang.String GetRHSString(int clause)
                              throws COptQuestException
Returns the right hand side string expression associated with the clause indicated by the input parameter. For the constraint "var1 < var2 or var3 < 4", GetRHSString(1) would return "var2". Clauses are 1 based values.

Parameters:
clause - 1 based index of the clause.
Returns:
the string representing the right hand side.
Throws:
COptQuestException

GetLHSString

public java.lang.String GetLHSString(int clause)
                              throws COptQuestException
Returns the left hand side string expression associated with the clause indicated by the input parameter. For the constraint "var1 < var2 or var3 < 4", GetLHSString(1) would return "var1". Clauses are 1 based values.

Parameters:
clause - 1 based index of the clause.
Returns:
the string representing the left hand side.
Throws:
COptQuestException

GetOperatorString

public java.lang.String GetOperatorString(int clause)
                                   throws COptQuestException
Returns the operator as a string expression for the clause indicated by the input parameter. Clauses are 1 based values.

Parameters:
clause - 1 based index of the clause.
Returns:
the string representing the operator.
Throws:
COptQuestException