Decision Optimization

Decision Optimization

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


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

Constraint naming indexed by Tuple

  • 1.  Constraint naming indexed by Tuple

    Posted 11/20/17 02:30 PM

    Originally posted by: naveendivakaran


    Hi,

     

    I have been trying to name a subset of constraints in my LP, with tuples. Unfortunately, when I look at the generated LP, the constraint names do not reflect the strings in the tuple. Am I doing something wrong? Can someone help me with this?

     

    Snippets from mod file

    //Tuple Definition

    tuple t3s5i2f {string str1; string str2; string str3;int int1; int int2; int int3; int int4; int int5;float flt1; float flt2;};

    tuple tsi{string str1; int int1;};

     

    //Input initiation

    {t3s5i2f} setWOA = ...;

    {tsi} TravIndex = {<trav,out_ww>|<facility,area,trav,rec,step,ws,step_ww,out_ww,woa,yld> in setWOA};

     

    //constraint Definition

    constraint ctbendMinWO[TravIndex];

     

    part of the lp file generated:

    ctbendMinWO({,201949})

     

    I expect to see:

    ctbendMinWO({"ABC",201949}), as "ABC" is the string that forms the first element of the tuple structure {tsi}.

     

    It seems like only the integer elements of the tuple is getting generated in the lp. Am I doing anything wrong? Or, is this a limitation?

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Constraint naming indexed by Tuple

    Posted 11/20/17 02:53 PM

    Originally posted by: naveendivakaran


    I think I found the answer to this myself. The constraint definition in the mod file was:

     

    forall(<trav,out_ww> in TravIndex)
      ctbendMinWO[<trav,out_ww>]:
    min_wo_trav[<trav,out_ww>] >= 0;

     

    When i rewrite it as:

    forall(ind in TravIndex)
       ctbendMinWO[ind]:
    min_wo_trav[ind] >= 0;

    it shows the string. But I am still curious why the initial code wont work.

     

    I still have a question though. It seems like the string works differently for constraint name and variable. When the variables seem to replace space by a dot, the constraint name seems to replace space by an under score. Could I somehow make the variable and constraint naming use the same formatting?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Constraint naming indexed by Tuple

    Posted 11/21/17 04:51 AM

    Hi,

    I tried

    tuple tsi{string str1; int int1;};

    {tsi} s={<"a",1>,<"b",2>};

    dvar int x[s];

    constraint ct2[s];

    subject to
    {
    forall(i in s) ct:x[i]<=i.int1;

    forall(i in s) ct2[i]:x[i]<=i.int1;
    }

    main
    {
    thisOplModel.generate();

    cplex.exportModel("test.lp");
    }

    which gives

    \ENCODING=ISO-8859-1
    \Problem name: array

    Minimize
     obj:
    Subject To
     ct({"a",1}):  x({"a",1}) <= 1
     ct({"b",2}):  x({"b",2}) <= 2
     ct2({"a",1}): x({"a",1}) <= 1
     ct2({"b",2}): x({"b",2}) <= 2
    Bounds
          x({"a",1}) Free
          x({"b",2}) Free
    Generals
     x({"a",1})  x({"b",2})
    End

    same with

    tuple tsi{string str1; int int1;};

    {tsi} s={<"a",1>,<"b",2>};

    dvar int x[s];

    constraint ct2[s];

    subject to
    {
    forall(<a,b> in s) ct:x[<a,b>]<=b;

    forall(<a,b> in s) ct2[<a,b>]:x[<a,b>]<=b;
    }

    main
    {
    thisOplModel.generate();

    cplex.exportModel("test2.lp");
    }

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer