本文整理汇总了C++中OsiSolverInterface::setIntParam方法的典型用法代码示例。如果您正苦于以下问题:C++ OsiSolverInterface::setIntParam方法的具体用法?C++ OsiSolverInterface::setIntParam怎么用?C++ OsiSolverInterface::setIntParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsiSolverInterface
的用法示例。
在下文中一共展示了OsiSolverInterface::setIntParam方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: problem_convert_to_osi
void* problem_convert_to_osi(Problem *p)
{
int i;
double rowLb, rowUb;
OsiSolverInterface *solver = new OsiClpSolverInterface();
CoinBuild cb;
solver->setIntParam(OsiNameDiscipline, 2);
solver->messageHandler()->setLogLevel(0);
solver->setHintParam(OsiDoReducePrint,true,OsiHintTry);
for(i = 0; i < p->numCols; i++)
{
solver->addCol(0, NULL, NULL, p->colLb[i], p->colUb[i], p->objCoef[i]);
solver->setColName(i, p->colName[i]);
if(p->colType[i] == CONTINUOUS)
solver->setContinuous(i);
else
solver->setInteger(i);
}
for(i = 0; i < p->numRows; i++)
{
switch(p->rowSense[i])
{
case 'E':
rowLb = p->rhs[i];
rowUb = p->rhs[i];
break;
case 'L':
rowLb = -p->infty;
rowUb = p->rhs[i];
break;
case 'G':
rowLb = p->rhs[i];
rowUb = p->infty;
break;
default:
fprintf(stderr, "Error: invalid type of constraint!\n");
exit(EXIT_FAILURE);
}
cb.addRow(p->rowNElements[i], p->idxsByRow[i], p->coefsByRow[i], rowLb, rowUb);
}
solver->addRows(cb);
for(i = 0; i < p->numRows; i++)
solver->setRowName(i, p->rowName[i]);
return solver;
}
示例2: pushCbcOsiKwd
int pushCbcOsiKwd (CoinParam *param)
{
assert (param != 0) ;
CbcOsiParam *osiParam = dynamic_cast<CbcOsiParam *>(param) ;
assert (osiParam != 0) ;
OsiSolverInterface *osi = osiParam->obj() ;
assert (osi != 0) ;
std::string str = osiParam->kwdVal() ;
CbcOsiParam::CbcOsiParamCode code = osiParam->paramCode() ;
int retval = 0 ;
/*
Figure out what we're doing and set the relevant field.
*/
OsiIntParam key ;
switch (code) {
case CbcOsiParam::KEEPNAMES: {
if (str == "on" || str == "off") {
int discipline ;
if (str == "on") {
discipline = 1 ;
} else {
discipline = 0 ;
}
bool recog = osi->setIntParam(OsiNameDiscipline, discipline) ;
if (recog == false) {
std::cerr
<< "pushCbcOsiKwdParam(KEEPNAMES): underlying solver does not "
<< "recognise name discipline " << discipline << "."
<< std::endl ;
retval = +1 ;
}
} else {
std::cerr
<< "pushCbcOsiKwdParam(KEEPNAMES): unrecognised keyword `"
<< str << "'." << std::endl ;
retval = -1 ;
}
break ;
}
default: {
std::cerr
<< "pushCbcGenKwdParam: unrecognised parameter code `"
<< code << "'." << std::endl ;
retval = -1 ;
break ;
}
}
return (retval) ;
}
示例3: pushCbcOsiInt
int pushCbcOsiInt (CoinParam *param)
{
assert (param != 0) ;
CbcOsiParam *osiParam = dynamic_cast<CbcOsiParam *>(param) ;
assert (osiParam != 0) ;
OsiSolverInterface *osi = osiParam->obj() ;
assert (osi != 0) ;
int val = osiParam->intVal() ;
CbcOsiParam::CbcOsiParamCode code = osiParam->paramCode() ;
assert (osi != 0) ;
/*
Setup to return nonfatal/fatal error (1/-1) by default, so that all we need
to do is correct to 0 (no error) if we're successful.
*/
int retval ;
if (CoinParamUtils::isInteractive()) {
retval = 1 ;
} else {
retval = -1 ;
}
/*
Translate the parameter code from CbcOsiParamCode into the correct key for
CbcIntParam.
*/
OsiIntParam key ;
switch (code) {
case CbcOsiParam::MAXITERATION: {
key = OsiMaxNumIteration ;
break ;
}
case CbcOsiParam::MAXHOTITS: {
key = OsiMaxNumIterationHotStart ;
break ;
}
default: {
std::cerr << "pushCbcOsiIntParam: no equivalent OsiIntParam for "
<< "parameter code `" << code << "'." << std::endl ;
retval = -1 ;
break ;
}
}
bool setOK = osi->setIntParam(key, val) ;
if (setOK == false) {
retval = -1 ;
}
return (retval) ;
}
示例4: if
//.........这里部分代码省略.........
memcpy(saveSolution, solver->getColSolution(),
numCols * sizeof(double));
objValue = solver->getObjSense() * solver->getObjValue();
}
}
else {
delete ws;
break;
}
}
} // EOF 2 pass
//--------------------------------------------------
// If we have a set of first time object,
// branch up and down to initialize pseudo-cost.
//--------------------------------------------------
numFirsts = static_cast<int> (firstObjects.size());
//std::cout << "PSEUDO: numFirsts = " << numFirsts << std::endl;
if (numFirsts > 0) {
//std::cout << "PSEUDO: numFirsts = " << numFirsts << std::endl;
//--------------------------------------------------
// Backup solver status and mark hot start.
//--------------------------------------------------
saveLower = new double[numCols];
saveUpper = new double[numCols];
memcpy(saveLower, lower, numCols * sizeof(double));
memcpy(saveUpper, upper, numCols * sizeof(double));
CoinWarmStart * ws = solver->getWarmStart();
solver->getIntParam(OsiMaxNumIterationHotStart, saveLimit);
aveIterations = ALPS_MIN(50, aveIterations);
solver->setIntParam(OsiMaxNumIterationHotStart, aveIterations);
solver->markHotStart();
lbInd = new int [numFirsts];
ubInd = new int [numFirsts];
newLB = new double [numFirsts];
newUB = new double [numFirsts];
for (i = 0; i < numFirsts && bStatus != -2; ++i) {
colInd = firstObjects[i]->columnIndex();
lpX = saveSolution[colInd];
BlisStrongBranch(model, objValue, colInd, lpX,
saveLower, saveUpper,
downKeep, downGood, downDeg,
upKeep, upGood, upDeg);
if(!downKeep && !upKeep) {
// Both branch can be fathomed
bStatus = -2;
}
else if (!downKeep) {
// Down branch can be fathomed.
lbInd[numLowerTightens] = colInd;
newLB[numLowerTightens++] = ceil(lpX);
}
else if (!upKeep) {
// Up branch can be fathomed.
ubInd[numUpperTightens] = colInd;
示例5: if
//.........这里部分代码省略.........
// Resolve.
solver->resolve();
if (!solver->isProvenOptimal()) {
// Become infeasible, can do nothing.
bStatus = -2;
goto TERM_CREATE;
}
else {
// Save new lp solution.
memcpy(saveSolution, solver->getColSolution(),
numCols * sizeof(double));
objValue = solver->getObjSense() * solver->getObjValue();
}
}
else {
delete ws;
break;
}
}
} // EOF 2 pass
//--------------------------------------------------
// If we have a set of first time object,
// branch up and down to initialize pseudo-cost.
//--------------------------------------------------
numFirsts = static_cast<int> (firstObjects.size());
if (numFirsts > 0) {
CoinWarmStart * ws = solver->getWarmStart();
solver->getIntParam(OsiMaxNumIterationHotStart, saveLimit);
int maxIter = ALPS_MAX(model->getAveIterations(), 50);
solver->setIntParam(OsiMaxNumIterationHotStart, maxIter);
solver->markHotStart();
lbInd = new int [numFirsts];
ubInd = new int [numFirsts];
newLB = new double [numFirsts];
newUB = new double [numFirsts];
for (i = 0; i < numFirsts && bStatus != -2; ++i) {
colInd = firstObjects[i]->columnIndex();
lpX = saveSolution[colInd];
BlisStrongBranch(model, objValue, colInd, lpX,
saveLower, saveUpper,
downKeep, downGood, downDeg,
upKeep, upGood, upDeg);
if(!downKeep && !upKeep) {
// Both branch can be fathomed
bStatus = -2;
}
else if (!downKeep) {
// Down branch can be fathomed.
lbInd[numLowerTightens] = colInd;
newLB[numLowerTightens++] = ceil(lpX);
//break;
}
else if (!upKeep) {
// Up branch can be fathomed.
示例6: fixed
/* This is a utility function which does strong branching on
a list of objects and stores the results in OsiHotInfo.objects.
On entry the object sequence is stored in the OsiHotInfo object
and maybe more.
It returns -
-1 - one branch was infeasible both ways
0 - all inspected - nothing can be fixed
1 - all inspected - some can be fixed (returnCriterion==0)
2 - may be returning early - one can be fixed (last one done) (returnCriterion==1)
3 - returning because max time
*/
int
OsiChooseStrong::doStrongBranching( OsiSolverInterface * solver,
OsiBranchingInformation *info,
int numberToDo, int returnCriterion)
{
// Might be faster to extend branch() to return bounds changed
double * saveLower = NULL;
double * saveUpper = NULL;
int numberColumns = solver->getNumCols();
solver->markHotStart();
const double * lower = info->lower_;
const double * upper = info->upper_;
saveLower = CoinCopyOfArray(info->lower_,numberColumns);
saveUpper = CoinCopyOfArray(info->upper_,numberColumns);
numResults_=0;
int returnCode=0;
double timeStart = CoinCpuTime();
for (int iDo=0;iDo<numberToDo;iDo++) {
OsiHotInfo * result = results_ + iDo;
// For now just 2 way
OsiBranchingObject * branch = result->branchingObject();
assert (branch->numberBranches()==2);
/*
Try the first direction. Each subsequent call to branch() performs the
specified branch and advances the branch object state to the next branch
alternative.)
*/
OsiSolverInterface * thisSolver = solver;
if (branch->boundBranch()) {
// ordinary
branch->branch(solver);
// maybe we should check bounds for stupidities here?
solver->solveFromHotStart() ;
} else {
// adding cuts or something
thisSolver = solver->clone();
branch->branch(thisSolver);
// set hot start iterations
int limit;
thisSolver->getIntParam(OsiMaxNumIterationHotStart,limit);
thisSolver->setIntParam(OsiMaxNumIteration,limit);
thisSolver->resolve();
}
// can check if we got solution
// status is 0 finished, 1 infeasible and 2 unfinished and 3 is solution
int status0 = result->updateInformation(thisSolver,info,this);
numberStrongIterations_ += thisSolver->getIterationCount();
if (status0==3) {
// new solution already saved
if (trustStrongForSolution_) {
info->cutoff_ = goodObjectiveValue_;
status0=0;
}
}
if (solver!=thisSolver)
delete thisSolver;
// Restore bounds
for (int j=0;j<numberColumns;j++) {
if (saveLower[j] != lower[j])
solver->setColLower(j,saveLower[j]);
if (saveUpper[j] != upper[j])
solver->setColUpper(j,saveUpper[j]);
}
/*
Try the next direction
*/
thisSolver = solver;
if (branch->boundBranch()) {
// ordinary
branch->branch(solver);
// maybe we should check bounds for stupidities here?
solver->solveFromHotStart() ;
} else {
// adding cuts or something
thisSolver = solver->clone();
branch->branch(thisSolver);
// set hot start iterations
int limit;
thisSolver->getIntParam(OsiMaxNumIterationHotStart,limit);
thisSolver->setIntParam(OsiMaxNumIteration,limit);
thisSolver->resolve();
}
// can check if we got solution
// status is 0 finished, 1 infeasible and 2 unfinished and 3 is solution
int status1 = result->updateInformation(thisSolver,info,this);
numberStrongDone_++;
numberStrongIterations_ += thisSolver->getIterationCount();
if (status1==3) {
//.........这里部分代码省略.........
示例7: sci_rmps
//Solver function
int sci_rmps(char *fname)
{
//creating a problem pointer using base class of OsiSolverInterface and
//instantiate the object using derived class of ClpSolverInterface
OsiSolverInterface* si = new OsiClpSolverInterface();
// Error management variable
SciErr sciErr;
//data declarations
int *piAddressVarOne = NULL; //pointer used to access argument of the function
char* ptr; //pointer to point to address of file name
double* options_; //options to set maximum iterations
CheckInputArgument(pvApiCtx, 2,2 ); //Check we have exactly two arguments as input or not
CheckOutputArgument(pvApiCtx, 6, 6); //Check we have exactly six arguments on output side or not
//Getting the input arguments from Scilab
//Getting the MPS file path
//Reading mps file
getStringFromScilab(1,&ptr);
std::cout<<ptr;
//get options from Scilab
if(getFixedSizeDoubleMatrixInList(2 , 2 , 1 , 1 , &options_))
{
return 1;
}
//Read the MPS file
si->readMps(ptr);
//setting options for maximum iterations
si->setIntParam(OsiMaxNumIteration,options_[0]);
//Solve the problem
si->initialSolve();
//Quering about the problem
//get number of variables
double numVars_;
numVars_ = si->getNumCols();
//get number of constraint equations
double numCons_;
numCons_ = si->getNumRows();
//Output the solution to Scilab
//get solution for x
const double* xValue = si->getColSolution();
//get objective value
double objValue = si->getObjValue();
//get Status value
double status;
if(si->isProvenOptimal())
status=0;
else if(si->isProvenPrimalInfeasible())
status=1;
else if(si->isProvenDualInfeasible())
status=2;
else if(si->isIterationLimitReached())
status=3;
else if(si->isAbandoned())
status=4;
else if(si->isPrimalObjectiveLimitReached())
status=5;
else if(si->isDualObjectiveLimitReached())
status=6;
//get number of iterations
double iterations = si->getIterationCount();
//get reduced cost
const double* reducedCost = si->getReducedCost();
//get dual vector
const double* dual = si->getRowPrice();
returnDoubleMatrixToScilab(1 , 1 , numVars_ , xValue);
returnDoubleMatrixToScilab(2 , 1 , 1 , &objValue);
returnDoubleMatrixToScilab(3 , 1 , 1 , &status);
returnDoubleMatrixToScilab(4 , 1 , 1 , &iterations);
returnDoubleMatrixToScilab(5 , 1 , numVars_ , reducedCost);
returnDoubleMatrixToScilab(6 , 1 , numCons_ , dual);
free(xValue);
free(dual);
free(reducedCost);
}
示例8: main
int main(int argc, char **argv)
{
VRPH_version();
int i, j, k, n, status, num_attempts, *sol_buff, *IP_sol_buff;
char in_file[200];
double lambda, best_heur_sol=VRP_INFINITY;
bool first_sol=false, bootstrap=false;;
VRPSolution *fresh_solution;
OsiSolverInterface *si;
const double *x;
int last_num_cols=0, route_id=0;
time_t start, stop;
int *orderings[MAX_ROUTES];
for(i=0;i<MAX_ROUTES;i++)
orderings[i]=NULL;
// Set timing counters to 0
heur_time=mip_time=0;
// Check arguments
if(argc<5)
{
fprintf(stderr,"Usage: %s -f input_file -n num_runs [-v,-b,-c max_columns -d cols_to_delete]\n",
argv[0]);
fprintf(stderr,"\t Will solve the problem num_solutions times and add the routes\n");
fprintf(stderr,"\t to a set partitioning problem.\n");
fprintf(stderr,"\t Other options:\n");
fprintf(stderr,"\t -v runs in verbose mode\n");
fprintf(stderr,"\t -b will use bootstrapping where we send the set partitioning\n"
"\t solution back to the metaheuristic solver\n");
fprintf(stderr,"\t -c max_columns will allow this many active columns/variables in the IP.\n");
fprintf(stderr,"\t Default value is max_columns=500\n");
fprintf(stderr,"\t -d num_cols_to_delete will delete this many columns once we have too many\n");
fprintf(stderr,"\t in the IP. Default value is num_cols_to_delete=100\n");
exit(-1);
}
// Set defaults
verbose=false;
max_columns=500;
num_cols_to_delete=100;
// Parse command line
for(i=0;i<argc;i++)
{
if(strcmp(argv[i],"-f")==0)
strcpy(in_file,argv[i+1]);
if(strcmp(argv[i],"-n")==0)
num_attempts=atoi(argv[i+1]);
if(strcmp(argv[i],"-v")==0)
verbose=true;
if(strcmp(argv[i],"-b")==0)
bootstrap=true;
if(strcmp(argv[i],"-c")==0)
max_columns=atoi(argv[i+1]);
if(strcmp(argv[i],"-d")==0)
num_cols_to_delete=atoi(argv[i+1]);
}
// This is the # of non-VRPH_DEPOT nodes
n=VRPGetDimension(in_file);
// This will be used to import/export solutions
fresh_solution = new VRPSolution(n);
// Create buffers for importing solutions
sol_buff= new int[n+2];
IP_sol_buff = new int[n+2];
// Declare an OSI interface
si=new OsiGlpkSolverInterface;
si->setIntParam(OsiNameDiscipline,2);
for(i=0;i<n;i++)
{
si->addRow(0,NULL,NULL,1,1);
}
// Declare a VRP of the right size and import the file
VRP V(n);
ClarkeWright CW(n);
VRPRoute route(n);
V.read_TSPLIB_file(in_file);
// Set up a "route warehouse" to store the routes to be added to the IP
V.route_wh=new VRPRouteWarehouse(HASH_TABLE_SIZE);
// Set up a minimization problem
si->setObjSense(1);
// Set to error only output
si->setHintParam(OsiDoReducePrint,true, OsiHintDo);
// Unfortunately GLPK still prints out something regarding the conflict graph
for(i=0;i<num_attempts;i++)
{
if(i==0 || !bootstrap)
{
lambda=.5+1.5*lcgrand(0);
// Start with a clean VRP object
V.reset();
CW.Construct(&V, lambda, false);
//.........这里部分代码省略.........
示例9: cpropagation_preprocess
OsiSolverInterface* cpropagation_preprocess(CPropagation *cp, int nindexes[])
{
if(cp->varsToFix == 0)
{
/* printf("There are no variables to remove from the problem!\n"); */
return NULL; /* returns a pointer to original solver */
}
const double *colLb = problem_vars_lower_bound(cp->problem), *colUb = problem_vars_upper_bound(cp->problem);
const double *objCoef = problem_vars_obj_coefs(cp->problem);
const char *ctype = problem_vars_type(cp->problem);
double sumFixedObj = 0.0; /* stores the sum of objective coefficients of all variables fixed to 1 */
OsiSolverInterface *preProcSolver = new OsiClpSolverInterface();
preProcSolver->setIntParam(OsiNameDiscipline, 2);
preProcSolver->messageHandler()->setLogLevel(0);
preProcSolver->setHintParam(OsiDoReducePrint,true,OsiHintTry);
//preProcSolver->setObjName(cp->solver->getObjName());
for(int i = 0, j = 0; i < problem_num_cols(cp->problem); i++)
{
nindexes[i] = -1;
if(cp->isToFix[i] == UNFIXED)
{
preProcSolver->addCol(0, NULL, NULL, colLb[i], colUb[i], objCoef[i]);
preProcSolver->setColName(j, problem_var_name(cp->problem, i));
if(problem_var_type(cp->problem, i) == CONTINUOUS)
preProcSolver->setContinuous(j);
else
preProcSolver->setInteger(j);
nindexes[i] = j++;
}
else if(cp->isToFix[i] == ACTIVATE)
sumFixedObj += objCoef[i];
}
if(fabs(sumFixedObj) > EPS)
{
/* adding a variable with cost equals to the sum of all coefficients of variables fixed to 1 */
preProcSolver->addCol(0, NULL, NULL, 1.0, 1.0, sumFixedObj);
preProcSolver->setColName(preProcSolver->getNumCols()-1, "sumFixedObj");
preProcSolver->setInteger(preProcSolver->getNumCols()-1);
}
for(int idxRow = 0; idxRow < problem_num_rows(cp->problem); idxRow++)
{
const int nElements = problem_row_size(cp->problem, idxRow);
const int *idxs = problem_row_idxs(cp->problem, idxRow);
const double *coefs = problem_row_coefs(cp->problem, idxRow);
vector< int > vidx; vidx.reserve(problem_num_cols(cp->problem));
vector< double > vcoef; vcoef.reserve(problem_num_cols(cp->problem));
double activeCoefs = 0.0;
for(int i = 0; i < nElements; i++)
{
if(cp->isToFix[idxs[i]] == UNFIXED)
{
assert(nindexes[idxs[i]] >= 0 && nindexes[idxs[i]] < problem_num_cols(cp->problem));
vidx.push_back(nindexes[idxs[i]]);
vcoef.push_back(coefs[i]);
}
else if(cp->isToFix[idxs[i]] == ACTIVATE)
activeCoefs += coefs[i];
}
if(!vidx.empty())
{
double rlb, rub;
const char sense = problem_row_sense(cp->problem, idxRow);
if(sense == 'E')
{
rlb = problem_row_rhs(cp->problem, idxRow) - activeCoefs;
rub = problem_row_rhs(cp->problem, idxRow) - activeCoefs;
}
else if(sense == 'L')
{
rlb = preProcSolver->getInfinity();
rub = problem_row_rhs(cp->problem, idxRow) - activeCoefs;
}
else if(sense == 'G')
{
rlb = problem_row_rhs(cp->problem, idxRow) - activeCoefs;
rub = preProcSolver->getInfinity();
}
else
{
fprintf(stderr, "Error: invalid type of constraint!\n");
exit(EXIT_FAILURE);
}
preProcSolver->addRow((int)vcoef.size(), &vidx[0], &vcoef[0], rlb, rub);
preProcSolver->setRowName(idxRow, problem_row_name(cp->problem, idxRow));
}
}
return preProcSolver;
}