ILOG-CPLEX. Как я могу загрузить данные в мою модель из Excel? - PullRequest
0 голосов
/ 27 августа 2018

Я хочу загрузить параметры моей модели из файла Excel (.xls o csv), и я новичок в этой среде IDE, поэтому, например, следующий код решит проблему TSP (задача коммивояжера) [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; }

В моем файле TSP.dat у меня есть данные следующим образом:

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

Итак, вопрос: как я могу загрузить матрицу и другие вещи из Excel в модель? Если бы вы могли мне помочь, было бы здорово. Заранее спасибо.

...