营业执照怎么年审,seo教程,卖芒果的网络营销策划,响应式网站的建设1. 上手
1.1 快速使用
首先是简单的调用测试#xff0c;在mac上首先安装clp的库#xff1a;brew install coin-or-tools/coinor/cbc#xff0c;然后新建项目进行调用#xff0c;各项配置如下#xff0c;注意要添加的library和directory比较多#xff1a;
1.2 命令行方…1. 上手
1.1 快速使用
首先是简单的调用测试在mac上首先安装clp的库brew install coin-or-tools/coinor/cbc然后新建项目进行调用各项配置如下注意要添加的library和directory比较多
1.2 命令行方式
安装完cbc后可以直接输入cbc调出命令行 或者直接一行调用
cbc air03.lp solve solu sol.txt求解的几个配置 Sec :默认Infinity最多允许的执行时间 MaxN: 默认Infinity : 最多允许搜索的节点数。防止内存溢出 MaxS : 默认Infinity : 做多允许存储的可行解数量。如果只想要一个可行解可以把这个数值设置为1.
2. 基本调用方法
标识类名说明ACbcBranch…MIP的非连续类比如说整数变量、0-1变量BCbcNode接下来进行branch的节点CCbcTreeCbcNode的集合DCbcCompare…在CbcTree上决定下一步探索那个Node的函数可以修改ECglCutGeneratorsCGL中的cut generator很少有人自己写FCbcHeuristics启发式算法
2.1 model和solver
需要首先定义一个线性规划的solver传入model中。 model的方法和solver的方法很多是一致的比如model.getNumCols() 以及model.solver()-getNumCols()但是同步性有时会有差别比如getColSolution() CbcModel可能不是最新的结果这时可以用CbcModel::bestSolution()来获取结果。 当然两者还是有差别的比如用来减少输出显示的代码
model.solver()-setHintParam(OsiDoReducePrint,true,OsiHintTry);在model中就没有。
2.2 获取结果信息 2.3 预处理和cut选项 Prep : 预处理默认sos sos: creates Special Ordered Sets [CITE] to improve branching off: turns of pre-processing equal : turns ≤ clique constraints into equality clique constraints PassP : 默认5 Cuts : 默认On Clique : 默认IfMove Off : never try this cut; Root : cuts applied only at root node; IfMove : cuts will be used of they succeed on improving the dual bound; ForceOn : forces the use of the cut generator at every node. LiftliftAndProjectCuts : 默认Off MixedMixedIntegerRounding : 默认IfMove TwoTwoMirCuts : 默认Root : Determines the application Two phase Mixed Integer Rounding cuts. Knapsack : 默认IfMove Flow : 默认IfMove ProbingResidualCapacityCuts : 默认forceOnStrong 除了上述选项外还包含forceOn, forceOnGlobal, forceOnStrong, forceOnButStrong and strongRoot. ResidualResidualCapacityCuts : 默认Off CutDCutDepth: 默认-1 当深度为CutD的倍数时进行cut。CutD-1时由cbc来自动判断。 CutLCutLength: 默认-1 gomory cuts允许的最大cut数目。默认情况由cbc决定 0 ≤ CutL 10, 000, 000 : maximum length of CutL for cuts generated at root node and in the tree; CutL ≥ 10, 000, 000 : allows cuts with unlimited length at root node, with a limit inside the tree. for example: CutL 10,000,130 indicate that in the tree only cuts with at most 130 variables will be accepted. PassCPassCuts : 默认-1 根节点cut passes最大数目。如果是 -1, 使用以下策略其中n是变量数column number: n ≤ 500 : 100 passes; 500 n ≤ 5000 : 100 passes, stopping when bound improvements are small; n ≥ 5000 : 20 passes for larger problems.
2.4 启发式算法
Round在每次搜索时启用rounding heuristicFeas : 在根节点启动feasibility pump heuristic。使用一系列LPs尝试获取integer feasible solution.PassFPassFeasibilityPump: 默认30。Feasibility Pump heuristic的最大允许pass数目。若没有获得初始可行解可以尝试将数值提升。Local(LocalTreeSearch)默认offPivotAndC PivotAndComplement默认OffPivotAndFPivotAndFix默认OffCombine : 默认On 在多次求解之后仅尝试对出现过多次的变量进行bcCombine2 : 默认Off 比上面的要求更严格要求出现多次且数值相同。Rins : 默认On 控制Relaxation Induced Neighborhood Search heuristic.Rens : 默认Off 控制Relaxation Enforced Neighborhood Search heuristic.VndVndVariableNeighborhoodSearch:默认Off 控制Variable Neighborhood Search heuristic.DivingGDivingGuided : 默认Off. 切换为Guided Dives heuristicDivingPDivingPseudoCost: 默认Off. 切换为使用pseudo costs的Diving heuristic .DivingFDivingFractional: 默认Off. 切换为Diving Fractional heuristic.DivingSDivingSome: 默认Off. 切换为random diving heuristic at various times.
此外cbc只有一个rounding heuristic可以自定义启发式算法。
3. 选择下一个搜索节点
使用CbcCompare来控制如何选择搜索节点。已经定义好的实现如下
类型描述CbcCompareDepth一直探索最深的树节点CbcCompareObjective一直探索当前目标函数最佳的树节点CbcCompareDefault在可行解找到前使用depth-first。当一定数量的nodes被探索过、或者一定数量的解被发现后改用breadth-first搜索然后当树到达一定的尺寸后再改为depth-firstCbcCompareEstimate当pseudo cost启用时可以用来猜测解
要自己实现的话参考使用下面的函数 修改CbcCompareUser.hpp和CbcCompareUser.cpp中CbcCompare的bool test(CbcNode* x, CbcNode* y)) 函数当node y优先于node x返回true。 CbcCompareUser::test()方法代码如下
// Returns true if y better than x
bool
CbcCompareUser::test (CbcNode * x, CbcNode * y)
{if (weight_-1.0) {// before solutionif (x-numberUnsatisfied() y-numberUnsatisfied())return true;else if (x-numberUnsatisfied() y-numberUnsatisfied())return false;elsereturn x-depth() y-depth();} else {// after solution.// note: if weight_0, comparison is based// solely on objective valuedouble weight CoinMax(weight_,0.0);return x-objectiveValue() weight*x-numberUnsatisfied() y-objectiveValue() weight*y-numberUnsatisfied();}
}tree是无状态的。newSolution()方法在每次新的解发现时调用另外每1000次探索后调用every1000Nodes()此时可以修改test()中的变量(e.g., weight_).同时由于CbcNode有model指针因此同时可以修改诸如最大允许时间等变量 (e.g., CbcModel::setMaximumSeconds(double value))
3. 示例文件说明