0

I am trying to write the result data to an external file because of an error I got after running the code for 16 hours.

I found the code above, it works for the variables with one index but my variables are not with one index. There are even variables with 4 indexes. How can I adapt this code to my situation?

execute{
  var ofile = new IloOplOutputFile("modelRun.txt");
  ofile.writeln("Data:");
  for(var i in thisOplModel.r){
     ofile.writeln("d["+i+"+"]="+thisOplModel.d[i]]);
  }
  ofile.writeln("Optimal objective value="+cplex.getObjValue());
  ofile.writeln("Optimal variable values:");
  for(i in thisOplModel.r){
     ofile.writeln("x["+i+"]="+thisOplModel.x[i]);
  }
  ofile.close();
}

Thank you for any help!

Sena
  • 31
  • 5

2 Answers2

0

If x is a 4D array instead of:

for(i in thisOplModel.r){
     ofile.writeln("x["+i+"]="+thisOplModel.x[i]);
  }

you could directly write:

ofile.writeln("x="+thisOplModel.x);
halfer
  • 19,824
  • 17
  • 99
  • 186
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thank you, it is actually exactly what i wanted but I'd like to also learn what will the outcome be. For 1D and 2D arrays in notepad it gives the arrays like: y = [3 0 0 0 2 0 0 0 0 0 4 3 0 0 0 0 0 0 0 0 6 2 0 0]; d = [[1 1 0 0 1 0] [0 1 0 0 1 0] [0 1 0 0 1 0]] I am not sure how a 4D array would be in notepad. – Sena Feb 14 '19 at 16:43
0

About displaying 4D arrays:

range r=1..2;
int x[i in r][j in r][k in r][l in r]=i+j+k+l;

execute
{
writeln("x=",x);
}

which gives

x= [[[[4 5]
                 [5 6]]
             [[5 6]
                 [6 7]]]
         [[[5 6]
                 [6 7]]
             [[6 7]
                 [7 8]]]]
halfer
  • 19,824
  • 17
  • 99
  • 186
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15