Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  tuple transformation

    Posted 04/14/19 11:13 AM

    Originally posted by: brown_rice


    Hi,

    Suppose I read my data as 

    tuple transport{

    string _from;

    string _to;

    string vehicle;

    float cost;

    }

    {transport} transportation = ...;

    Now I'd like to do;

    tuple locations{

    string _from;

    string _to;

    int  vehicle;

    }

    setof(locations) location_set = { <i,j,v> | <i,j,v,c> in  transportation };

    int cost_values[location_set] = the cost values stored in transportation. 

     

    How can I make this transformation in OPL?

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: tuple transformation

    Posted 04/14/19 03:04 PM

    Hi

    tuple transport{

    key string _from;

    key string _to;

    key string vehicle;

    float cost;

    }

    {transport} transportation = {<"A","B","Ferrari",10>,<"C","D","Bus",1>};

     

    tuple locations{

    string _from;

    string _to;

    string  vehicle;

    }

    setof(locations) location_set = { <i,j,v> | <i,j,v,c> in  transportation };

    float cost_values[l in location_set] = first({c | <l._from,l._to,l.vehicle,c> in transportation});

    execute
    {
    writeln(cost_values);
    }

     

    gives

     

    [10 1]

    regards

     

    https://www.linkedin.com/pulse/low-barrier-entry-optimization-through-cplex-alex-fleischer/


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: tuple transformation

    Posted 04/15/19 08:58 AM

    Originally posted by: brown_rice


    Hi,

    Thanks for the answer, It works, but I have two questions.

    First, is it crucial to use "key" in tuple definitions? I never use them. Would that cause any trouble in big models? or is it just the way you prefer to code?

    Second questions is about "first". What does exactly "first" do? When I remove it, OPL raises an error message. However, I can do this too

     {float} cost_values[l in location_set] = {c | <l._from,l._to,l.vehicle,c> in transportation}; 

    What is the main difference between what I shared above and what you shared in your response?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: tuple transformation

    Posted 04/15/19 10:41 AM

    Hi,

    key helps make sure about data integrity.

    See https://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.0/ilog.odms.ide.help/OPL_Studio/opllang_quickref/topics/tlr_opl_key.html

    first : https://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.0/ilog.odms.ide.help/OPL_Studio/opllang_quickref/topics/tlr_oplf_first.html

    {float} cost_values[l in location_set] = {c | <l._from,l._to,l.vehicle,c> in transportation}; 

    returns a set and first helps to turn that set into a single element.

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer