本文整理汇总了C++中OsiClpSolverInterface::getNumRows方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiClpSolverInterface::getNumRows方法的具体用法?C++ OsiClpSolverInterface::getNumRows怎么用?C++ OsiClpSolverInterface::getNumRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiClpSolverInterface
的用法示例。
在下文中一共展示了OsiClpSolverInterface::getNumRows方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setWhen
/*
Randomized Rounding Heuristic
Returns 1 if solution, 0 if not
*/
int
CbcHeuristicRandRound::solution(double & solutionValue,
double * betterSolution)
{
// rlh: Todo: Memory Cleanup
// std::cout << "Entering the Randomized Rounding Heuristic" << std::endl;
setWhen(1); // setWhen(1) didn't have the effect I expected (e.g., run once).
// Run only once.
//
// See if at root node
bool atRoot = model_->getNodeCount() == 0;
int passNumber = model_->getCurrentPassNumber();
// Just do once
if (!atRoot || passNumber > 1) {
// std::cout << "Leaving the Randomized Rounding Heuristic" << std::endl;
return 0;
}
std::cout << "Entering the Randomized Rounding Heuristic" << std::endl;
typedef struct {
int numberSolutions;
int maximumSolutions;
int numberColumns;
double ** solution;
int * numberUnsatisfied;
} clpSolution;
double start = CoinCpuTime();
numCouldRun_++; //
#ifdef HEURISTIC_INFORM
printf("Entering heuristic %s - nRuns %d numCould %d when %d\n",
heuristicName(),numRuns_,numCouldRun_,when_);
#endif
// Todo: Ask JJHF what "number of times
// the heuristic could run" means.
OsiSolverInterface * solver = model_->solver()->clone();
double primalTolerance ;
solver->getDblParam(OsiPrimalTolerance, primalTolerance) ;
OsiClpSolverInterface * clpSolver = dynamic_cast<OsiClpSolverInterface *> (solver);
assert (clpSolver);
ClpSimplex * simplex = clpSolver->getModelPtr();
// Initialize the structure holding the solutions for the Simplex iterations
clpSolution solutions;
// Set typeStruct field of ClpTrustedData struct to 1 to indicate
// desired behavior for RandRound heuristic (which is what?)
ClpTrustedData trustedSolutions;
trustedSolutions.typeStruct = 1;
trustedSolutions.data = &solutions;
solutions.numberSolutions = 0;
solutions.maximumSolutions = 0;
solutions.numberColumns = simplex->numberColumns();
solutions.solution = NULL;
solutions.numberUnsatisfied = NULL;
simplex->setTrustedUserPointer(&trustedSolutions);
// Solve from all slack to get some points
simplex->allSlackBasis();
// Calling primal() invalidates pointers to some rim vectors,
// like...row sense (!)
simplex->primal();
// 1. Okay - so a workaround would be to copy the data I want BEFORE
// calling primal.
// 2. Another approach is to ask the simplex solvers NOT to mess up my
// rims.
// 3. See freeCachedResults() for what is getting
// deleted. Everything else points into the structure.
// ...or use collower and colupper rather than rowsense.
// ..store address of where one of these
// Store the basic problem information
// -Get the number of columns, rows and rhs vector
int numCols = clpSolver->getNumCols();
int numRows = clpSolver->getNumRows();
// Find the integer variables (use columnType(?))
// One if not continuous, that is binary or general integer)
// columnType() = 0 continuous
// = 1 binary
// = 2 general integer
bool * varClassInt = new bool[numCols];
const char* columnType = clpSolver->columnType();
int numGenInt = 0;
for (int i = 0; i < numCols; i++) {
if (clpSolver->isContinuous(i))
varClassInt[i] = 0;
else
varClassInt[i] = 1;
if (columnType[i] == 2) numGenInt++;
}
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
CglRedSplit generator4;
// try larger limit
generator4.setLimit(200);
CglClique generator5;
generator5.setStarCliqueReport(false);
generator5.setRowCliqueReport(false);
CglMixedIntegerRounding2 mixedGen;
CglFlowCover flowGen;
// Add in generators
// Experiment with -1 and -99 etc
model.addCutGenerator(&generator1,-1,"Probing");
model.addCutGenerator(&generator2,-1,"Gomory");
model.addCutGenerator(&generator3,-1,"Knapsack");
// model.addCutGenerator(&generator4,-1,"RedSplit");
model.addCutGenerator(&generator5,-1,"Clique");
model.addCutGenerator(&flowGen,-1,"FlowCover");
model.addCutGenerator(&mixedGen,-1,"MixedIntegerRounding");
// Say we want timings
int numberGenerators = model.numberCutGenerators();
int iGenerator;
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) {
// Turn this off if you get problems
// Used to be automatically set
osiclp->setSpecialOptions(128);
if(osiclp->getNumRows()<300&&osiclp->getNumCols()<500) {
//osiclp->setupForRepeatedUse(2,0);
osiclp->setupForRepeatedUse(0,0);
}
}
// Uncommenting this should switch off all CBC messages
// model.messagesPointer()->setDetailMessages(10,10000,NULL);
// Allow rounding heuristic
CbcRounding heuristic1(model);
model.addHeuristic(&heuristic1);
// And local search when new solution found
CbcHeuristicLocal heuristic2(model);
model.addHeuristic(&heuristic2);
// Redundant definition of default branching (as Default == User)
CbcBranchUserDecision branch;
model.setBranchingMethod(&branch);
// Definition of node choice
CbcCompareUser compare;
model.setNodeComparison(compare);
// Do initial solve to continuous
model.initialSolve();
// 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);
示例3: main
//.........这里部分代码省略.........
CglGomory generator2;
// try larger limit
generator2.setLimit(300);
CglKnapsackCover generator3;
CglRedSplit generator4;
// try larger limit
generator4.setLimit(200);
CglClique generator5;
generator5.setStarCliqueReport(false);
generator5.setRowCliqueReport(false);
CglMixedIntegerRounding2 mixedGen;
CglFlowCover flowGen;
// Add in generators
// Experiment with -1 and -99 etc
model.addCutGenerator(&generator1,-1,"Probing");
model.addCutGenerator(&generator2,-1,"Gomory");
model.addCutGenerator(&generator3,-1,"Knapsack");
// model.addCutGenerator(&generator4,-1,"RedSplit");
model.addCutGenerator(&generator5,-1,"Clique");
model.addCutGenerator(&flowGen,-1,"FlowCover");
model.addCutGenerator(&mixedGen,-1,"MixedIntegerRounding");
OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (model.solver());
// go faster stripes
if (osiclp) {
// Turn this off if you get problems
// Used to be automatically set
osiclp->setSpecialOptions(128);
if(osiclp->getNumRows()<300&&osiclp->getNumCols()<500) {
//osiclp->setupForRepeatedUse(2,1);
osiclp->setupForRepeatedUse(0,1);
}
}
// Uncommenting this should switch off most CBC messages
//model.messagesPointer()->setDetailMessages(10,5,5000);
// Allow rounding heuristic
CbcRounding heuristic1(model);
model.addHeuristic(&heuristic1);
// And local search when new solution found
CbcHeuristicLocal heuristic2(model);
model.addHeuristic(&heuristic2);
// Redundant definition of default branching (as Default == User)
CbcBranchUserDecision branch;
model.setBranchingMethod(&branch);
// Definition of node choice
CbcCompareUser compare;
model.setNodeComparison(compare);
// Do initial solve to continuous
model.initialSolve();
// 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);
示例4: main
//.........这里部分代码省略.........
//generator1.createCliques(*model.solver(),2,1000,true);
//generator1.setMode(0);
CglGomory generator2;
// try larger limit
generator2.setLimit(300);
CglKnapsackCover generator3;
CglOddHole generator4;
generator4.setMinimumViolation(0.005);
generator4.setMinimumViolationPer(0.00002);
// try larger limit
generator4.setMaximumEntries(200);
CglClique generator5;
generator5.setStarCliqueReport(false);
generator5.setRowCliqueReport(false);
CglMixedIntegerRounding mixedGen;
CglFlowCover flowGen;
// Add in generators
model.addCutGenerator(&generator1,-1,"Probing");
model.addCutGenerator(&generator2,-1,"Gomory");
model.addCutGenerator(&generator3,-1,"Knapsack");
model.addCutGenerator(&generator4,-1,"OddHole");
model.addCutGenerator(&generator5,-1,"Clique");
model.addCutGenerator(&flowGen,-1,"FlowCover");
model.addCutGenerator(&mixedGen,-1,"MixedIntegerRounding");
OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (model.solver());
// go faster stripes
if (osiclp->getNumRows()<300&&osiclp->getNumCols()<500) {
osiclp->setupForRepeatedUse(2,0);
printf("trying slightly less reliable but faster version (? Gomory cuts okay?)\n");
printf("may not be safe if doing cuts in tree which need accuracy (level 2 anyway)\n");
}
// Allow rounding heuristic
CbcRounding heuristic1(model);
model.addHeuristic(&heuristic1);
// And local search when new solution found
CbcHeuristicLocal heuristic2(model);
model.addHeuristic(&heuristic2);
// Redundant definition of default branching (as Default == User)
CbcBranchUserDecision branch;
model.setBranchingMethod(&branch);
// Definition of node choice
CbcCompareUser compare;
model.setNodeComparison(compare);
// Do initial solve to continuous
model.initialSolve();
// Could tune more
model.setMinimumDrop(CoinMin(1.0,
fabs(model.getMinimizationObjValue())*1.0e-3+1.0e-4));
if (model.getNumCols()<500)
model.setMaximumCutPassesAtRoot(-100); // always do 100 if possible
示例5: main
int main (int argc, const char *argv[])
{
// Define your favorite OsiSolver
OsiClpSolverInterface solver1;
// Read in model using argv[1]
// and assert that it is a clean model
std::string mpsFileName;
#if defined(SAMPLEDIR)
mpsFileName = SAMPLEDIR "/p0033.mps";
#else
if (argc < 2) {
fprintf(stderr, "Do not know where to find sample MPS files.\n");
exit(1);
}
#endif
if (argc>=2) mpsFileName = argv[1];
int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
assert(numMpsReadErrors==0);
double time1 = CoinCpuTime();
OsiClpSolverInterface solverSave = solver1;
/* Options are:
preprocess to do preprocessing
time in minutes
if 2 parameters and numeric taken as time
*/
bool preProcess=false;
double minutes=-1.0;
int nGoodParam=0;
for (int iParam=2; iParam<argc;iParam++) {
if (!strcmp(argv[iParam],"preprocess")) {
preProcess=true;
nGoodParam++;
} else if (!strcmp(argv[iParam],"time")) {
if (iParam+1<argc&&isdigit(argv[iParam+1][0])) {
minutes=atof(argv[iParam+1]);
if (minutes>=0.0) {
nGoodParam+=2;
iParam++; // skip time
}
}
}
}
if (nGoodParam==0&&argc==3&&isdigit(argv[2][0])) {
// If time is given then stop after that number of minutes
minutes = atof(argv[2]);
if (minutes>=0.0)
nGoodParam=1;
}
if (nGoodParam!=argc-2&&argc>=2) {
printf("Usage <file> [preprocess] [time <minutes>] or <file> <minutes>\n");
exit(1);
}
// Reduce printout
solver1.setHintParam(OsiDoReducePrint,true,OsiHintTry);
// See if we want preprocessing
OsiSolverInterface * solver2=&solver1;
CglPreProcess process;
// Never do preprocessing until dual tests out as can fix incorrectly
preProcess=false;
if (preProcess) {
/* Do not try and produce equality cliques and
do up to 5 passes */
solver2 = process.preProcess(solver1,false,5);
if (!solver2) {
printf("Pre-processing says infeasible\n");
exit(2);
}
solver2->resolve();
}
// Turn L rows into cuts
CglStoredUser stored;
{
int numberRows = solver2->getNumRows();
int * whichRow = new int[numberRows];
// get row copy
const CoinPackedMatrix * rowCopy = solver2->getMatrixByRow();
const int * column = rowCopy->getIndices();
const int * rowLength = rowCopy->getVectorLengths();
const CoinBigIndex * rowStart = rowCopy->getVectorStarts();
const double * rowLower = solver2->getRowLower();
const double * rowUpper = solver2->getRowUpper();
const double * element = rowCopy->getElements();
int iRow,nDelete=0;
for (iRow=0;iRow<numberRows;iRow++) {
if (rowLower[iRow]<-1.0e20||rowUpper[iRow]>1.0e20) {
// take out
whichRow[nDelete++]=iRow;
}
}
// leave some rows to avoid empty problem (Gomory does not like)
nDelete = CoinMax(CoinMin(nDelete,numberRows-5),0);
for (int jRow=0;jRow<nDelete;jRow++) {
iRow=whichRow[jRow];
int start = rowStart[iRow];
stored.addCut(rowLower[iRow],rowUpper[iRow],rowLength[iRow],
//.........这里部分代码省略.........