Decision Optimization

Decision Optimization

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


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

get dual value in main script

  • 1.  get dual value in main script

    Posted 10/28/10 08:18 PM

    Originally posted by: CynthiaLi


    Hi,I have a question about get dual value in main script. I'm a beginner, so I am not even sure that the question is right...
    Anyway, I basically modified the cutstock example. In the cutstock model, there is a part:
    for(var i in masterOpl.Items) {
    subData.Duals[i] = masterOpl.ctFill[i].dual;
    }
    I believe it means to pass the dual value from the master problem to the sub problem.
    I want to do a similar thing. The difference is that I want to take the dual value from the master problem first, then do some calculation to put in the subproblem. Here is my code:
    var duals;
    for(var t=1;t<=MasterData.NbDual;t++)
    {
    duals[t]=MasterOpl.ctFill[t].dual;
    }
    for (var i=1; i<= MasterOpl.NbX;i++)
    {
    for(var j=1; j<= MasterOpl.NbDual;j++) Big[i]=Big[i]+duals[j]*MasterOpl.T[i][j];
    }

    However, there is error sign pointing at the line of duals[t]=MasterOpl.ctFill[t].dual;
    And it says "Scripting runtime error: cannot add properties to this value, "undefined".
    Where did I go wrong?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: get dual value in main script

    Posted 10/28/10 10:03 PM

    Originally posted by: SystemAdmin


    If you need to treat duals in your script as array then you should declare it as:
    var duals = new Array();
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: get dual value in main script

    Posted 02/13/11 05:40 PM

    Originally posted by: SystemAdmin


    I need a little help in the same context :
    I am trying to get duals for constraints using Opl dual function

    Syntax
    dual(ct)

    Description
    This function is available in a post-processing context.
    is there any example showing usage?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: get dual value in main script

    Posted 02/14/11 11:06 AM

    Originally posted by: SystemAdmin


    Yes, you may want to look at 'custock' example that comes with distribution. Specifically, in cutstock_main.mod file, 'FillDuals' script accesses dual value of constraints to fill an array that is then passed to sub-model.

    Regards,
    Faisal
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: get dual value in main script

    Posted 02/15/11 12:30 PM

    Originally posted by: SystemAdmin


    Thanks Faisal, that was helpful.

    I have a few questions ( if you are from IBM team):
    the syntax mentioned in Opl Reference manual is
    Opl.dual(ct) > i took ct for constraint name
    am i missing something here? because i get error if i try that.
    Also i tried the following (similar) in the post processing code
    execute DISPLAY_RESULT{
    for ( var i in Rows )

    write ( ct i . dual , " " ) ;
    }

    but it gives me dual value as 'undefined' in the script log
    and it is not displayed in problem browser either ( all other outputs are displayed in problem browser)
    Thank you
    Mandar
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: get dual value in main script

    Posted 06/16/11 01:28 PM

    Originally posted by: SystemAdmin


    I also have the same problem...
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: get dual value in main script

    Posted 06/17/11 02:07 AM

    Originally posted by: SatishKumarA


    Try this,

    execute DISPLAY_RESULT{
     
    for ( var i in Rows )
    write ( ct i . dual , " " ) ;
    writeln("Dual value:",i,ct[i].dual); (or)
    writeln("Dual Value:,ct[i].dual);
    }
    

    And AFAIK, dual value will be given as "undefined" when the corresponding constraint is undefined.

    I hope this helps,

    Thanks,
    Satish Kumar A
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: get dual value in main script

    Posted 06/17/11 02:09 AM

    Originally posted by: SatishKumarA


    Try this,
    execute DISPLAY_RESULT{ 
    for ( var i in Rows )
    writeln("Dual value:",i,ct[i].dual); (or) writeln("Dual Value:",ct[i].dual);
    }
    


    And AFAIK, dual value will be given as "undefined" when the corresponding constraint is undefined.

    I hope this helps,

    Thanks,
    Satish Kumar A
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: get dual value in main script

    Posted 12/02/19 11:17 AM

    Originally posted by: Mathsg


    Hi, i am facing same problem with dual variables. I am getting an error in scripting part of my master problem when passing dual variable constriant from master problem to sub model. i have tried my best to fix it but i am unable to locate it. Kindly guide me 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: get dual value in main script

    Posted 12/02/19 12:22 PM

    Hi,

    in cutstock_main

    you may read


          // Using data elements from the master model.
          var subData = new IloOplDataElements();
          subData.RollWidth = masterOpl.RollWidth;
          subData.Size = masterOpl.Size;
          subData.Duals = masterOpl.Duals;     
          subOpl.addDataSource(subData);
          subOpl.generate();

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: get dual value in main script

    Posted 12/03/19 02:02 AM

    Originally posted by: Mathsg


    Hi Alex, 

     

    Thank you so much for your continued help throughout my research. I have read your refrance but i have not get much about it weather my problem is same as that problem. I am unable to locating the problem why it give me an error while passing dual variables constraint from master problem to another model may be the error is due to accesing of array with false way or i dont know. Can you help me to fix the error ? I am looking forward to hearing from you. thank you


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: get dual value in main script

    Posted 12/03/19 03:19 AM

    Have you tried

    subData.Duals = masterOpl.Duals;   

    from cutstock_main example ?

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 13.  Re: get dual value in main script

    Posted 12/03/19 09:44 AM

    Originally posted by: Mathsg


    Hi,

     

    Thank you so much for your help. The problem has been fixed which was due to some mistakes in my constraint but now it give me another error while writing next iteration part in script for updating the master problem from sub opl. In my orignal master problem i was cosidering subset of light paths which has given me current solution and then sub model give me negative reduce cost which means that still there are light paths that can improve our Master problem. Now i am writing it in script part of OPL to get the light paths from sub model and update the master problem. i have looked upon the cut stock example but i am unable getting an idea from this example. can you help me ?  i would appreciate it very much if anyone can fix the error or give me some kind suggestions. thank you


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 14.  Re: get dual value in main script

    Posted 12/03/19 10:04 AM

    and what is the type of routes ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 15.  Re: get dual value in main script

    Posted 12/03/19 10:06 PM

    Originally posted by: Mathsg


    Hi,

     

    thank you very much for your time. I am solving networking planing problem by column generation approache in which i have 6 node topology. Source and destination are connected through k shortest path.

    i have decompose the problem into master and sub problem. i am going to minimize the cost of flow. In the master problem i have cosider 2 k shortest path for each flow between source and destination which give me current solution for the flows and sub problem can generate new path which can imporve our objective i.e., minimize the cost. path is made up of connecting different link and combine them i.e., hope count. Now i am confused that how to write the next iteration for updating the master problem as i have get reduced cost from sub problem which means there a path i.e., links that can improve our master prblem objective. i have written it but it give me an error


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 16.  Re: get dual value in main script

    Posted 12/04/19 01:44 AM

    Originally posted by: Mathsg


    Hi,

     

    thank you very much for your time. I am solving networking planing problem by column generation approache in which i have 6 node topology. Source and destination are connected through k shortest path.

    i have decompose the problem into master and sub problem. i am going to minimize the cost of flow. In the master problem i have cosider 2 k shortest path for each flow between source and destination which give me current solution for the flows and sub problem can generate new path which can imporve our objective i.e., minimize the cost. path is made up of connecting different link and combine them i.e., hope count. Now i am confused that how to write the next iteration for updating the master problem as i have get reduced cost from sub problem which means there a path i.e., links that can improve our master problem objective. i have written it but it give me an error


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 17.  Re: get dual value in main script

    Posted 12/04/19 04:04 AM