Originally posted by: Mathsg
Hi,
I am getting an error "Scripting runtime error: IloTuple, 1" when passing dual variable from one model to another. My dual variables is an array type and passing it values from one model i.e., Master problem to another model i.e., sub model. i have declare it in scripting part. Kindly guide me
int nbnodes = ...; /* Total number of nodes*/
range nodes = 1..nbnodes; /*set of all ECs*/
int totallc = ...; /*total number of LC*/
int LC_Cost = ...; /*total number of different cost of LC*/
int LC_Capacties = ...;
tuple lincard{ /*Tuple for LC*/
key int id; /*S.N of LC starting from 0 to....*/
int k_lc; /*different capacties of LC*/
int costtype_lc; /*different costs of LC*/
}
{lincard} Lincards = ...; /*Taking tupple data of LC from data file*/
int totalec = ...; /*total number of EC*/
int EC_Cost = ...; /*total number of different cost of EC*/
int EC_Capacties = ...; /* total number of different capacties fo EC*/
tuple eccard{ /*Tuple for EC*/
key int id; /*S.N of EC starting from 0 to....*/
int k_ec; /*different capacties of EC*/
int costtype_ec; /*different cost of EC*/
}
{eccard} ECcards = ...; /*Taking tupple data of EC from data file*/
int nmbr_routes = ...; /*Totall number of routes*/
range routes = 1..nmbr_routes; /*range of routes*/
int nmberflow = ...; /*Totall number of flows*/
int im_flow = ...; /*important flows*/
//{string} flow_type = {"ip_f", "np_f"};
tuple flow{ /*Tuple for flows*/
key int id; /*S.N of flows starting from 0 to....*/
int src; /*Source node of flows*/
int dest; /*destination node of flows*/
float flow_bw; /*BW of flows*/
int khan; /*this int take two values, either 1, if flow is important or 0 if flow is non-important*/
}
{flow} flows = ...; /*Taking tupple data of flows from data file*/
float Duals[routes] = ...;
int hope_count[routes][nodes][nodes] = ...; /*hope count between source and destination*/
int a[Lincards] = ...; /*Set upper limit of LC in data file*/
int b[ECcards] = ...; /*Set upper limit of EC in data file*/
int q[nodes][nodes] = ...; /* the boolean value that equals to 1 if nodes u and v are from different zones, and 0 otherwise*/
int link [nodes][nodes] = ...; /*link between source and dist*/
dvar boolean k[flows][nodes][nodes]; /*k=1, if flow "i" get routed b/w node u to v and "0", otherwise*/
dvar boolean lemda[flows][routes][nodes][nodes]; /*lemda=1 if "jth" lighpath is used and "0", otherwise*/
dvar boolean x[flows][Lincards][nodes][nodes]; /*x=1, if nth LC is used, and 0, otherwise*/
dvar boolean y[flows][ECcards][nodes][nodes]; /*y=1, if nth EC is used, and 0, otherwise*/
//dvar boolean w[flows][flows][Lincards][nodes][nodes];/*w=1, if different flows "i"and"m" share the nth LC, and 0, otherwise*/
//dvar boolean z[flows][flows][ECcards][nodes][nodes]; /*z=1, if different flows "i"and"m" share the nth EC, and 0, otherwise*/
dvar int n1[Lincards][nodes]; /*n1=integer values indicates the total number of used LC at node v*/
dvar int n2[ECcards][nodes]; /*n2=integer values indicates the total number of used EC at node v*/
dvar boolean f[Lincards][nodes][nodes]; /*f=1, if nth LC used for transmission over u to v, and 0 otherwise*/
dvar boolean g[ECcards][nodes][nodes]; /*g=1, if nth EC used for transmission over u to v, and 0 otherwise*/
minimize((sum(k in Lincards, u in nodes)(n1[k][u]*k.costtype_lc*2))+(sum(k in ECcards, u in nodes)(n2[k][u]*k.costtype_ec*2))+(sum(i in flows, j in routes, u in nodes, v in nodes)lemda[i][j][u][v]*hope_count[j][u][v]*i.flow_bw));
subject to{
forall ( i in flows, u in nodes, v in nodes)
Const1:
k[i][u][v]<=link[u][v];
forall(i in flows, u in nodes: u==i.src)
Const2:
sum(v in nodes)(k[i][u][v]-k[i][v][u])==1;
forall(i in flows, u in nodes: u==i.dest)
Const3:
sum(v in nodes)(k[i][u][v]-k[i][v][u])==-1;
forall(i in flows, u in nodes: u!=i.src && u!=i.dest)
Const4:
sum(v in nodes)(k[i][u][v]-k[i][v][u])==0;
forall ( i in flows, u in nodes, v in nodes)
Const5:
sum(j in routes)lemda[i][j][u][v]== k[i][u][v];
forall (i in flows, j in routes, u in nodes, v in nodes)
Const6:
sum(p in Lincards)x[i][p][u][v]==lemda[i][j][u][v];
forall (i in flows, j in routes, u in nodes, v in nodes: 1==i.khan)
Const7:
sum(p in ECcards)y[i][p][u][v]==lemda[i][j][u][v]*q[u][v];
forall (p in Lincards, u in nodes, v in nodes)
Const8:
sum(i in flows) x[i][p][u][v]*i.flow_bw<=p.k_lc;
forall (p in ECcards, u in nodes, v in nodes)
Const9:
sum(i in flows) y[i][p][u][v]*i.flow_bw<=p.k_ec;
/*forall ( i in flows, m in flows, p in Lincards, u in nodes, v in nodes: i!=m)
Const10:
(x[i][p][u][v]+x[m][p][u][v]-1)<= w[i][m][p][u][v];
forall ( i in flows, m in flows, p in Lincards, u in nodes, v in nodes: i!=m)
Const11:
w[i][m][p][u][v]<= x[i][p][u][v];
forall ( i in flows, m in flows, p in Lincards, u in nodes, v in nodes: i!=m)
Const12:
w[i][m][p][u][v]<= x[m][p][u][v];
forall ( i in flows, m in flows, p in ECcards, u in nodes, v in nodes:i!=m)
Const13:
(y[i][p][u][v]+y[m][p][u][v]-1)<= z[i][m][p][u][v];
forall ( i in flows, m in flows, p in ECcards, u in nodes, v in nodes: i!=m)
Const14:
z[i][m][p][u][v]<= y[i][p][u][v];
forall ( i in flows, m in flows, p in ECcards, u in nodes, v in nodes: i!=m)
Const15:
z[i][m][p][u][v]<= y[m][p][u][v];
forall ( i in flows, m in flows, p in ECcards, u in nodes, v in nodes: i!=m )
Const16:
sum(o in Lincards) w[i][m][o][u][v]>=z[i][m][p][u][v];
forall ( i in flows, m in flows, u in nodes, v in nodes)
Const17:
sum(p in Lincards)w[i][m][p][u][v]<=1;
forall ( i in flows, m in flows, u in nodes, v in nodes)
Const18:
sum(p in ECcards)z[i][m][p][u][v]<=1;*/
forall (u in nodes, p in Lincards)
Const19:
sum(s in Lincards, v in nodes:s==p )f[s][u][v]<=n1[p][u];
forall (p in ECcards, u in nodes)
Const20:
sum(s in ECcards, v in nodes:s==p)g[s][u][v]<=n2[p][u];
forall ( i in flows, p in Lincards, u in nodes, v in nodes)
Const21:
x[i][p][u][v]<= f[p][u][v];
forall ( i in flows, p in ECcards, u in nodes, v in nodes)
Const22:
y[i][p][u][v]<= g[p][u][v];
forall (u in nodes, p in Lincards)
Const23:
n1[p][u]<=a[p];
forall (u in nodes, p in ECcards)
Const24:
n2[p][u]<=b[p];
}
// dual values used to fill in the sub model.
execute FillDuals {
for(j in routes) {
Duals[j] = Const6[j].dual;
}
}
main {
var status = 0;
thisOplModel.generate();
var RC_EPS = 1.0e-6;
var masterDef = thisOplModel.modelDefinition;
var masterCplex = cplex;
var masterData = thisOplModel.dataElements;
var subSource = new IloOplModelSource("CG_2_PP.mod");
var subDef = new IloOplModelDefinition(subSource);
var subData = new IloOplDataElements();
var subCplex = new IloCplex();
var best;
var curr = Infinity;
while ( best != curr ) {
best = curr;
var masterOpl = new IloOplModel(masterDef, masterCplex);
masterOpl.addDataSource(masterData);
masterOpl.generate();
masterOpl.convertAllIntVars();
writeln("Solve master.");
if ( masterCplex.solve() ) {
curr = masterCplex.getObjValue();
writeln();
writeln("OBJECTIVE: ",curr);
}
else {
writeln("No solution!");
masterOpl.end();
break;
}
subData.nmbr_routes = masterOpl.nmbr_routes;
subData.nbnodes = masterOpl.nbnodes;
subData.flows = masterOpl.flows;
subData.Lincards = masterOpl.Lincards;
subData.hope_count = masterOpl.hope_count;
subData.link = masterOpl.link;
subData.q = masterOpl.q;
subData.ECcards = masterOpl.ECcards;
subData.Duals = masterOpl.Duals;
for (var j in masterOpl.routes) {
subData.Duals[j] = masterOpl. Const6[j].dual;
}
var subOpl = new IloOplModel(subDef, subCplex);
subOpl.addDataSource(subData);
subOpl.generate();
writeln("Solve sub.");
if ( subCplex.solve() ) {
writeln();
writeln("OBJECTIVE: ",subCplex.getObjValue());
}
else {
writeln("No solution!");
subOpl.end();
masterOpl.end();
break;
}
if (subCplex.getObjValue() < -RC_EPS) {
subOpl.end();
masterOpl.end();
break;
}
// Prepare the next iteration:
//masterData.Patterns.add(masterData.Patterns.size,1,subOpl.Use.solutionValue);
for ( j in masterOpl.routes){
masterData.lemda.add(masterData.lemda[i][j][u][v]);
}
masterData.routes.add(subOpl.getObjValue());
subOpl.end();
masterOpl.end();
}
writeln("Relaxed model search end.");
masterOpl = new IloOplModel(masterDef,masterCplex);
masterOpl.addDataSource(masterData);
masterOpl.generate();
writeln("Solve integer master.");
if ( masterCplex.solve() ) {
writeln();
writeln("OBJECTIVE: ",masterCplex.getObjValue());
if (Math.abs(masterCplex.getObjValue() )>=0.0001) {
writeln("Unexpected objective value");
status = -1;
}
/*for(i in masterData.Patterns) {
if (masterOpl.Cut[i].solutionValue > 0) {
writeln("Pattern : ", i, " used ", masterOpl.Cut[i].solutionValue << " times");
}
}*/
}
masterOpl.end();
status;
}
#DecisionOptimization#OPLusingCPOptimizer