Search code examples
tuplescplex

Defining tuple in CPLEX


I want to define a tuple in a CPLEX .mod file. There is a main block in the .mod file. When I try to define the tuple inside the main block, an error occurs like: Scripting parser error: missing ';' or newline between statements. This is shown in the next figure:

enter image description here

But when I replace the tuple definition out of the main block, the problem is solved. Like the next figure:

enter image description here

Although the problem is solved with the second approach, I want to ask what is the reason for this.


Solution

  • in the main block you should use thisOplModel to get anything from the model.

    tuple minandmax
    {
    int m;
    int M;
    }
    
    {minandmax} singletonMinAndMax={<1,5>};
    
    dvar int X;
    subject to
    {
      
    }
    
    main
    {
      writeln("give me ",Opl.first(thisOplModel.singletonMinAndMax).M);
    }
    

    gives

    give me 5