Topic
  • 7 replies
  • Latest Post - ‏2013-05-13T20:19:10Z by AlexFleischer
Hannaneh
Hannaneh
5 Posts

Pinned topic Dual Undefined

‏2013-05-02T09:37:34Z |

Hi Guys,

I have a program as below:

minimize sum(i in Links) Flow[i]*Cost[i]   //Cost of each link is a piecewise function

s.t.:forall(i in Nodes)  ct1: sum(<i,j> in Links) Flow[<i,j>] -

                                   sum(<j,i> in Links) Flow[<j,i>] == SupDem[i]; //SupDem=1 or -1 0r 0

execute Post{

for(var i in Nodes)

writeln(ct1[i].name, "--->", thisOplModel.ct1[i].dual);

}

the output of this script is undefined for all the duals. Any idea why ??

  • AlexFleischer
    AlexFleischer
    1206 Posts

    Re: Dual Undefined

    ‏2013-05-02T13:03:30Z  

    Hi,

     

    are you sure your model is a LP and not a MIP ?

     

    regards

  • Hannaneh
    Hannaneh
    5 Posts

    Re: Dual Undefined

    ‏2013-05-02T13:39:18Z  

    Hi Alex and thanks for your response,

    Yes, i am sure, here is the completed code:

    int NbNodes=...;

    range Nodes=1..NbNodes;

    float SupDem[Nodes]=...;

    tuple links{

    key int FromN;

    key int ToN;

    float ub;

    };

    {links} Links=...;

     int NbPieces=...;

    float Cost[1..NbPieces]=...;

    float Breakpoint[1..NbPieces-1]=...;

    dvar float+ Flow[a in Links];

    dexpr float TotalCost= sum(a in Links)(

    (piecewise(i in 1..NbPieces-1){ Cost[i] -> Breakpoint[i]; Cost[NbPieces]}Flow[a]/a.ub) ;

    minimize TotalCost;

    subject to{

    forall(i in Nodes)

    ct1: sum(<i,j,u> in Links) Flow[<i,j,u>] - sum(<j,i,u> in Links) Flow[<j,i,u>] == SupDem[i];

    }

    execute Post{

    for(var i in Nodes)

       writeln(ct1[i].name, "--->", thisOplModel.ct1[i].dual);

    }

    Cheers,

  • AlexFleischer
    AlexFleischer
    1206 Posts

    Re: Dual Undefined

    ‏2013-05-02T14:36:18Z  
    • Hannaneh
    • ‏2013-05-02T13:39:18Z

    Hi Alex and thanks for your response,

    Yes, i am sure, here is the completed code:

    int NbNodes=...;

    range Nodes=1..NbNodes;

    float SupDem[Nodes]=...;

    tuple links{

    key int FromN;

    key int ToN;

    float ub;

    };

    {links} Links=...;

     int NbPieces=...;

    float Cost[1..NbPieces]=...;

    float Breakpoint[1..NbPieces-1]=...;

    dvar float+ Flow[a in Links];

    dexpr float TotalCost= sum(a in Links)(

    (piecewise(i in 1..NbPieces-1){ Cost[i] -> Breakpoint[i]; Cost[NbPieces]}Flow[a]/a.ub) ;

    minimize TotalCost;

    subject to{

    forall(i in Nodes)

    ct1: sum(<i,j,u> in Links) Flow[<i,j,u>] - sum(<j,i,u> in Links) Flow[<j,i,u>] == SupDem[i];

    }

    execute Post{

    for(var i in Nodes)

       writeln(ct1[i].name, "--->", thisOplModel.ct1[i].dual);

    }

    Cheers,

    Hi,

     

    but the piecewise may turn LP into MIP.

    What happens if you replace your PWL by a constant ?

     

    regards

  • Hannaneh
    Hannaneh
    5 Posts

    Re: Dual Undefined

    ‏2013-05-02T14:50:00Z  

    Hi,

     

    but the piecewise may turn LP into MIP.

    What happens if you replace your PWL by a constant ?

     

    regards

    Hello,

    You are right. when i change PWL with constant, it gives me a dual. But i cannot do it in my main program. Is there any solution to go around it?

    Thanks,

  • AlexFleischer
    AlexFleischer
    1206 Posts

    Re: Dual Undefined

    ‏2013-05-03T07:21:39Z  
    • Hannaneh
    • ‏2013-05-02T14:50:00Z

    Hello,

    You are right. when i change PWL with constant, it gives me a dual. But i cannot do it in my main program. Is there any solution to go around it?

    Thanks,

    Hi

    have you tried to relax the integrity constraint with ConvertAllIntVars  ?

     

    regards

     

  • Hannaneh
    Hannaneh
    5 Posts

    Re: Dual Undefined

    ‏2013-05-04T13:48:38Z  

    Hi

    have you tried to relax the integrity constraint with ConvertAllIntVars  ?

     

    regards

     

    Hi,

    I tried it and used it after MOpl.generate() and before Cplex.solve(), with both dvar int/float, but still getting dual undefined.

     

    Kind Regards,

     

  • AlexFleischer
    AlexFleischer
    1206 Posts

    Re: Dual Undefined

    ‏2013-05-13T20:19:10Z  
    • Hannaneh
    • ‏2013-05-04T13:48:38Z

    Hi,

    I tried it and used it after MOpl.generate() and before Cplex.solve(), with both dvar int/float, but still getting dual undefined.

     

    Kind Regards,

     

    Hi,

     

    because PWL turns the model into a MIP.

    So I see two options:

    1) rewrite your pwl with integer variables in order to be able to use convertAllIntVars

    2) use two .mod models

    a) The first one will compute the results for the decision variable that are used in the pwl

    b) The second model will have those decision variables as constants and then you have an LP and the duals.

    regards