Desiderius Severus
Desiderius Severus

Reputation: 141

String variables and dictionnary output in MiniZinc

I have a MiniZinc program in which the variables are mostly integers. Outputs look like

 DELPECH            [4, 5, 7, 10, 11]
 DELPORTE           [2, 3, 6, 8, 10]    
 DELROT         [1, 2, 3, 6, 7] 
 DELRUE         [2, 3, 5, 7, 10]    

And the underlying code looks like

output([
join([name[ss, 1] ++ 
show([tt | tt in TOPICS where topicSelected[ss,tt]]) ++ "\"
| ss in STUDENTS])]);

The problem is that the numbers (between 1 and 11) in fact correspond to topics choices in a scheduling problem, and I would like to display them as such in the final output, i.e. to apply a dictionary looking like 1->"History", 2->"Math", etc.

I was planning to define an array for each student courses[ss] with the name of the corresponding topics, but I don't think it is possible to make variable string arrays. Is there a good way to do it?

Upvotes: 0

Views: 193

Answers (1)

Axel Kemper
Axel Kemper

Reputation: 11322

Variables of type var string are not supported. But you can index an array of string constants with a var variable:

array[int] of string: a = ["abra", "ka", "dabra"];

output [ "\n\(a[i]) " ++ show(a[i]) | i in 1..3];

I don't know how to avoid the quotes in string output.

Upvotes: 1

Related Questions