对于给定的配置,我想将整个运行时间限制为1800 s,其中包括主要问题,通过该主要问题可以调用子问题1和2。 除此之外,您能否告诉我如何为不同的子模型设置不同的时限?例如,如果我要将子问题1的运行时间限制为500 s,将子问题2的运行时间限制为800 s。 如代码说明所示,我使用了execute_ {cplex.tilim = 1800;}行,但是程序运行了1800 s以上。
//-----------------Main-problem.mod-------------------------------
//variables definition here
execute {cplex.tilim= 1800;}
Objective function;
subject to {
Constraints:1-7
}
execute FillDuals {
Dual of constraint 1;
}
}
main{
thisOplModel.settings.mainEndEnabled = true;
thisOplModel.generate();
var masterDef = thisOplModel.modelDefinition;
var masterCplex = cplex;
var masterData = thisOplModel.dataElements;
var masterOpl = new IloOplModel(masterDef,masterCplex);
masterOpl.addDataSource(masterData);
masterOpl.generate();
masterCplex.solve();
masterOpl.postProcess();
//\**************Calling Sub-Problem 1*********************************
var SubSource1 = new IloOplModelSource("Sub-Problem1.mod");
var Sub1Def = new IloOplModelDefinition(SubSource1);
var Sub1Def = thisOplModel.modelDefinition;
var Sub1Cplex = cplex;
var Sub1Data = thisOplModel.dataElements;
var Sub1Opl = new IloOplModel(Sub1Def,Sub1Cplex);
Sub1Opl.addDataSource(Sub1Data);
Sub1Opl.generate();
Sub1Cplex.solve();
//\****************************************************************
//\*******************Calling Sub-Problem2*********************************
var SubSource2 = new IloOplModelSource("Sub-Problem2.mod");
var Sub2Def = new IloOplModelDefinition(SubSource2);
var Sub2Def = thisOplModel.modelDefinition;
var Sub2Cplex = cplex;
var Sub2Data = thisOplModel.dataElements;
var Sub2Opl = new IloOplModel(Sub2Def,Sub2Cplex);
Sub1Opl.addDataSource(Sub2Data);
Sub2Opl.generate();
Sub2Cplex.solve();
//\****************************************************************
} //end of main
//--------------------Sub-Problem1.mod------------------------
variables and constants definition;
Objective function;
subject to {
Constraints:
}
//SubOpl1 doesnt have main function main{}
//-------------------Sub-Problem2.mod----------------------
variables and constants definitions;
Objective function;
subject to {
Constraints:
}
//SubOpl2 doesnt have main function main{}
//-------------------------------------------------------
答案 0 :(得分:1)
您可以像在预处理中一样设置时间限制,但也可以在主程序段中设置时间限制:
您可以更改
Sub1Opl.generate();
Sub1Cplex.solve();
进入
Sub1Opl.generate();
Sub1Cplex.tilim=60;
Sub1Cplex.solve();
如果您需要Sub1CPLEX在60秒后停止
致谢
NB:该时间限制适用于cplex解决方案,因此,如果您需要总共1800 s的许多解决方案的时间限制,则需要为每个解决方案使用较小的时间限制