本文整理汇总了C++中OsiClpSolverInterface::columnType方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiClpSolverInterface::columnType方法的具体用法?C++ OsiClpSolverInterface::columnType怎么用?C++ OsiClpSolverInterface::columnType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiClpSolverInterface
的用法示例。
在下文中一共展示了OsiClpSolverInterface::columnType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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++;
}
//.........这里部分代码省略.........