Topic
  • 5 replies
  • Latest Post - ‏2016-06-26T12:17:02Z by NRouge
SystemAdmin
SystemAdmin
1883 Posts

Pinned topic If-Decision Variable

‏2012-12-25T13:16:58Z |
hii, I am new to Cplex optimization Studio.Please help me as I am stuck in a problem where I have to use If condition in Decision variable (dvar). Please tell me how it is possible to do in IBM ILOG CPLEX Optimization Studio

Version: 12.4

Thank You
Updated on 2013-01-06T17:37:57Z at 2013-01-06T17:37:57Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: If-Decision Variable

    ‏2012-12-25T23:19:23Z  
    It's not very clear what you mean by "if condition in decision variable". I think you probably want to conditionally define a decision expression (dexpr) using a if-then-else semantic. OPL provides a one line syntax for that:

    range A = 1..5;
    dvar int b[a in A];
    dvar int c[a in A];
    dexpr int x[a in A] = a%2 == 0 ? b[a] : c[a];
    


    In this example, x[a] is equal to b[a] if a is even, or c[a] if a is odd.

    Regards,
    Stefano
    Updated on 2014-03-26T05:51:45Z at 2014-03-26T05:51:45Z by iron-man
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: If-Decision Variable

    ‏2013-01-06T17:37:57Z  
    Are you trying to use a decision variable in an if-statement? This is not supported, see the reference manual.
    What you can do instead is use logical constraints. A statement like 'if (x>=0) then a*y >= b' is equivalent to the implication constraint 'x >= 0 => a*y >= b'.
  • NRouge
    NRouge
    16 Posts

    Re: If-Decision Variable

    ‏2016-06-26T11:06:45Z  
    Are you trying to use a decision variable in an if-statement? This is not supported, see the reference manual.
    What you can do instead is use logical constraints. A statement like 'if (x>=0) then a*y >= b' is equivalent to the implication constraint 'x >= 0 => a*y >= b'.

    Hi,

    I have a model

    ..

    float D[N,N]=...;

    ..

    dvar boolean x[N,N,N];

    ..

    forall (i in N,j in N, k in V)
      if (x[i,j,k]==1) then (D[i,k]+t[i,j] <= D[j,k]);

     

    I want dvar x in if statement like this. It has error 'Decision variable (or expression) "x" not allowed." please help. Thanks.

  • AlexFleischer
    AlexFleischer
    2074 Posts

    Re: If-Decision Variable

    ‏2016-06-26T12:01:27Z  
    • NRouge
    • ‏2016-06-26T11:06:45Z

    Hi,

    I have a model

    ..

    float D[N,N]=...;

    ..

    dvar boolean x[N,N,N];

    ..

    forall (i in N,j in N, k in V)
      if (x[i,j,k]==1) then (D[i,k]+t[i,j] <= D[j,k]);

     

    I want dvar x in if statement like this. It has error 'Decision variable (or expression) "x" not allowed." please help. Thanks.

    Hi,

    instead of

    forall (i in N,j in N, k in V)
      if (x[i,j,k]==1) then (D[i,k]+t[i,j] <= D[j,k]);

    you should try

    forall (i in N,j in N, k in V)
      (x[i,j,k]==1) => (D[i,k]+t[i,j] <= D[j,k]);

    regards

  • NRouge
    NRouge
    16 Posts

    Re: If-Decision Variable

    ‏2016-06-26T12:17:02Z  

    Hi,

    instead of

    forall (i in N,j in N, k in V)
      if (x[i,j,k]==1) then (D[i,k]+t[i,j] <= D[j,k]);

    you should try

    forall (i in N,j in N, k in V)
      (x[i,j,k]==1) => (D[i,k]+t[i,j] <= D[j,k]);

    regards

    Thanks a lot for your quick response .