lundi 30 mars 2015

How to Solve Different Test Problems in CPLEX Using the Same .mod File at One Run?

I searched the forum but could not find any topic about solving different test problems using the same model at one run. There is a post “How to run a single .mod file and lots of .dat files using CPLEX and java?” but my question is a bit different from it.



SheetConnection sheet("C:/Users/ikucukkoc/opl/Test Problems/P1.xlsx");
PartsDataTemp from SheetRead(sheet,"'PartsData'!A:D");
MachinesDataTemp from SheetRead(sheet,"'MachinesData'!A:I");
X to SheetWrite(sheet,"RESULT_X!A:J");
Y to SheetWrite(sheet,"RESULT_Y!A:J"); enter code here


I have a .mod file (namely "Planning v1-3.mod") which consists of Constraints, Objective Function, etc. and a .dat file (namely "Planning v1-3.dat") in which I connect to an Excel file to read data from and write results in its different sheets using the following code:



SheetConnection sheet("C:/Users/ikucukkoc/opl/Test Problems/P1.xlsx");
PartsDataTemp from SheetRead(sheet,"'PartsData'!A:D");
MachinesDataTemp from SheetRead(sheet,"'MachinesData'!A:I");
X to SheetWrite(sheet,"RESULT_X!A:J");
Y to SheetWrite(sheet,"RESULT_Y!A:J");


I can solve test problems one by one. However, I have many (i.e. 45) different test problems named systematically (e.g. P1, P2, P3, …, P45) and I want to solve all of them at one run and write results to each correspondent Excel file. I wrote a main section using the advice for the similar question in the forum as follows, but it does not do what I want. Because I do not want to create 45 different .dat files as I already have my data in Excel files.



main{
var src = new IloOplModelSource("Planning v1-3.mod");
var def = new IloOplModelDefinition(src);

var iteration=1;

while(iteration<=2){
var opl = new IloOplModel(def,cplex);
var filename="P"+iteration;
var data = new IloOplDataSource(filename+".dat");
opl.addDataSource(data);
var details=opl.dataElements;
opl.generate();
if(cplex.solve()){
writeln(filename + ": Solution Found");
}
else{
writeln(filename + ": NO SOLUTION!");
}
iteration++
}
}


As output, I can write solutions for decision variables X and Y. But I also want to write Objective Function Value and CPU Times consumed to each Excel file. Could anyone help me to achieve all of these please? Can attach .mod and .dat files if needed.


Your immediate response is highly appreciated!


Many thanks in advance.


Aucun commentaire:

Enregistrer un commentaire