22 #include "OSParameters.h"
53 using namespace Couenne;
63 #include "CoinTime.hpp"
71 #ifdef COIN_HAS_FILTERSQP
75 #include "CbcCutGenerator.hpp"
90 using namespace Bonmin;
91 using namespace Couenne;
93 using std::ostringstream;
98 using namespace Ipopt;
103 couenneErrorMsg =
"";
123 if(m_osilreader != NULL)
128 if(m_osolreader != NULL)
delete m_osolreader;
146 this->bCallbuildSolverInstance =
true;
150 std::ostringstream outStr;
152 if(osil.length() == 0 &&
osinstance == NULL)
throw ErrorClass(
"there is no instance");
165 if( n_allvars < 0 )
throw ErrorClass(
"Couenne solver Cannot have a negatiave number of Variables");
169 outStr <<
"NUMBER OF VARIABLES = " << n_allvars << std::endl;
185 for (i = 0; i < n_allvars; ++i)
187 if( (varType[i] ==
'B') || (varType[i]) ==
'I' )
189 couenne->addVariable(
true, couenne->domain() );
193 couenne->addVariable(
false, couenne->domain() );
199 couenne->domain()->push(n_allvars, x_, lb, ub);
210 throw ErrorClass(
"Solver cannot handle multiple objectives --- please delete all but one");
216 for ( i = 0; i < nterms; ++i)
218 lin[i].first = couenne->Var( sv->
indexes[ i] );
221 lin[i].second = sv->
values[ i];
225 lin[i].second = -sv->
values[ i];
236 nl[0] = createCouenneExpression( exptree->
m_treeRoot );
250 couenne->addObjective(obj_body,
"min");
263 for (i = 0; i < nconss; ++i)
268 for (j = 0; j < row_nonz; ++
j)
270 con_lin[
j].first = couenne->Var( sm->
indexes[ kount] );
271 con_lin[
j].second = sm->
values[ kount];
278 nl[0] = createCouenneExpression(exptree->
m_treeRoot);
279 con_body =
new exprGroup(0., con_lin, nl, 1);
283 con_body =
new exprGroup(0., con_lin, NULL, 0);
286 if (rowlb[ i] == rowub[ i])
288 couenne->addEQConstraint(con_body,
new exprConst( rowub[ i] ));
293 couenne->addLEConstraint(con_body,
new exprConst( rowub[ i] ));
298 couenne->addGEConstraint(con_body,
new exprConst( rowlb[ i] ));
301 couenne->addRNGConstraint(con_body,
new exprConst( rowlb[ i]),
new
305 catch(
const ErrorClass& eclass)
310 osrl = osrlwriter->writeOSrL(
osresult);
311 throw ErrorClass( osrl) ;
319 std::ostringstream outStr;
331 return createCouenneExpression(node->
m_mChildren[0]);
335 sumargs[i] = createCouenneExpression(node->
m_mChildren[i]);
362 return createCouenneExpression(node->
m_mChildren[0]);
366 args[i] = createCouenneExpression(node->
m_mChildren[i]);
390 return createCouenneExpression(node->
m_mChildren[0]);
394 args[i] = createCouenneExpression(node->
m_mChildren[i]);
404 return createCouenneExpression(node->
m_mChildren[0]);
408 args[i] = createCouenneExpression(node->
m_mChildren[i]);
421 if (varnode->
coef == 0.)
423 if (varnode->
coef == 1.)
424 return new exprClone(couenne->Variables()[varnode->
idx]);
425 if (varnode->
coef == -1.)
432 outStr << node->
getTokenName() <<
" NOT IMPLEMENTED!!" << endl;
443 std::ostringstream outStr;
448 bSetSolverOptions =
true;
449 couenneSetup.initializeOptionsAndJournalist();
451 couenneSetup.options()->SetIntegerValue(
"bonmin.bb_log_level", 0);
452 couenneSetup.options()->SetIntegerValue(
"bonmin.nlp_log_level", 0 );
453 if(
osoption == NULL && osol.length() > 0)
456 osoption = m_osolreader->readOSoL( osol);
462 std::vector<SolverOption*> optionsVector;
464 int num_bonmin_options = optionsVector.size();
465 std::string optionName;
467 for(i = 0; i < num_bonmin_options; i++)
469 if(optionsVector[ i]->category ==
"ipopt")
471 optionName = optionsVector[ i]->name;
475 if(optionsVector[ i]->category ==
"bonmin" )
477 optionName =
"bonmin."+optionsVector[ i]->name;
481 optionName =
"couenne."+optionsVector[ i]->name;
487 outStr <<
"found option " << optionName <<
" of type " << optionsVector[ i]->type << std::endl;
490 if(optionsVector[ i]->type ==
"numeric" )
492 couenneSetup.options()->SetNumericValue(optionName,
os_strtod( optionsVector[ i]->value.c_str(), &pEnd ) );
494 else if(optionsVector[ i]->type ==
"integer" )
496 couenneSetup.options()->SetIntegerValue(optionName, atoi( optionsVector[ i]->value.c_str() ) );
498 else if(optionsVector[ i]->type ==
"string" )
500 couenneSetup.options()->SetStringValue(optionName, optionsVector[ i]->value );
506 catch(
const ErrorClass& eclass)
511 osrl = osrlwriter->writeOSrL(
osresult);
512 throw ErrorClass( osrl) ;
518 using namespace Ipopt;
523 #define PRINTED_PRECISION 1e-5
526 if( this->bCallbuildSolverInstance ==
false) buildSolverInstance();
527 if(this->bSetSolverOptions ==
false) setSolverOptions() ;
535 bb.setProblem(couenne);
539 if(
osoption == NULL && osol.length() > 0)
542 osoption = m_osolreader->readOSoL( osol);
553 couenneSetup.options(),
554 couenneSetup.journalist(),
558 couenneSetup.options(),
559 couenneSetup.journalist()
566 bool setupInit =
false;
567 setupInit = couenneSetup.InitializeCouenne(argv, couenne, NULL, ci);
570 if(setupInit ==
false)
572 std::string solutionDescription =
"";
573 std::string message =
"Couenne solver finishes to the end.";
576 throw ErrorClass(
"OSResult error: setServiceName");
578 throw ErrorClass(
"OSResult error: setInstanceName");
580 throw ErrorClass(
"OSResult error: setVariableNumer");
582 throw ErrorClass(
"OSResult error: setObjectiveNumber");
584 throw ErrorClass(
"OSResult error: setConstraintNumber");
586 throw ErrorClass(
"OSResult error: setSolutionNumer");
588 throw ErrorClass(
"OSResult error: setGeneralMessage");
589 solutionDescription =
"COUENNE INITIALIZE PROBLEM: \n There was a problem with Couenne Initialize: \n the problem could be infeasible \n there may be zero decision variables";
592 osrl = osrlwriter->writeOSrL(
osresult);
603 std::string solutionDescription =
"";
604 std::string message =
"Success";
607 throw ErrorClass(
"OSResult error: setServiceName");
609 throw ErrorClass(
"OSResult error: setInstanceName");
611 throw ErrorClass(
"OSResult error: setVariableNumer");
613 throw ErrorClass(
"OSResult error: setObjectiveNumber");
615 throw ErrorClass(
"OSResult error: setConstraintNumber");
617 throw ErrorClass(
"OSResult error: setSolutionNumer");
619 throw ErrorClass(
"OSResult error: setGeneralMessage");
620 solutionDescription =
"CONTINUOUS_UNBOUNDED [COUENNE]: The continuous relaxation is unbounded, the MINLP may or may not be unbounded.";
623 osrl = osrlwriter->writeOSrL(
osresult);
631 if (bb.model (). cutGenerators ())
632 cg = dynamic_cast <CouenneCutGenerator *>
633 (bb.model (). cutGenerators () [0] -> generator ());
637 couenneSetup.options () -> GetNumericValue (
"couenne_check", global_opt,
"couenne.");
638 double timeLimit = 0;
639 couenneSetup.options () -> GetNumericValue (
"time_limit", timeLimit,
"couenne.");
642 status = tminlp->status;
646 catch(
const ErrorClass& eclass)
650 osrl = osrlwriter->writeOSrL(
osresult);
651 throw ErrorClass( osrl) ;
667 osrl = osrlwriter->writeOSrL(
osresult);
668 throw ErrorClass( osrl) ;
673 ostringstream outStr;
674 outStr << E.className() <<
"::"<< E.methodName() << std::endl << E.message() << std::endl;
678 osrl = osrlwriter->writeOSrL(
osresult);
679 throw ErrorClass( osrl) ;
684 ostringstream outStr;
685 outStr << E.className() <<
"::"<< E.methodName() << std::endl << E.message() << std::endl;
689 osrl = osrlwriter->writeOSrL(
osresult);
690 throw ErrorClass( osrl);
693 catch (Ipopt::OPTION_INVALID &E)
695 ostringstream outStr;
696 outStr <<
"Ipopt exception : " << E.Message() << std::endl;
700 osrl = osrlwriter->writeOSrL(
osresult);
701 throw ErrorClass( osrl);
703 catch (
int generic_error)
705 if (generic_error == infeasible)
709 osrl = osrlwriter->writeOSrL(
osresult);
710 throw ErrorClass( osrl);
723 std::string solutionDescription =
"";
724 std::string message =
"Couenne solver finishes to the end.";
734 throw ErrorClass(
"OSResult error: setSolverInvoked");
736 throw ErrorClass(
"OSResult error: setServiceName");
738 throw ErrorClass(
"OSResult error: setInstanceName");
742 throw ErrorClass(
"OSResult error: setVariableNumer");
744 throw ErrorClass(
"OSResult error: setObjectiveNumber");
746 throw ErrorClass(
"OSResult error: setConstraintNumber");
748 throw ErrorClass(
"OSResult error: setSolutionNumer");
750 throw ErrorClass(
"OSResult error: setGeneralMessage");
754 case TMINLP::SUCCESS:
755 solutionDescription =
"SUCCESS[COUENNE]: Algorithm terminated normally at a locally optimal point, satisfying the convergence tolerances.";
763 if(fabs(*(z + 0)) == 9.999
e+12)
765 solutionDescription =
"CONTINUOUS_UNBOUNDED [COUENNE]: Continuous relaxation is unbounded, the MINLP may or may not be unbounded.";
777 *(x + i) = bb.bestSolution()[i];
784 case TMINLP::LIMIT_EXCEEDED:
785 solutionDescription =
"LIMIT_EXCEEDED[COUENNE]: A resource limit was exceeded, we provide the current solution.";
798 *(x + i) = bb.model().getColSolution()[i];
804 case TMINLP::MINLP_ERROR:
805 solutionDescription =
"MINLP_ERROR [COUENNE]: Algorithm stopped with unspecified error.";
810 case TMINLP::CONTINUOUS_UNBOUNDED:
811 solutionDescription =
"CONTINUOUS_UNBOUNDED [COUENNE]: The continuous relaxation is unbounded, the MINLP may or may not be unbounded.";
816 case TMINLP::INFEASIBLE:
817 solutionDescription =
"INFEASIBLE [COUENNE]: Problem may be infeasible.";
822 solutionDescription =
"OTHER[COUENNE]: other unknown solution status from Couenne solver";
827 osrl = osrlwriter->writeOSrL(
osresult);
843 osrl = osrlwriter->writeOSrL(
osresult);
Cut Generator for linear convexifications.
double * getConstraintLowerBounds()
Get constraint lower bounds.
double * getVariableLowerBounds()
Get variable lower bounds.
double * getConstraintUpperBounds()
Get constraint upper bounds.
~CouenneSolver()
the IpoptSolver class destructor
double coef
coef is an option coefficient on the variable, the default value is 1.0
std::string OSgetVersionInfo()
double os_strtod(const char *s00, char **se)
int getNumberOfIntegerVariables()
getNumberOfIntegerVariables
void writeResult()
use this to write the solution information to an OSResult object
char * getVariableTypes()
Get variable initial values.
ScalarExpressionTree * getNonlinearExpressionTree(int rowIdx)
Get the expression tree for a given row index.
bool setSolutionStatus(int solIdx, std::string type, std::string description)
Set the [i]th optimization solution status, where i equals the given solution index.
bool setPrimalVariableValuesDense(int solIdx, double *x)
Set the [i]th optimization solution's primal variable values, where i equals the given solution index...
class Group, with constant, linear and nonlinear terms:
const OSSmartPtr< OSOutput > osoutput
int getVariableNumber()
Get number of variables.
bool setServiceName(std::string serviceName)
Set service name.
bool setVariableNumber(int variableNumber)
Set the variable number.
unsigned int inumberOfChildren
inumberOfChildren is the number of OSnLNode child elements If this number is not fixed, e.g., for a sum node, it is temporarily set to 0
int idx
idx is the index of the variable
std::string errormsg
errormsg is the error that is causing the exception to be thrown
virtual void solve()
solve results in an instance being read into the Couenne data structrues and optimized ...
std::vector< SolverOption * > getSolverOptions(std::string solver_name)
Get the options associated with a given solver.
SparseVector ** getObjectiveCoefficients()
Get objective coefficients.
Power of an expression (binary operator), with constant.
bool setSolverInvoked(std::string solverInvoked)
Set solver invoked.
void writeDiffFiles(const std::string prefix=std::string()) const
write files with differences between input model and this one
Take an OSResult object and write a string that validates against OSrL.
int getObjectiveNumber()
Get number of objectives.
bool setObjectiveNumber(int objectiveNumber)
Set the objective number.
bool setInstanceName(std::string instanceName)
Set instance name.
Couenne::expression * createCouenneExpression(OSnLNode *node)
int inodeInt
inodeInt is the unique integer assigned to the OSnLNode or OSnLMNode in OSParameters.h.
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
bool setSolutionNumber(int number)
set the number of solutions.
The OSnLNodeNumber Class.
Used to hold part of the instance in memory.
void fint fint fint real fint real real real real real real real real real * e
Error class to throw exceptions from OsiTMINLPInterface.
Used to read an OSiL string.
virtual void setSolverOptions()
The implementation of the virtual functions.
a sparse matrix data structure
void setSolver(Ipopt::SmartPtr< TNLPSolver > app)
Set the solver to be used by interface.
SparseMatrix * getLinearConstraintCoefficientsInRowMajor()
Get linear constraint coefficients in row major.
The OSnLNodeVariable Class.
Class for MINLP problems with symbolic information.
void printError(std::ostream &os)
Print error message.
expression clone (points to another expression)
std::string * getObjectiveMaxOrMins()
Get objective maxOrMins.
a sparse vector data structure
OSnLNode ** m_mChildren
m_mChildren holds all the operands, that is, nodes that the current node operates on...
bool setGeneralMessage(std::string message)
Set the general message.
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
double * getObjectiveConstants()
Get objective constants.
bool setGeneralStatusType(std::string type)
Set the general status type, which can be: success, error, warning.
OSnLNode * m_treeRoot
m_treeRoot holds the root node (of OSnLNode type) of the expression tree.
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
std::string getInstanceName()
Get instance name.
static const int infeasible
int number
number is the number of elements in the indexes and values arrays.
void setModel(Ipopt::SmartPtr< TMINLP > tminlp)
Set the model to be solved by interface.
std::vector< std::pair< exprVar *, CouNumber > > lincoeff
double CouNumber
main number type in Couenne
int getConstraintNumber()
Get number of constraints.
bool setConstraintNumber(int constraintNumber)
Set the constraint number.
int getNumberOfSolverOptions()
Get the number of solver options.
Used to read an OSoL string.
bool initForAlgDiff()
This should be called by nonlinear solvers using callback functions.
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
double * values
values holds a double array of nonzero values.
double * calculateAllObjectiveFunctionValues(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
Calculate all of the objective function values.
CouenneSolver()
the CouenneSolver class constructor
We will throw this error when a problem is not solved.
double * getVariableUpperBounds()
Get variable upper bounds.
bool setObjectiveValuesDense(int solIdx, double *objectiveValues)
Set the [i]th optimization solution's objective values, where i equals the given solution index...
int * indexes
indexes holds an integer array of indexes whose corresponding values are nonzero. ...
class for the exponential,
The OSnLNode Class for nonlinear expressions.
virtual std::string getTokenName()=0
void initialize(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions, Ipopt::SmartPtr< Ipopt::OptionsList > options, Ipopt::SmartPtr< Ipopt::Journalist > journalist, const std::string &prefix, Ipopt::SmartPtr< TMINLP > tminlp)
Facilitator to initialize interface.
virtual void buildSolverInstance()
buildSolverInstance is a virtual function – the actual solvers will implement their own buildSolverIn...
used for throwing exceptions.
int getNumberOfBinaryVariables()
getNumberOfBinaryVariables
void fint fint fint real fint real * x
class for multiplications,