我正在解决12.10版Cplex opl中的优化问题。该问题被表述为混合整数锥规划模型。我在一天 24 小时内分别执行代码,并相应地更改输入数据。优化过程随时间变化;对于某些时间,3 到 4 分钟内即可获得结果,而对于其他时间,最多需要 25 分钟才能获得最佳解决方案。
我的优化问题涉及确定具有 37 个开关的电力网络的最佳开关状态。主要目标是最大限度地减少网络损耗,同时保持网络的放射状结构,同时实施必要的重新配置。优化问题确定交换机的最佳状态。每小时应打开 5 个交换机。优化过程针对一天中的每个小时进行,考虑不同的负载条件以找出五个打开的开关。我观察到计算时间存在显着差异,有些小时在几分钟内即可产生结果,而另一些则需要 25 到 30 分钟
我鼓励您查看 CPLEX 文档中的“评估可变性”。
这将帮助您抵御好运气和坏运气。
这在 OPL 和其他 API 中可用
评估变异性
CPLEX 多次解决问题以评估可变性。
CPLEX 可以多次解决相同的混合整数问题,每次 使用不同的随机种子的时间。运用这个工具可以作为 模型随机扰动的替代品。事实上,锻炼身体 该工具可以帮助您评估类别的可变性 您的实例所属的问题。提示:你的问题一定是一个 以下类型的问题:
mixed integer linear program (MILP) mixed integer quadratic program (MIQP) mixed integer quadratically constrained program (MIQCP)
要调用此过程,请按照下列步骤操作:
First, enter or read your model, so that your problem is currently in memory and available to CPLEX. Optionally, set CPLEX parameters in the usual way; these settings will be applied on every run. Then invoke the following command, where n specifies the number of times that you want CPLEX to solve your problem for comparison.
注意:您还可以编写一些代码,例如 https://github.com/AlexFleischerParis/howtowithopl/blob/master/randomseedvariability.mod
int n=30; // number of random seeds
int d[1..n]; // duration
int o[1..n]; // objective
int iter[1..n]; // iterations
// start of the model we want to test
int Fixed = 100;
int NbWarehouses = 50;
int NbStores = 200;
assert( NbStores > NbWarehouses );
range Warehouses = 1..NbWarehouses;
range Stores = 1..NbStores;
int Capacity[w in Warehouses] =
NbStores div NbWarehouses +
w % ( NbStores div NbWarehouses );
int SupplyCost[s in Stores][w in Warehouses] =
1 + ( ( s + 10 * w ) % 100 );
dvar int Open[Warehouses] in 0..1;
dvar float Supply[Stores][Warehouses] in 0..1;
dexpr int TotalFixedCost = sum( w in Warehouses ) Fixed * Open[w];
dexpr float TotalSupplyCost = sum( w in Warehouses, s in Stores ) SupplyCost[s][w] * Supply[s][w];
minimize TotalFixedCost + TotalSupplyCost;
subject to {
forall( s in Stores )
ctStoreHasOneWarehouse:
sum( w in Warehouses )
Supply[s][w] == 1;
forall( w in Warehouses )
ctOpen:
sum( s in Stores )
Supply[s][w] <= Open[w] * Capacity[w];
}
// end of the model we want to test
main {
thisOplModel.generate();
var sum_d=0;
var sum_o=0;;
var sum_iter=0;
writeln("seed objective iteration runtime");
for(var i=1;i<=thisOplModel.n;i++)
{
var opl=new IloOplModel(thisOplModel.modelDefinition);
opl.generate();
cplex.randomseed=i;
var d1=new Date();
cplex.solve();
var d2=new Date();
thisOplModel.d[i]=d2-d1;
sum_d+=d2-d1;
thisOplModel.d[i]=d2-d1;
thisOplModel.o[i]=Opl.ftoi(Opl.round(cplex.getObjValue()));
sum_o+=thisOplModel.o[i];
thisOplModel.iter[i]=cplex.getNiterations();
sum_iter+=thisOplModel.iter[i];
writeln(i," ",thisOplModel.o[i]," ",thisOplModel.iter[i]," ",
thisOplModel.d[i]/1000);
cplex.clearModel();
}
writeln("-----------------------------------------");
writeln("average ",sum_o/thisOplModel.n," ",
sum_iter/thisOplModel.n," ",sum_d/thisOplModel.n/1000);
writeln("std dev ",Opl.standardDeviation(thisOplModel.o)," ",
Opl.standardDeviation(thisOplModel.iter)," ",Opl.standardDeviation(thisOplModel.d)/1000);
}