Decision Optimization

 View Only
Expand all | Collapse all

decision variable with ordered pairs of indices

  • 1.  decision variable with ordered pairs of indices

    Posted Mon January 30, 2012 03:28 PM

    Originally posted by: SystemAdmin


    Hi:

    I am trying to define a decision variable :
    {string} HELOS= ...;
    dvar int+ PEN[i1 in HELOS, i2 in HELOS];
    

    How can i filter the dvar such that it is defined only on the combinations of i1 and i2

    it is achieved by an ampl code :

    var PEN{i1 in HELOS, i2 in HELOS: i2 > i1} >= 0;
    


    • in OPL currently i am doing it as: *
    tuple HeloPair{
            string i1;
            string i2;
      }
     
    {HeloPair} HeloPairs={<i,j> | i in HELOS,j in HELOS: ord(HELOS,j) < ord(HELOS,i)};
    dvar int+ Pen[HeloPairs];
    


    can it be written in a simple manner in OPL as in AMPL ?

    Thanks for help
    v/r
    Mandar
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: decision variable with ordered pairs of indices

    Posted Tue January 31, 2012 01:10 PM
    Hi,

    you should use the keyword ordered

    Let me give you an example:

    se being a set of integers such as {int} se={3,2,1};
    int s = sum(ordered i,j in se) i div j;
    is equivalent to
    int s = sum(i,j in se: ord(se,i)<ord(se,j)) i div j;
    


    Alex
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: decision variable with ordered pairs of indices

    Posted Tue January 31, 2012 09:31 PM

    Originally posted by: SystemAdmin


    Thanks for reply, Alex

    i tried but please note in my case i have decision variables and not parameters. Does OPL allow filtering on Decisioin variables? I got errors when i tried something similar to AMPL.

    I am trying avoid creation of unnecessary decision variables.
    Thanks,
    Mandar
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: decision variable with ordered pairs of indices

    Posted Wed February 01, 2012 09:34 AM
    Hi

    so if I adapt my example to your case, it becomes:

    tuple HeloPair{
            string i1;
            string i2;
      }
      
      {string} HELOS={"A","B","C"};
     
    {HeloPair} HeloPairs={ <i,j> | ordered i,j in HELOS};
    dvar int+ Pen[HeloPairs] in 0..2;
     
    subject to
    {
      
    }
     
    execute
    {
      writeln(Pen);
    }
    


    which gives

    [0 0 0]
    


    Regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer