Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

Name tuple field in OPTMODEL

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Name tuple field in OPTMODEL

In OPL, it's possible to name the different field of a tuple (like record in a database table):

 

tuple Point {

       int x;

       int y;

   };

 

It’s also possible to index field:

 

tuple nurse {

  key string name;

  int seniority;

  int qualification;

  int payRate;

}

 

This way, we don’t have to redefine pattern all the time.

We can access field by using point notation:

 

int x = p.x;

 

You can access an array by the index:

 

NurseWorkTime[<"Isabelle">]<=20;

 

We can use pattern like in OPTMODEL but it’s an option:

 

   forall(<a,b,c> in t) y[<a,b,c>]==...; };

 

The question is : Is this possible to name tuple field and index tupleset in OPTMODEL?


Accepted Solutions
Solution
‎05-19-2016 12:55 PM
SAS Employee
Posts: 414

Re: Name tuple field in OPTMODEL

[ Edited ]

No, you cannot declare a tuple in OPTMODEL, but you can declare a set of tuples and then use arrays indexed over that set.  For example, a tuple of length 1: 

 

set <str> NURSES;
num seniority {NURSES};
num qualification {NURSES};
num payRate {NURSES};
 
NurseWorkTime["Isabelle"]<=20;

 

Or a tuple of length 2 (say <firstname, lastname>):

 

set <str,str> NURSES;
num seniority {NURSES};
num qualification {NURSES};
num payRate {NURSES};
 
NurseWorkTime["Isabelle","Smith"]<=20;

 

In general, the tuples can be arbitrary combinations of num and str.

http://support.sas.com/documentation/cdl/en/ormpug/68156/HTML/default/viewer.htm#ormpug_optmodel_det...

View solution in original post


All Replies
Solution
‎05-19-2016 12:55 PM
SAS Employee
Posts: 414

Re: Name tuple field in OPTMODEL

[ Edited ]

No, you cannot declare a tuple in OPTMODEL, but you can declare a set of tuples and then use arrays indexed over that set.  For example, a tuple of length 1: 

 

set <str> NURSES;
num seniority {NURSES};
num qualification {NURSES};
num payRate {NURSES};
 
NurseWorkTime["Isabelle"]<=20;

 

Or a tuple of length 2 (say <firstname, lastname>):

 

set <str,str> NURSES;
num seniority {NURSES};
num qualification {NURSES};
num payRate {NURSES};
 
NurseWorkTime["Isabelle","Smith"]<=20;

 

In general, the tuples can be arbitrary combinations of num and str.

http://support.sas.com/documentation/cdl/en/ormpug/68156/HTML/default/viewer.htm#ormpug_optmodel_det...

Occasional Contributor
Posts: 11

Re: Name tuple field in OPTMODEL

Thank you for your answer. I think it can be a good feature to implement in your next version. This way it would be easier to convert OPL code to OPTMODEL.

Occasional Contributor
Posts: 11

Re: Name tuple field in OPTMODEL

Did you expect to add tuple or record type in a near future? This feature (name tuple field) is really useful when you build real life model and also help when you want to convert a model from another algebraic model to OPTMODEL.

SAS Employee
Posts: 414

Re: Name tuple field in OPTMODEL

This feature is not currently in our road map, but we'll keep it in mind for a future release.

Occasional Contributor
Posts: 11

Re: Name tuple field in OPTMODEL

Thank you for your answer. I will wait for this feature.
SAS Employee
Posts: 414

Re: Name tuple field in OPTMODEL

In the mean time, please let me know if you would like any suggestions for converting your existing code.

SAS Employee
Posts: 37

Re: Name tuple field in OPTMODEL

[ Edited ]

You can approximate the key and dot notation from OPL with arrays of sets, like this:

 

    proc optmodel;
        set NAMES init /Betty Houlihan/;
        set NURSE{NAMES} init [ 
            /* Seniority, Qualification, Pay Rate */
            /<        20,            73,   140000 >/ 
          , /<         2,            88,    40000 >/ 
        ];

        for {ni in NAMES, <seniority,qualification,pay_rate> in NURSE[ni]}
            put "Nurse " ni " has " seniority " years of experience.";
    quit;

 

The downside is that you have the onus of keeping the order of the dummy variables consistent. The upside is that this notation is more like the algebra you might find in a textbook.

 

Occasional Contributor
Posts: 11

Re: Name tuple field in OPTMODEL

Thank you for your answer. As you mention, we have to keep an order list of variable and this can be error prone.

Occasional Contributor
Posts: 11

Re: Name tuple field in OPTMODEL

Using notation that we find in a textbook is good advantage for student. It’s not useful for practitioner.

 

Thank you for your answer.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 524 views
  • 4 likes
  • 3 in conversation