本文整理汇总了C++中OsiClpSolverInterface::isContinuous方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiClpSolverInterface::isContinuous方法的具体用法?C++ OsiClpSolverInterface::isContinuous怎么用?C++ OsiClpSolverInterface::isContinuous使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiClpSolverInterface
的用法示例。
在下文中一共展示了OsiClpSolverInterface::isContinuous方法的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: 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++;
}
//.........这里部分代码省略.........