13 #ifndef OsiTMINLPInterface_H
14 #define OsiTMINLPInterface_H
21 #include "OsiSolverInterface.hpp"
22 #include "CoinWarmStartBasis.hpp"
33 class RegisteredOptions;
34 class StrongBranchingSolver;
68 std::string methodName,
69 std::string
f = std::string(),
72 CoinError(message,methodName,std::string(
"OsiTMINLPInterface"),
f, l)
78 #define SimpleError(x, y) SimpleError((x), (y), __FILE__, __LINE__)
83 return app_->newUnsolvedError(num, problem, name);
144 const std::string &
prefix,
152 initialize(roptions, options, journalist,
"bonmin.", tminlp);
166 OsiSolverInterface *
clone(
bool copyData =
true)
const;
189 return app_->prefix();
213 virtual void resolve(
const char * whereFrom);
227 throw SimpleError(
"Function not implemented for OsiTMINLPInterface",
"branchAndBound()");
254 hasContinuedAfterNlpFailure_ =
true;
262 return newCutoffDecr;
274 return hasContinuedAfterNlpFailure_;
279 pretendFailIsInfeasible_ = 2;
284 problem_->set_obj_value(1e200);
289 problem_->set_obj_value(-1e200);
290 problem_->force_fractionnal_sol();
316 bool setStrParam(OsiStrParam key,
const std::string & value);
318 bool getIntParam(OsiIntParam key,
int& value)
const;
320 bool getDblParam(OsiDblParam key,
double& value)
const;
322 bool getStrParam(OsiStrParam key, std::string& value)
const;
353 const OsiSolverInterface::OsiNameVec&
getVarNames() ;
408 virtual bool isBinary(
int columnNumber)
const;
414 virtual bool isInteger(
int columnNumber)
const;
484 return nCallOptimizeTNLP_;
489 return totalNlpSolveTime_;
494 return totalIterations_;
506 virtual void setColLower(
int elementIndex,
double elementValue );
510 virtual void setColUpper(
int elementIndex,
double elementValue );
525 virtual void setRowLower(
int elementIndex,
double elementValue );
529 virtual void setRowUpper(
int elementIndex,
double elementValue );
532 virtual void setRowType(
int index,
char sense,
double rightHandSide,
574 virtual bool setWarmStart(
const CoinWarmStart* warmstart);
580 return warmStartMode_;
589 throw SimpleError(
"Needs coding for this interface",
"basisIsAvailable");
607 numIterationSuspect_ = value;
649 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
655 virtual void addCol(
const CoinPackedVectorBase& vec,
656 const double collb,
const double colub,
659 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
664 virtual void deleteCols(
const int num,
const int * colIndices)
666 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
672 virtual void addRow(
const CoinPackedVectorBase& vec,
673 const double rowlb,
const double rowub)
675 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
680 virtual void addRow(
const CoinPackedVectorBase& vec,
681 const char rowsen,
const double rowrhs,
684 throw SimpleError(
"OsiTMINLPInterface model does not implement this function.",
689 virtual void deleteRows(
const int num,
const int * rowIndices)
693 problem_->removeCuts(num, rowIndices);
700 const double* collb,
const double* colub,
702 const double* rowlb,
const double* rowub)
704 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
712 double*& collb,
double*& colub,
double*& obj,
713 double*& rowlb,
double*& rowub)
715 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
722 const double* collb,
const double* colub,
724 const char* rowsen,
const double* rowrhs,
725 const double* rowrng)
727 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
734 double*& collb,
double*& colub,
double*& obj,
735 char*& rowsen,
double*& rowrhs,
738 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
746 const int* start,
const int* index,
748 const double* collb,
const double* colub,
750 const double* rowlb,
const double* rowub)
752 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
759 const int* start,
const int* index,
761 const double* collb,
const double* colub,
763 const char* rowsen,
const double* rowrhs,
764 const double* rowrng)
766 throw SimpleError(
"OsiTMINLPInterface model does not implement this function.",
773 const char *extension =
"mps")
775 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
783 const char *extension =
"mps",
784 double objSense=0.0)
const
786 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
791 virtual std::vector<double*>
getDualRays(
int maxNumRays,
bool fullRay =
false)
const
793 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
800 throw SimpleError(
"OsiTMINLPInterface does not implement this function.",
816 app_->setOutputToDefault();}
818 app_->forceSolverOutput(log_level);}
854 const std::list<Ipopt::SmartPtr<TNLPSolver> >&
debug_apps()
const{
886 app_->enableWarmStart();
910 double theta,
bool global);
915 const double *
x2,
bool global);
919 const double *
x2,
bool global){
950 void switchToFeasibilityProblem(
size_t n,
const double * x_bar,
const int* ind,
double a,
double s,
int L);
954 void switchToFeasibilityProblem(
size_t n,
const double * x_bar,
const int* ind,
955 double rhs_local_branching_constraint);
958 void switchToOriginalProblem();
961 void round_and_check(
double tolerance,
962 OsiObject ** objects = 0,
int nObjects = -1){
963 if(!problem_->check_solution(objects, nObjects)){
973 enum OaMessagesTypes {
974 CUT_NOT_VIOLATED_ENOUGH = 0,
975 VIOLATED_OA_CUT_GENERATED,
977 OA_MESSAGES_DUMMY_END};
979 class OaMessages :
public CoinMessages{
985 class OaMessageHandler :
public CoinMessageHandler{
988 OaMessageHandler():CoinMessageHandler(){
991 OaMessageHandler(FILE * fp):CoinMessageHandler(fp){
994 virtual ~OaMessageHandler(){
997 OaMessageHandler(
const OaMessageHandler &other):
998 CoinMessageHandler(other){}
1000 OaMessageHandler(
const CoinMessageHandler &other):
1001 CoinMessageHandler(other){}
1003 OaMessageHandler &
operator=(
const OaMessageHandler &rhs){
1004 CoinMessageHandler::operator=(rhs);
1007 virtual CoinMessageHandler*
clone()
const{
1008 return new OaMessageHandler(*
this);}
1010 void print(OsiRowCut &row);
1012 void setOaMessageHandler(
const CoinMessageHandler &handler){
1014 oaHandler_ =
new OaMessageHandler(handler);
1021 virtual ApplyCutsReturnCode applyCuts(
const OsiCuts & cs,
1022 double effectivenessLb = 0.0){
1024 problem_->addCuts(cs);
1025 ApplyCutsReturnCode rc;
1029 virtual void applyRowCuts(
int numberCuts,
const OsiRowCut * cuts);
1033 virtual void applyRowCuts(
int numberCuts,
const OsiRowCut ** cuts)
1037 problem_->addCuts(numberCuts, cuts);
1042 double getConstraintsViolation(
const double *
x,
double & obj);
1046 double getNonLinearitiesViolation(
const double *
x,
const double obj);
1050 void extractInterfaceParams();
1061 return app_->roptions();
1072 virtual void markHotStart();
1076 virtual void solveFromHotStart();
1079 virtual void unmarkHotStart();
1083 void get_tolerances(
double &tiny,
double&very_tiny,
double &rhsRelax,
double &
infty){
1085 very_tiny = veryTiny_;
1086 rhsRelax = rhsRelax_;
1097 enum RandomGenerationType{
1098 uniform =0, perturb=1, perturb_suffix=2};
1100 int initializeJacobianArrays();
1104 virtual std::string appName()
1113 void solveAndCheckErrors(
bool doResolve,
bool throwOnFailure,
1114 const char * whereFrom);
1119 virtual void applyRowCut(
const OsiRowCut & rc )
1121 const OsiRowCut * cut = &rc;
1122 problem_->addCuts(1, &cut);
1126 virtual void applyColCut(
const OsiColCut & cc )
1128 throw SimpleError(
"Ipopt model does not implement this function.",
1146 bool feasibility_mode_;
1151 std::list<Ipopt::SmartPtr<TNLPSolver> > debug_apps_;
1157 CoinWarmStart* warmstart_;
1162 void freeCachedColRim();
1164 void freeCachedRowRim();
1166 void freeCachedData();
1169 void extractSenseRhsAndRange()
const;
1171 mutable char *rowsense_;
1174 mutable double *rhs_;
1177 mutable double *rowrange_;
1180 mutable double *reducedCosts_;
1182 double OsiDualObjectiveLimit_;
1184 mutable bool hasVarNamesFile_;
1186 int nCallOptimizeTNLP_;
1189 double totalNlpSolveTime_;
1191 int totalIterations_;
1193 double maxRandomRadius_;
1195 int randomGenerationType_;
1197 double max_perturbation_;
1201 int numRetryInitial_;
1203 int numRetryResolve_;
1205 int numRetryInfeasibles_;
1207 int numRetryUnsolved_;
1209 double infeasibility_epsilon_;
1216 double coeff_var_threshold_;
1218 double first_perc_for_cutoff_decr_;
1220 double second_perc_for_cutoff_decr_;
1228 int pretendFailIsInfeasible_;
1230 mutable int pretendSucceededNext_;
1233 bool hasContinuedAfterNlpFailure_;
1236 int numIterationSuspect_ ;
1240 bool hasBeenOptimized_;
1244 mutable double * obj_;
1246 static bool hasPrintedOptions;
1267 Ipopt::TNLP::LinearityType * constTypes_;
1292 OaMessages oaMessages_;
1294 OaMessageHandler * oaHandler_;
1297 double newCutoffDecr;
1303 const std::string &
prefix);
1308 bool internal_setWarmStart(
const CoinWarmStart*
ws);
1311 CoinWarmStart* internal_getWarmStart()
const;
1314 CoinWarmStart* build_fake_basis()
const;
1321 static const char * OPT_SYMB;
1322 static const char * FAILED_SYMB;
1323 static const char * INFEAS_SYMB;
1324 static const char * TIME_SYMB;
1325 static const char * UNBOUND_SYMB;
1331 return INFEAS_SYMB;}
1333 return UNBOUND_SYMB;}
1336 else return FAILED_SYMB;
1338 const char * statusAsString(){
1339 return statusAsString(optimizationStatus_);}
bool getIntParam(OsiIntParam key, int &value) const
TNLPSolver::UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)
Base class for all MINLPs that use a standard triplet matrix form and dense vectors.
double getNewCutoffDecr()
Are there a numerical difficulties?
virtual double getInfinity() const
Get solver's value for infinity.
virtual bool isAbandoned() const
Are there a numerical difficulties?
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound.
void getOuterApproximation(OsiCuts &cs, int getObj, const double *x2, bool global)
Get the outer approximation constraints at the current optimal point.
virtual void loadProblem(const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub)
We have to keep this but it will throw an error.
Solver
Solvers for solving nonlinear programs.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
const double * getDownPsCosts() const
Get number of columns.
WarmStartModes getWarmStartMode()
Get an empty warm start object.
filterSQP Sequential Quadratic Programming algorithm.
Output the number of the problem.
virtual bool isPrimalObjectiveLimitReached() const
Is the given primal objective limit reached?
const TMINLP2TNLP * problem() const
get pointer to the TMINLP2TNLP adapter
const double * getUpPsCosts() const
Get number of columns.
const Ipopt::SmartPtr< Ipopt::OptionsList > options() const
Retrieve OsiTMINLPApplication option list.
void getConstraintOuterApproximation(OsiCuts &cs, int constraintNumber, const double *x2, bool global)
Get the outer approximation at current optimal point for given constraint.
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
void forceBranchable()
Force current solution to be branched on (make it fractionnal with small objective) ...
virtual bool isInteger(int columnNumber) const
Return true if column is integer.
void fint fint fint real * a
OsiSolverInterface * clone(bool copyData=true) const
Virtual copy constructor.
virtual int getNumElements() const
Cbc will understand that no matrix exsits if return -1.
virtual void deleteRows(const int num, const int *rowIndices)
We have to keep this but it will throw an error.
bool IsValid(const OSSmartPtr< U > &smart_ptr)
virtual int getNumRows() const
Get number of rows.
Head of "civilized" log.
virtual void branchAndBound()
Nescessary for compatibility with OsiSolverInterface but does nothing.
This is a generic class for calling an NLP solver to solve a TNLP.
double * downPsCosts
User set down pseudo costs.
void use(Ipopt::SmartPtr< TMINLP2TNLP > tminlp2tnlp)
Sets the TMINLP2TNLP to be used by the interface.
virtual CoinWarmStart * getEmptyWarmStart() const
Get an empty warm start object.
virtual void setContinuous(int index)
Set the index-th variable to be a continuous variable.
virtual void resolveForCost(int numretry, bool keepWs)
Resolve the problem with different random starting points to try to find a better solution (only make...
const int * getBranchingDirections() const
get prefered branching directions
Different solver gives different status for problem.
First line (first solve) of log.
Output the number of the problem.
virtual int getNumCols() const
Get number of columns.
virtual bool isProvenOptimal() const
Is optimality proven?
virtual void initialSolve()
Solve initial continuous relaxation.
virtual double getObjValue() const
Get objective function value (can't use default)
Warn that a problem is resolved.
const int * getPriorities() const
Get priorities on integer variables.
int * branchingDirections
User set preferered branching direction.
virtual void loadProblem(const int numcols, const int numrows, const int *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng)
We have to keep this but it will throw an error.
void fint fint fint real fint real real real real * f
virtual const double * getObjCoefficients() const
This returns the objective function gradient at the current point.
SimpleError(std::string message, std::string methodName, std::string f=std::string(), int l=-1)
Alternate constructor using strings.
virtual const CoinPackedMatrix * getMatrixByCol() const
We have to keep this but it will return NULL.
double totalNlpSolveTime()
get total time taken to solve NLP's.
void ignoreFailures()
tell to ignore the failures (don't throw, don't fathom, don't report)
const Bonmin::TNLPSolver * solver() const
double solveFeasibilityProblem(size_t n, const double *x_bar, const int *ind, double a, double s, int L)
Given a point x_bar this solves the problem of finding the point which minimize a convex combination ...
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
virtual void setObjCoeff(int elementIndex, double elementValue)
We have to keep this but it will throw an error.
int * priorities
User set priorities on variables.
Error class to throw exceptions from OsiTMINLPInterface.
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound.
virtual int readMps(const char *filename, const char *extension="mps")
We have to keep this but it will throw an error.
virtual double getObjSense() const
Get objective function sense (1 for min (default), -1 for max) Always minimizes.
bool getStrParam(OsiStrParam key, std::string &value) const
void setNumIterationSuspect(int value)
void getBendersCut(OsiCuts &cs, bool global)
Get a benders cut from solution.
found a feasible solution
virtual void getConstraintOuterApproximation(OsiCuts &cs, int constraintNumber, const double *x, const double *x2, bool global)
Get the outer approximation at provided point for given constraint.
virtual void resolve()
Resolve the continuous relaxation after problem modification.
virtual void addCol(const CoinPackedVectorBase &vec, const double collb, const double colub, const double obj)
We have to keep this but it will throw an error.
void readOptionFile(const std::string &fileName)
Read parameter file.
void setSolver(Ipopt::SmartPtr< TNLPSolver > app)
Set the solver to be used by interface.
bool hasContinuedOnAFailure()
Did we continue on a failure.
virtual void setRowUpper(int elementIndex, double elementValue)
Set a single row upper bound.
virtual void setColSolution(const double *colsol)
Set the primal solution variable values Set the values for the starting point.
virtual void setRowType(int index, char sense, double rightHandSide, double range)
Set the type of a single row.
virtual bool isFreeBinary(int columnNumber) const
Return true if column is binary and not fixed at either bound.
bool setStrParam(OsiStrParam key, const std::string &value)
void forceInfeasible()
Force current solution to be infeasible.
Found a better solution with random values.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
virtual bool isIterationLimitReached() const
Iteration limit reached?
virtual const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
virtual void deleteCols(const int num, const int *colIndices)
We have to keep this but it will throw an error.
virtual const double * getRightHandSide() const
Get pointer to array[getNumRows()] of rows right-hand sides.
void fint fint fint real fint real real real real real real real * r
virtual bool isProvenDualInfeasible() const
Is dual infeasiblity proven?
void initialize(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions, Ipopt::SmartPtr< Ipopt::OptionsList > options, Ipopt::SmartPtr< Ipopt::Journalist > journalist, Ipopt::SmartPtr< TMINLP > tminlp)
Facilitator to initialize interface.
virtual void loadProblem(const int numcols, const int numrows, const int *start, const int *index, const double *value, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub)
We have to keep this but it will throw an error.
int totalIterations()
get total number of iterations
void setWarmStartMode(int mode)
Get an empty warm start object.
virtual bool isDualObjectiveLimitReached() const
Is the given dual objective limit reached?
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real * ws
virtual bool isContinuous(int colNumber) const
Return true if column is continuous.
void forceSolverOutput(int log_level)
virtual const char * getRowSense() const
Get pointer to array[getNumRows()] of row constraint senses.
virtual int getIterationCount() const
Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver...
virtual void assignProblem(CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, double *&rowlb, double *&rowub)
We have to keep this but it will throw an error.
virtual bool isIntegerNonBinary(int columnNumber) const
Return true if column is general integer.
Recomputed integer feasible with alternate objective function.
void setModel(Ipopt::SmartPtr< TMINLP > tminlp)
Set the model to be solved by interface.
ReturnStatus
Standard return statuses for a solver.
standard line (retry solving) of log.
virtual void setObjSense(double s)
Set the objective function sense (disabled).
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.
void setNewCutoffDecr(double d)
Are there a numerical difficulties?
double getPushFact() const
void getOuterApproximation(OsiCuts &cs, const double *x, int getObj, const double *x2, bool global)
Get the outer approximation constraints at provided point.
const char * prefix() const
Default Constructor.
virtual std::vector< double * > getDualRays(int maxNumRays, bool fullRay=false) const
Throws an error.
virtual CoinWarmStart * getWarmStart() const
Get warmstarting information.
const TMINLP * model() const
Warn that there are equality or ranged constraints and OA may works bad.
found an infeasible problem
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual prices.
virtual ~OsiTMINLPInterface()
Destructor.
int nCallOptimizeTNLP()
get total number of calls to solve.
virtual void setRowPrice(const double *rowprice)
Set dual solution variable values.
MessagesTypes
Type of the messages specifically written by OsiTMINLPInterface.
resolve() has been called but there was no previous call to initialSolve().
virtual const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
We will throw this error when a problem is not solved.
virtual void addObjectiveFunction(OsiSolverInterface &si, const double *x)
Add constraint corresponding to objective function.
Stores branching priorities information.
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
virtual void assignProblem(CoinPackedMatrix *&matrix, double *&collb, double *&colub, double *&obj, char *&rowsen, double *&rowrhs, double *&rowrng)
We have to keep this but it will throw an error.
virtual bool basisIsAvailable() const
Get an empty warm start object.
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
bool setIntParam(OsiIntParam key, int value)
virtual void resolveForRobustness(int numretry)
Method to be called when a problem has failed to be solved.
void randomStartingPoint()
Get an empty warm start object.
Trying to access non-existent TNLPSolver.
virtual bool isBinary(int columnNumber) const
Return true if column is binary.
virtual void writeMps(const char *filename, const char *extension="mps", double objSense=0.0) const
We have to keep this but it will throw an error.
virtual const CoinPackedMatrix * getMatrixByRow() const
We have to keep this but it will return NULL.
OsiTMINLPInterface & operator=(const OsiTMINLPInterface &rhs)
Assignment operator.
virtual void loadProblem(const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const char *rowsen, const double *rowrhs, const double *rowrng)
We have to keep this but it will throw an error.
bool setDblParam(OsiDblParam key, double value)
virtual std::vector< double * > getPrimalRays(int maxNumRays) const
Throws an error.
virtual void addRow(const CoinPackedVectorBase &vec, const char rowsen, const double rowrhs, const double rowrng)
We have to keep this but it will throw an error.
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warmstarting information.
This is an adapter class that converts a TMINLP to a TNLP to be solved by Ipopt.
found an unsolved problem
virtual void addRow(const CoinPackedVectorBase &vec, const double rowlb, const double rowub)
We have to keep this but it will throw an error.
const std::list< Ipopt::SmartPtr< TNLPSolver > > & debug_apps() const
Messages written by an OsiTMINLPInterface.
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 setColLower(int elementIndex, double elementValue)
Set a single column lower bound.
a failure occured but is continuing
void continuingOnAFailure()
Warn solver that branch-and-bound is continuing after a failure.
OsiTMINLPInterface()
Default Constructor.
const OsiSolverInterface::OsiNameVec & getVarNames()
get name of variables
Subproblem not solve with warm start but solved with random point.
virtual void extractLinearRelaxation(OsiSolverInterface &si, const double *x, bool getObj=1)
Extract a linear relaxation of the MINLP.
Output summary statistics on Ipopt solution.
void setSolverOutputToDefault()
Problem not solved with warm start but solved without.
Different solver gives different optimal value for problem.
bool getDblParam(OsiDblParam key, double &value) const
double * upPsCosts
User set up pseudo costs.
void fint fint fint real fint real * x
virtual void extractLinearRelaxation(OsiSolverInterface &si, bool getObj=1, bool solveNlp=1)
Extract a linear relaxation of the MINLP.