0

I want to load the parameters of my model from an excel file (.xls o csv) and I am new in this IDE, so for example, the next code solve the TSP (Traveling Salesman Problem) [TSP.mod]

/*********************************************
 * OPL 12.7.1.0 Model
 * Author: Alonso
 * Creation Date: 22/8/2018 at 19:10:47
 *********************************************/
int n = ... ; // total number of nodes in the problem input!
range Nodes = 1.. n ; // define the nodes
range Nodes1 = 2 .. n ; // define the nodes
tuple Arc {int i; int j;}
{Arc} Arcs ={<i,j> | i in Nodes, j in Nodes}; // data structure
tuple Arc0 {int i; int j;}
{Arc0} Arcs0 ={<i,j> | i in Nodes, j in Nodes}; // data structure
int dist[Arcs0] =... ; //input!
dvar boolean x[Arcs]; //variable definition
dvar float+ u_b[Nodes1]; 
minimize sum(<i,j> in Arcs) dist[<i,j>] * x[<i,j>] ; // objective
subject to // constraints
{
sum(<1,j> in Arcs) x[<1,j>]==1;
sum(<j,1> in Arcs) x[<j,1>]==1;
forall(i in Nodes1)
sum(<j,i> in Arcs) x[<j,i>] ==1 ;
forall(i in Nodes1)
sum(<i,j> in Arcs) x[<i,j>] ==1 ;
forall(i in Nodes1, j in Nodes1:<i,j> in Arcs)
x[<i,j>]+x[<j,i>] <=1;
forall(i in Nodes1, j in Nodes1:<i,j> in Arcs)
u_b[i]-u_b[j]+(n-1)*x [<i,j>] <= n-2;
forall(i in Nodes1)
x[<i,i>]==0; }

In my file TSP.dat I have the data in the following way:

n=4; // numero de nodos
dist=[100 9  7   8 
       9 100 10  15
       7 10  100 4
       8  15  4  100
        ]; // matriz con las distancias

So the question is: How can I load the matrix and other stuff from excel to the model? If you could help me it would be great. Thanks in advance.

rkersh
  • 4,447
  • 2
  • 22
  • 31
  • [This](https://www.ibm.com/developerworks/community/forums/html/topic?id=21a8ed2c-3625-4a0b-8fdf-a74d4a3bb5d4&ps=25) post from the official IBM developerWorks forum could be useful. – rkersh Aug 27 '18 at 22:07
  • Also, see https://stackoverflow.com/questions/48231980. – rkersh Aug 27 '18 at 22:10

0 Answers0