本文整理汇总了C++中OsiClpSolverInterface::initialSolve方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiClpSolverInterface::initialSolve方法的具体用法?C++ OsiClpSolverInterface::initialSolve怎么用?C++ OsiClpSolverInterface::initialSolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiClpSolverInterface
的用法示例。
在下文中一共展示了OsiClpSolverInterface::initialSolve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
char *f_name_lp, *last_dot_pos, f_name[256], *f_name_pos;
int i, ncol;
if((argc < 2) || (argc > 2)) {
printf("### ERROR: main(): Usage: One of the following\ncgl_data_test input_file_name.mps\ncgl_data_test input_file_name.lp\n");
exit(1);
}
f_name_lp = strdup(argv[1]);
f_name_pos = strrchr(f_name_lp, '/');
if(f_name_pos != NULL) {
strcpy(f_name, &(f_name_pos[1]));
}
else {
strcpy(f_name, f_name_lp);
}
last_dot_pos = strrchr(f_name, '.');
if(last_dot_pos != NULL) {
last_dot_pos = '\0';
}
OsiClpSolverInterface *clp = new OsiClpSolverInterface;
clp->messageHandler()->setLogLevel(0);
if(strcmp(&(f_name_lp[strlen(f_name_lp)-3]), ".lp") == 0) {
clp->readLp(f_name_lp);
}
else {
if(strcmp(&(f_name_lp[strlen(f_name_lp)-4]), ".mps") == 0) {
clp->readMps(f_name_lp);
}
else {
printf("### ERROR: unrecognized file type\n");
exit(1);
}
}
ncol = clp->getNumCols();
clp->initialSolve();
printf("LP value: %12.2f\n", clp->getObjValue());
OsiCuts cuts;
// Define parameters for CglRedSplit generator
CglParam cpar;
cpar.setMAX_SUPPORT(ncol+1);
CglRedSplitParam rspar(cpar);
// Create a cut generator with the given parameters
CglRedSplit cutGen(rspar);
char *colType = new char[ncol];
for(i=0; i<ncol; i++) {
if(clp->isContinuous(i)) {
colType[i] = 'C';
}
else {
colType[i] = 'I';
}
}
int round, max_rounds = 10;
for(round=0; round<max_rounds; round++) {
cutGen.generateCuts(*clp, cuts);
int ncuts = cuts.sizeRowCuts();
const OsiRowCut **newRowCuts = new const OsiRowCut * [ncuts];
for(i=0; i<ncuts; i++) {
newRowCuts[i] = &cuts.rowCut(i);
}
clp->applyRowCuts(ncuts, newRowCuts);
delete[] newRowCuts;
printf("round %4d: %4d generated cuts new objective value: %12.2f\n",
round, ncuts, clp->getObjValue());
clp->resolve();
if(clp->isAbandoned()) {
printf("###ERROR: Numerical difficulties in Solver\n");
exit(1);
}
if(clp->isProvenPrimalInfeasible()) {
printf("### WARNING: Problem is infeasible\n");
exit(1);
}
}
delete clp;
free(f_name_lp);
delete[] colType;
return(0);
}
示例2: main
//.........这里部分代码省略.........
model.addCutGenerator(&generator1,-1,"Probing");
//model.addCutGenerator(&generator2,-1,"Gomory");
model.addCutGenerator(&generator2,1,"Gomory");
model.addCutGenerator(&generator3,-1,"Knapsack");
// model.addCutGenerator(&generator4,-1,"RedSplit");
//model.addCutGenerator(&generator5,-1,"Clique");
model.addCutGenerator(&generator5,1,"Clique");
model.addCutGenerator(&flowGen,-1,"FlowCover");
model.addCutGenerator(&mixedGen,-1,"MixedIntegerRounding");
// Add stored cuts (making sure at all depths)
model.addCutGenerator(&stored,1,"Stored",true,false,false,-100,1,-1);
int numberGenerators = model.numberCutGenerators();
int iGenerator;
// Say we want timings
for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
CbcCutGenerator * generator = model.cutGenerator(iGenerator);
generator->setTiming(true);
}
OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (model.solver());
// go faster stripes
if (osiclp) {
if(osiclp->getNumRows()<300&&osiclp->getNumCols()<500) {
//osiclp->setupForRepeatedUse(2,0);
osiclp->setupForRepeatedUse(0,0);
}
// Don't allow dual stuff
osiclp->setSpecialOptions(osiclp->specialOptions()|262144);
}
// Uncommenting this should switch off all CBC messages
// model.messagesPointer()->setDetailMessages(10,10000,NULL);
// No heuristics
// Do initial solve to continuous
model.initialSolve();
/* You need the next few lines -
a) so that cut generator will always be called again if it generated cuts
b) it is known that matrix is not enough to define problem so do cuts even
if it looks integer feasible at continuous optimum.
c) a solution found by strong branching will be ignored.
d) don't recompute a solution once found
*/
// Make sure cut generator called correctly (a)
iGenerator=numberGenerators-1;
model.cutGenerator(iGenerator)->setMustCallAgain(true);
// Say cuts needed at continuous (b)
OsiBabSolver oddCuts;
oddCuts.setSolverType(4);
// owing to bug must set after initialSolve
model.passInSolverCharacteristics(&oddCuts);
// Say no to all solutions by strong branching (c)
CbcFeasibilityNoStrong noStrong;
model.setProblemFeasibility(noStrong);
// Say don't recompute solution d)
model.setSpecialOptions(4);
// Could tune more
double objValue = model.solver()->getObjSense()*model.solver()->getObjValue();
double minimumDropA=CoinMin(1.0,fabs(objValue)*1.0e-3+1.0e-4);
double minimumDrop= fabs(objValue)*1.0e-4+1.0e-4;
printf("min drop %g (A %g)\n",minimumDrop,minimumDropA);
model.setMinimumDrop(minimumDrop);
if (model.getNumCols()<500)
model.setMaximumCutPassesAtRoot(-100); // always do 100 if possible
else if (model.getNumCols()<5000)
model.setMaximumCutPassesAtRoot(100); // use minimum drop