Originally posted by: SystemAdmin
[xellos00 said:]
Hello to all, i'm new to this Optimization Software, i could make it solve a problem changing the data automatically, so you know, i read the manual.
The problem is about two parts, and in the program that i could run was all solve together, but now i need to solve the same problem, but separately. The thing is, to solve it separately i need that the variables from the first part become data for the second part. I made the arrangements in the .mod file so those variables now are data, and separate the two parts in different .mod files and calling them from a different .mod file called Main.mod. The first part is solve fine, but the second part is reading everything (i think), but the solution is impossible according with the constraint of the .mod file.
As you can see i made a large amount of vars that are meaningless, but it was to try to make it work. The result at the end is that the constraints in the "Semanal.mod" file don't apply. But the cplex solve it just fine.
Here is the main model:
main{
var source = new IloOplModelSource("Separado.mod");
var def = new IloOplModelDefinition(source);
var Cplex = new IloCplex();
var mensual = new IloOplModel(def, Cplex);
var data = new IloOplDataSource("Separado.dat");
mensual.addDataSource(data);
mensual.generate();
Cplex.solve();
//Meaningless vars
var produccionvalues = mensual.produccion;
var inventariovalues = mensual.inventario;
var backordervalues = mensual.backorder;
var horas_extra_produccionvalues = mensual.horas_extra_produccion;
var horas_normales_produccionvalues = mensual.horas_normales_produccion;
var cantidad_subcontratacionvalues = mensual.cantidad_subcontratacion;
var trabajadores_despedidosvalues = mensual.trabajadores_despedidos;
var trabajadores_contratadosvalues = mensual.trabajadores_contratados;
var trabajadores_actualesvalues = mensual.trabajadores_actuales;
var trabajadores_horas_extrasvalues = mensual.trabajadores_horas_extras;
mensual.end();
//Second Part
var source1 = new IloOplModelSource("Semanal.mod");
var def1 = new IloOplModelDefinition(source1);
var Cplex1 = new IloCplex();
var semanal = new IloOplModel(def1, Cplex1);
var data1 = new IloOplDataSource("Semanal.dat");
semanal.addDataSource(data1);
semanal.generate();
//Next Iteration
var def2 = semanal.modelDefinition;
var data2 = semanal.dataElements;
semanal = new IloOplModel(def2, Cplex1);
semanal.addDataSource(data2);
semanal.generate();
//Changing the data to solve the new model
for (var x in semanal.mes){
for(var i in data2.producto){
data2.produccion[i][x] = produccionvalues[i][x];
data2.inventario[i][x] = inventariovalues[i][x];
data2.backorder[i][x] = backordervalues[i][x];
data2.horas_extra_produccion[i][x] = horas_extra_produccionvalues[i][x];
data2.horas_normales_produccion[i][x] = horas_normales_produccionvalues[i][x];
data2.cantidad_subcontratacion[i][x] = cantidad_subcontratacionvalues[i][x];
}
data2.trabajadores_despedidos[x] = trabajadores_despedidosvalues[x];
data2.trabajadores_contratados[x] = trabajadores_contratadosvalues[x];
data2.trabajadores_actuales[x] = trabajadores_actualesvalues[x];
data2.trabajadores_horas_extras[x] = trabajadores_horas_extrasvalues[x];
}
semanal.addDataSource(data2);
semanal.generate();
if (Cplex1.solve())
writeln("success");
else writeln("Cuack");
}
#DecisionOptimization#MathematicalProgramming-General