Cplex学习笔记
The dual simplex method is the first choice for optimizing a linear programming problem, especially for primal-degenerate problems with little variability in the righthand side coefficients but significant variability in the cost coefficients.
Primal Simplex Optimizerwill sometimes work better on problems where the number of variables exceeds the number of constraints significantly, or on problems that exhibit little variability in the cost coefficients. 654
Network Optimizer may have a positive impact on performance of network structure
The barrier optimizer offers an approach particularly efficient on large, sparse(稀疏的) problems
Sifting was developed to exploit the characteristics of models with large aspect ratios (that is, a large ratio of the number of columns to the number of rows).
The concurrent optimizer(并行优化)多线程计算机平台
简言之:原始变量多于约束 对偶右停左变,边界大型稀疏阵 筛选行列数差大。
To save the basis to a file:
? When you are using the Component Libraries, use the method cplex.writeBasis or the Callable
Library routine CPXmbasewrite , after the call to the optimizer.
? In the Interactive Optimizer, use the write command with the file type bas , after optimization.
Then to read an advanced basis from this file later:
? When you are using the Component Libraries, use the method cplex.readBasis or the routine
CPXreadcopybase .
? In the Interactive Optimizer, use the read command with the file type bas
If the number of iterations required to solve your problem is approximately the same as the number of rows, then you are doing well. If the number of iterations is three times greater than the number of rows (or more), then it may very well be possible to improve performance by changing the parameter that sets the pricing algorithm, DPriInd for the dual simplex optimizer or PPriInd for the primal simplex optimizer
If you observe that your problem has difficulty staying feasible during its solution, then you should consider an alternative scaling method. ScaInd parameter settings for scaling methods
ScaInd Value Meaning
-1 no scaling
0 equilibration scaling (default) 1 aggressive scaling 671
CPLEX学习手册
STL Standard Template Library 简称STL,标准模板库。
IloEnv类用于创建优化环境,进行优化时的内存管理,是一个句柄,指向一个优化实例,最后必须要关掉。 IloModel类用于建模
IloModel model(env);
env必须要传进来,否则错误。 与Ilomodel相关的类:
IloNumVar : representing modeling variables
例如:IloNumVar x1(env, 0.0, 40.0, ILOFLOAT);
IloSemiContVar :semi-continuous or semi-integer variable
IloRange : defining constraints of the form l <= expr <= u, where expr is a linear expression,约束
也可以直接些,不用IloRange
IloExr类用于定义一个表达式,是一个句柄,当无法方便的直接写出约束表达式时用,用完必须end关闭
IloObjective :representing an objective function
例如:IloObjective obj = IloMinimize(env, x1 + 2*x2 + 3*x3);
目标函数和约束必须加入到模型中
例如:model.add(-x1 + x2 + x3 <= 20); model.add(object);
IloCplex类用于read and extract模型到Optimizer,接着进行SOLVe 算法选择:
switch (argv[2][0]) { case 'o':
cplex.setParam(IloCplex::RootAlg, IloCplex::AutoAlg); break;
case 'p':
cplex.setParam(IloCplex::RootAlg, IloCplex::Primal); break; case 'd':
cplex.setParam(IloCplex::RootAlg, IloCplex::Dual); break; case 'b':
cplex.setParam(IloCplex::RootAlg, IloCplex::Barrier); cplex.setParam(IloCplex::BarCrossAlg, IloCplex::NoAlg); break; case 'h':
cplex.setParam(IloCplex::RootAlg, IloCplex::Barrier); break; case 'n':
cplex.setParam(IloCplex::RootAlg, IloCplex::Network); break; case 's':
cplex.setParam(IloCplex::RootAlg, IloCplex::Sifting); break; case 'c':
cplex.setParam(IloCplex::RootAlg, IloCplex::Concurrent); break; default: break; }
IloCplex cplex(env)+ cplex.extract(model)= IloCplex cplex(model); 上式表示提取模型
cplex.solve ();求解模型,当返回值时IloTrue表示有可行解,IloFalse表示无解
cplex.getStatus ();用不同的返回值表示解是可行解还是最优解。 解的查询:
IloNum IloCplex::getValue (IloNumVar var) const; void IloCplex::getValues (IloNumArray val,
const IloNumVarArray var) const;
例如:IloNum val1 = cplex.getValue(x1); IloNum objval = cplex.getObjValue (); 捕捉错误: IloEnv env; try { // ...
} catch (IloException& e) {
cerr << \} catch (...) {
cerr << \
}
env.end();
输出CPLEX变量数据,对于数组变量,必须先赋值给一个IloNum,对于单变量,直接取出用CPLEX.getValue();