Decision Optimization

 View Only
Expand all | Collapse all

Define variable subject to decision variable binary

  • 1.  Define variable subject to decision variable binary

    Posted Fri August 30, 2019 08:36 AM

    Originally posted by: JCGar


    Hello,

    I have a binary decision variable dvar boolean X , an integer variable dvar int  bu  and  dvar int+ zh;

      X [<h,u,c>] = {<1 1 1> <1 1 2> <1 1 3> <1 1 4> <1 1 5> <1 2 1> <1 2 2>
                            <1 2 3> <1 2 4> <1 2 5> <1 3 1> <1 3 2> <1 3 3>
                           <1 3 4> <1 3 5> <1 4 1> <1 4 2> <1 4 3> <1 4 4>
                           <1 4 5> <1 5 1> <1 5 2> <1 5 3> <1 5 4> <1 5 5>

                           <2 1 1>}

    I have a restriction like this:

    subject to{

     forall (h in 1..2, c in res[h] )  
              bu[<h,c>] >=  sum(u in res[h]) x[<h,u,c>] ) - 1 ; 

     forall (h in 1..2)  

          zh[h] >= maxl( c in res[h]) bu[<h,c>] ;

    }

     variable bu give me:   bu = [0 -1 -1 1 1 0];  that is correct.

    But I I would like to know if it is possible to add the values in c, to get something like this:   bu = [0 -1 -2 -1 0 0 ]

    Regards.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: Define variable subject to decision variable binary

    Posted Fri August 30, 2019 08:53 AM

    I am not sure what you mean. Do you just want to add bu and c? Have you tried using a dexpr for that?


    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: Define variable subject to decision variable binary

    Posted Fri August 30, 2019 09:40 AM

    Originally posted by: JCGar


    Hello,

    I want sum the value obtained in  bu[<h,c>], as :  bu[<h,c>] = (sum(u in res[h]) x[<h,u,c>] ) - 1 ) + bu[<h,c-1>] .

    Regards.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: Define variable subject to decision variable binary

    Posted Sat August 31, 2019 04:25 AM

    Hi

    range r=1..6;
     
     int buval[r] = [0, -1, -1, 1, 1, 0];  
     
     dvar int bu[r];
     dvar int busum[r];
     
     subject to
     {
     forall(i in r) bu[i]==buval[i];
     
     busum[1]==bu[1];
     forall(i in r:i!=1) busum[i]==busum[i-1]+bu[i];
     
     }
     
     execute
     {
     writeln(busum);
     }

    gives

     

    [0 -1 -2 -1 0 0]

    could that help ?

     

    regards


    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: Define variable subject to decision variable binary

    Posted Sun September 01, 2019 05:43 AM

    Originally posted by: JCGar


    Hello,

    Tahnk you, it runs fine.

    regards.


    #DecisionOptimization
    #MathematicalProgramming-General