How to export solved variables from ILOG CPLEX to MATLAB?

200 Views Asked by At

I am using the IBM ilog cplex optimizer to solve a large integer programming problem. I have to depend on MATLAB for generating the data set and I could copy it in the .dat file in the appropriate format. With this .dat file, I could solve the problem in the IBM ilog cplex environment. Next, I am trying to write the solved values in a .txt or a .m file so that I can import these values in MATLAB and use them for graphical representation. However, when I'm trying to do this, if the variable is too long, then it is being written in multiple lines as follows:

x_b =  [0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0
     0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
     0 0 1 0 0 0 1 0];

Therefore, it is becoming impossible to import this as an array in MATLAB. So, could anyone please suggest a better method to do this?

Thanks.

1

There are 1 best solutions below

0
On

In OPL CPLEX if you write .mod

range r=1..80;
int x_b[r]=...;

execute
{
  var f=new IloOplOutputFile("exp.txt");
  for(var i in r) f.writeln(x_b[i]);
  f.close();
}

and use your .dat

x_b =  [0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0
     0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
     0 0 1 0 0 0 1 0];

You will get exp.txt

0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
1
0
0
1
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0

that you can read with fscanf from Matlab