Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Export dual variables

    Posted 08/22/16 05:05 AM

    Originally posted by: JCPawlowski


    Hi,

    I have a problem extracting the dual variables of a constraint in a post process opl script. I already did it on easy constraints and it works well but I can't figure out how to do it for this one:

     

    // Temporal capacity constraints
        forall (<i,j,c,b> in Arcs, e in Epochs)
          ctLinkCapacity:
              sum (d in Demands, f in 1 .. d.td : f <= e) d.bw * (dArc[d, <i,j,c,b>, (e-f+1)] + dArc[d, <j,i,c,b>, (e-f+1)]) <= b;

     

    I tried this way: (that's what I did in the past for "easier" constraints and it worked)

     

    float Duals[Arcs][Epochs];

        for (a in Arcs) {
            for (var e in Epochs) {
                Duals[a][e] = ctLinkCapacity[a][e].dual;
              }
         } 

    I have the following error: 

    Erreur d'exécution du script : Index hors bornes pour le tableau "ctLinkCapacity", " <1 3 804 32000>".   (out of bound index)

    Unfortunately the <1 3 804 32000> tuple exists in my Arcs set. I'm guessing I have wrongly written the export but I can't find how to do it differently in the manual.

     

    Thanks in advance,

     

    JC

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Export dual variables

    Posted 08/22/16 10:12 AM

    Hi,

    the index you use for the array has to be exactly the same as the one in the constraints:

    tuple arc
     {
     int a;
     int b;
     }
     
     {int} Epochs=asSet(1..10);
     
     {arc} Arcs={<1,2>,<2,3>};
     
     dvar float x[Arcs][Epochs];
     
     maximize sum(a in Arcs, e in Epochs) x[a][e];
     subject to
     {
        forall (<a,b> in Arcs, e in Epochs)
          ctLinkCapacity:
              x[<a,b>][e]<=10;
              
            }          
     

     

    float Duals[Arcs][Epochs];
    execute
    {
        for (a in Arcs) {
            for (var e in Epochs) {
                Duals[a][e] = ctLinkCapacity[a][e].dual;
              }
            }          
         } 

    gives an out of bound wheras if I turn

    forall (<a,b> in Arcs, e in Epochs)
          ctLinkCapacity:
              x[<a,b>][e]<=10;

    into

     

    forall (a in Arcs, e in Epochs)
          ctLinkCapacity:
              x[a][e]<=10;

    then it works fine.

    tuple arc
     {
     int a;
     int b;
     }
     
     {int} Epochs=asSet(1..10);
     
     {arc} Arcs={<1,2>,<2,3>};
     
     dvar float x[Arcs][Epochs];
     
     maximize sum(a in Arcs, e in Epochs) x[a][e];
     subject to
     {
        forall (a in Arcs, e in Epochs)
          ctLinkCapacity:
              x[a][e]<=10;
              
            }          
     

     

    float Duals[Arcs][Epochs];
    execute
    {
        for (a in Arcs) {
            for (var e in Epochs) {
                Duals[a][e] = ctLinkCapacity[a][e].dual;
              }
            }          
         } 

    works fine

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Export dual variables

    Posted 08/22/16 11:15 AM

    Originally posted by: JCPawlowski


    Thank you a lot  Alex !

     

    That is what I tought but unfortunately I cannot use exactly this version as you can see in my constraint I use my tuple <i,j,c,b> and also <j,i,c,b>, therefore I cannot use the short "a" and have to put the whole tuple !

    I also tried to put the whole tuple in my saving command as follow but somehow it doesn't work :

     

        for (<i,j,c,b> in Arcs) {
            for (var e in Epochs) {
                Duals[<i,j,c,b>][e] = ctLinkCapacity[<i,j,c,b>][e].dual;
              }
         }      

    The script doesn't accept it ! Is there a way to do it ? or do i have to change the constraint itself ?

    can I slice in the constraint using two arc a1 and a2 ? and setting the tuples like this: item(a1,0) == item(a2,1) and item(a1,1) == item(a2,0) and item(a1,2) == item(a2,2) and item(a1,3) == item(a2,3)

    // Temporal capacity constraints
        forall (a1 in Arcs, a2 in Arcs, e in Epochs : item(a1,0) == item(a2,1) and item(a1,1) == item(a2,0) and item(a1,2) == item(a2,2) and item(a1,3) == item(a2,3))
          ctLinkCapacity:
              sum (d in Demands, f in 1 .. d.td : f <= e) d.bw * (dArc[d, a1, (e-f+1)] + dArc[d, a2, (e-f+1)]) <= b;

     

    I remember something about not slicing with decision variables.

     

    Thanks in advance

    Regards,

    JC


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Export dual variables

    Posted 08/22/16 12:24 PM

    Hi,

    you could have a look at

    http://www.ibm.com/support/knowledgecenter/SSSA5P_12.6.3/ilog.odms.ide.help/OPL_Studio/opllangref/topics/opl_langref_formalParams_filtering.html

    about implicit and explicit slicing

    Plus

    {int} s={1,2,3};

        tuple arc
         {
         int a;
         int b;
         }
         
         {int} Epochs=asSet(1..10);
         
         {arc} Arcs={<1,2>,<2,3>};
         
         dvar float x[Arcs][Epochs];
         
         maximize sum(a in Arcs, e in Epochs) x[a][e];
         subject to
         {
            forall (<a,b> in Arcs, e in Epochs)
              ctLinkCapacity:
                  x[<a,b>][e]<=10;
                  
                }          
         

         

        float Duals[Arcs][Epochs];
        execute
        {
            for (var a in s) for (var b in s) {
                if (Arcs.contains(a,b)) for (var e in Epochs) {
                    Duals[Arcs.find(a,b)][e] = ctLinkCapacity[a][b][e].dual;
                  }
                }          
             }
     

    works fine

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer