Class COptQuestStringObjective


public class COptQuestStringObjective extends COptQuestSingleObjective
The COptQuestStringObjective class is used to define an objective function using a mathematical expression. The expression may be linear or non-linear. For example, the objective may be to minimize "2*Var1 + 3*Var2 + 1.5*Var3". "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 following mathematical functions are supported and can be used in the mathematical expression:
  • min(x,y) Returns the smaller value of x and y
  • max(x,y) Returns the larger value of x and y
  • sqrt(x) Returns the square root of x
  • log(x) Returns the logarithm of x
  • log10(x) Returns the base 10 logarithm of x
  • pow(x,y) Returns x raise to the power y
  • exp(x) Returns e raised to the power x
  • abs(x) Returns the absolute value of x
  • pi The mathematical constant pi (3.141159)
  • e The mathematical constant e (2.718)
  • rand() Returns a random number between 0 and 1
  • fmod(x,y) Returns the remainder of x/y
  • floor(x) Returns the largest whole number less than or equal to x
  • ceil(x) Return the smallest whole number greater than or equal to x
  • sin(x) Returns the sine of x where x is an angle in radians
  • cos(x) Returns the cosine of x where x is an angle in radians
  • tan(x) Returns the tangent of x where x is an angle in radians
  • sinh(x) Returns the hyperbolic sine of x where x is an angle in radians
  • cosh(x) Returns the hyperbolic cosine of x where x is an angle in radians
  • tanh(x) Returns the hyperbolic tangent of x where x is an angle in radians
  • asin(x) Returns the arcsine of x in the range -n/2 to n/2 radians. x is between -1 and 1.
  • asin(x) Returns the arcsine of x in the range -n/2 to n/2 radians. x is between -1 and 1.
  • acos(x) Returns the arccosine of x in the range 0 to n radians. x is between -1 and 1.
  • atan(x) Returns the arcstangent of x in the range -pi/2 to pi/2 radians. if x is 0, atan returns 0.
  • atan2(x,y) Returns the arctangent of y/x in the range -pi to pi radians. If both x and y are 0, the function returns 0.
  • DtoR(x) Converts degrees to radians.
  • RtoD(x) Converts radians to degrees.
  • Constructor Details

    • COptQuestStringObjective

      public COptQuestStringObjective()
      Default constructor
    • COptQuestStringObjective

      public COptQuestStringObjective(String expression)
      Constructor with string expression
  • Method Details

    • IsLinear

      public boolean IsLinear()
      Returns true if the expression is linear. Returns false if it is not. This method should be called after the optimization has started or after calling CheckExpression(). IsLinear() will return false if it is called before one of these methods.
      Overrides:
      IsLinear in class COptQuestObjective
      Returns:
      true if the objective equation is linear. Returns false if it is not linear or if it's state has not been checked.
    • SetEquation

      public void SetEquation(String expression) throws COptQuestException
      Sets the mathematical expression that defines the objective.
      Parameters:
      expression - - mathematical expression that defines the objective of the optimization
      Throws:
      COptQuestException - if a problem is encountered
    • GetEquation

      public String GetEquation()
      Get the equation
      Returns:
      equation
    • SetCheckLinear

      public void SetCheckLinear(boolean Value)
      If true, the objective should be checked for linearity. Linear objectives can be solved using the OptQuest linear program. The default value is true.
      Parameters:
      Value - - 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 objective 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.
    • CheckExpression

      public void CheckExpression() throws COptQuestException
      Checks the objective expression for syntax errors. If the expression contains errors, a COptQuestException is thrown.
      Throws:
      COptQuestException - if a problem is encountered