Search code examples
cplexopl

OPL CPLEX Syntax Problem with Array of Tuple


This is .mod (model file)

tuple TDayPair{
  string day1;
  string day2;
}

{TDayPair} DAYS={<"Mon","Tue">,<"Thurs","Fri">};
int a[DAYS]= ...;
execute {
  writeln(a[<"Mon","Tue">]); //<--it gives syntax error here
}

This is .dat (data file)

a = #[
  <"Mon","Tue">:1,
  <"Thurs","Fri">:2,
]#;

It gives syntax error at the model file at writeln(a[<"Mon","Tue">]); what's the issue here?


Solution

  • If you write

    tuple TDayPair{
      string day1;
      string day2;
    }
    
    {TDayPair} DAYS={<"Mon","Tue">,<"Thurs","Fri">};
    int a[DAYS]= ...;
    execute {
      writeln(a[DAYS.find("Mon","Tue")]); //<--it gives syntax error here
    }
    

    You will get

    1
    

    OPL Modeling language is not the same as the OPL Javascript language that helps with preprocessing, postprocessing and flow control.