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?
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.
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.
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.
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.
This feature is not currently in our road map, but we'll keep it in mind for a future release.
In the mean time, please let me know if you would like any suggestions for converting your existing code.
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.
Thank you for your answer. As you mention, we have to keep an order list of variable and this can be error prone.
Using notation that we find in a textbook is good advantage for student. It’s not useful for practitioner.
Thank you for your answer.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.