0

I have the following variables:

tuple subtour 
{
    int         size;
    {int}       customers;
};
  
{subtour} S;

Now I want to create a new subtour with OPL script and add it to S. I know that I can create a new subtour with S.add(), but what do I have to put in the braces to create a new set of customers when adding the subtour? I already tried something like S.add(5, new Array(1,5,6)) without success.

Tim Dreier
  • 35
  • 4
  • Here is some great documentation, with examples: https://www.ibm.com/support/knowledgecenter/es/SSSA5P_12.7.1/ilog.odms.ide.help/OPL_Studio/opllangref/topics/opl_langref_data_init.html. Another example that might help: https://stackoverflow.com/a/50988756/421195. Unfortunately, I don't have a copy of CPLEX (or equivalent) handy, so I can't actually try out any examples for you myself :( – paulsm4 Oct 18 '20 at 18:15

1 Answers1

2
tuple subtour 
{
    int         size;
    {int}       customers;
};
  
{subtour} S;
{int} emptysubset;

execute
{
  S.add(1,emptysubset);
  Opl.first(S).customers.add(1);
  Opl.first(S).customers.add(5);
  Opl.first(S).customers.add(6);
  writeln(S);
}

gives

{<1 {1 5 6}>}
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15