BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BLAIS
Fluorite | Level 6

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?

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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

9 REPLIES 9
RobPratt
SAS Super FREQ

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...

BLAIS
Fluorite | Level 6

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.

BLAIS
Fluorite | Level 6

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.

RobPratt
SAS Super FREQ

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

BLAIS
Fluorite | Level 6
Thank you for your answer. I will wait for this feature.
RobPratt
SAS Super FREQ

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

LeoLopes
SAS Employee

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.

 

BLAIS
Fluorite | Level 6

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

BLAIS
Fluorite | Level 6

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

 

Thank you for your answer.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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