Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Conditional statements with dvars in constraints

  • 1.  Conditional statements with dvars in constraints

    Posted 12/18/08 06:13 PM

    Originally posted by: SystemAdmin


    [pmarley2 said:]

    Hi all,

    I am trying to write a conditional statement into my constraints. However, when I use decision variables inside the condition, I get an error. For example,

    1 subject to {
    2    forall (t in 0..nbHours-1) {
    3        forall (p in providers) {
    4                if (Power[p][t]/(suppliers[p][4] - suppliers[p][3]) >= 1)
    5                {
    6                        abs(Power[p][t] - Power[p][t+1]) <= suppliers[p][5];<br />7                }
    8        }
    9    } }

    I get an error on line 4 that says "Decision variable "Power" not allowed."

    I try to bypass using the if statement by writing the following.

    1 subject to {
    2    forall (t in 0..nbHours-1) {
    3        forall (p in providers) {
    4                (Power[p][t]/(suppliers[p][4] - suppliers[p][3]) >= 1) &&
    5                abs(Power[p][t] - Power[p][t+1]) <= suppliers[p][5];<br />6        }
    7    } }

    And the code works correctly. But is there a way to write a conditional statement in an easier way?

    Thanks.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Conditional statements with dvars in constraints

    Posted 12/18/08 07:39 PM

    Originally posted by: SystemAdmin


    [afleischer said:]

    Hi,

    it is not allowed to use if with decision variables (if cannot be part of a constraint)
    but what you can do is use the => logical

    so you can rewrite

    if (Power[p][t]/(suppliers[p][4] - suppliers[p][3]) >= 1)
                    {
                          abs(Power[p][t] - Power[p][t+1]) <= suppliers[p][5];<br />              }

    into


    (Power[p][t]/(suppliers[p][4] - suppliers[p][3]) >= 1) => (abs(Power[p][t] - Power[p][t+1]) <= suppliers[p][5])<br />
    Alex

    #DecisionOptimization
    #OPLusingCPLEXOptimizer