12 #ifndef CouenneMINLPInterface_hpp
13 #define CouenneMINLPInterface_hpp
20 #include "OsiSolverInterface.hpp"
194 CouenneMINLPInterface (
const CouenneMINLPInterface &);
197 OsiSolverInterface * clone (
bool copyData =
true)
const;
200 CouenneMINLPInterface & operator=(
const CouenneMINLPInterface& rhs);
203 virtual ~CouenneMINLPInterface ();
206 void readOptionFile(
const std::string & fileName);
217 virtual void initialSolve();
226 virtual void resolve();
232 virtual void resolveForCost(
int numretry,
bool keepWs);
237 virtual void resolveForRobustness(
int numretry);
240 virtual void branchAndBound()
251 virtual bool isAbandoned ()
const;
252 virtual bool isProvenOptimal ()
const;
253 virtual bool isProvenPrimalInfeasible ()
const;
254 virtual bool isProvenDualInfeasible ()
const;
255 virtual bool isPrimalObjectiveLimitReached ()
const;
256 virtual bool isDualObjectiveLimitReached ()
const;
257 virtual bool isIterationLimitReached ()
const;
260 void continuingOnAFailure()
262 hasContinuedAfterNlpFailure_ =
true;
266 bool hasContinuedOnAFailure()
268 return hasContinuedAfterNlpFailure_;
272 void ignoreFailures()
274 pretendFailIsInfeasible_ = 2;
278 void forceInfeasible()
284 void forceBranchable()
309 bool setIntParam(OsiIntParam key,
int value);
311 bool setDblParam(OsiDblParam key,
double value);
313 bool setStrParam(OsiStrParam key,
const std::string & value);
315 bool getIntParam(OsiIntParam key,
int& value)
const;
317 bool getDblParam(OsiDblParam key,
double& value)
const;
319 bool getStrParam(OsiStrParam key, std::string& value)
const;
322 inline double getPushFact()
const
345 virtual int getNumCols()
const;
349 virtual int getNumRows()
const;
352 const OsiSolverInterface::OsiNameVec& getVarNames() ;
354 virtual const double * getColLower()
const;
357 virtual const double * getColUpper()
const;
368 virtual const char * getRowSense()
const;
378 virtual const double * getRightHandSide()
const;
388 virtual const double * getRowRange()
const;
391 virtual const double * getRowLower()
const;
394 virtual const double * getRowUpper()
const;
398 virtual double getObjSense()
const
404 virtual bool isContinuous(
int colNumber)
const;
407 virtual bool isBinary(
int columnNumber)
const;
412 virtual bool isInteger (
int columnNumber)
const;
415 virtual bool isIntegerNonBinary(
int columnNumber)
const;
418 virtual bool isFreeBinary(
int columnNumber)
const;
421 virtual double getInfinity()
const;
424 const int * getPriorities()
const
426 const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
428 return branch->priorities;
433 const int * getBranchingDirections()
const
435 const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
437 return branch->branchingDirections;
441 const double * getUpPsCosts()
const
443 const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
445 return branch->upPsCosts;
449 const double * getDownPsCosts()
const
451 const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
453 return branch->downPsCosts;
463 virtual const double * getColSolution()
const;
466 virtual const double * getRowPrice()
const;
469 virtual const double * getReducedCost()
const;
473 virtual const double * getRowActivity()
const;
481 virtual int getIterationCount ()
const;
484 int nCallOptimizeTNLP()
486 return nCallOptimizeTNLP_;
490 double totalNlpSolveTime()
492 return totalNlpSolveTime_;
496 int totalIterations()
498 return totalIterations_;
511 virtual void setColLower(
int elementIndex,
double elementValue );
515 virtual void setColUpper(
int elementIndex,
double elementValue );
520 virtual void setColLower(
const double * array);
525 virtual void setColUpper(
const double * array);
530 virtual void setRowLower(
int elementIndex,
double elementValue );
533 virtual void setRowUpper(
int elementIndex,
double elementValue );
536 virtual void setRowType(
int index,
char sense,
double rightHandSide,
544 virtual void setObjSense(
double s);
550 virtual void setColSolution(
const double *colsol);
556 virtual void setRowPrice(
const double * rowprice);
572 virtual CoinWarmStart *getEmptyWarmStart ()
const;
575 virtual CoinWarmStart* getWarmStart()
const;
579 virtual bool setWarmStart(
const CoinWarmStart* warmstart);
581 void setExposeWarmStart(
bool value) {
582 exposeWarmStart_ = value;
585 bool getExposeWarmStart() {
586 return exposeWarmStart_;
589 void randomStartingPoint();
592 virtual bool basisIsAvailable()
const
595 throw SimpleError(
"Needs coding for this interface",
"basisIsAvailable");
604 virtual void setContinuous(
int index);
607 virtual void setInteger(
int index);
611 void setNumIterationSuspect(
int value)
613 numIterationSuspect_ = value;
626 virtual int getNumElements()
const
636 virtual const double * getObjCoefficients()
const;
640 virtual const CoinPackedMatrix * getMatrixByRow()
const
648 virtual const CoinPackedMatrix * getMatrixByCol()
const
655 virtual void setObjCoeff(
int elementIndex,
double elementValue )
657 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
663 virtual void addCol(
const CoinPackedVectorBase& vec,
664 const double collb,
const double colub,
667 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
673 virtual void deleteCols(
const int num,
const int * colIndices)
675 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
681 virtual void addRow(
const CoinPackedVectorBase& vec,
682 const double rowlb,
const double rowub)
684 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
690 virtual void addRow(
const CoinPackedVectorBase& vec,
691 const char rowsen,
const double rowrhs,
694 throw SimpleError(
"CouenneMINLPInterface model does not implement this function.",
699 virtual void deleteRows(
const int num,
const int * rowIndices)
703 problem_->removeCuts(num, rowIndices);
709 virtual void loadProblem(
const CoinPackedMatrix& matrix,
710 const double* collb,
const double* colub,
712 const double* rowlb,
const double* rowub)
714 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
721 virtual void assignProblem(CoinPackedMatrix*& matrix,
722 double*& collb,
double*& colub,
double*& obj,
723 double*& rowlb,
double*& rowub)
725 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
731 virtual void loadProblem(
const CoinPackedMatrix& matrix,
732 const double* collb,
const double* colub,
734 const char* rowsen,
const double* rowrhs,
735 const double* rowrng)
737 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
743 virtual void assignProblem(CoinPackedMatrix*& matrix,
744 double*& collb,
double*& colub,
double*& obj,
745 char*& rowsen,
double*& rowrhs,
748 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
755 virtual void loadProblem(
const int numcols,
const int numrows,
756 const int* start,
const int* index,
758 const double* collb,
const double* colub,
760 const double* rowlb,
const double* rowub)
762 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
768 virtual void loadProblem(
const int numcols,
const int numrows,
769 const int* start,
const int* index,
771 const double* collb,
const double* colub,
773 const char* rowsen,
const double* rowrhs,
774 const double* rowrng)
776 throw SimpleError(
"CouenneMINLPInterface model does not implement this function.",
782 virtual int readMps(
const char *filename,
783 const char *extension =
"mps")
785 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
792 virtual void writeMps(
const char *filename,
793 const char *extension =
"mps",
794 double objSense=0.0)
const
796 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
801 virtual std::vector<double*> getDualRays(
int maxNumRays)
const
803 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
808 virtual std::vector<double*> getPrimalRays(
int maxNumRays)
const
810 throw SimpleError(
"CouenneMINLPInterface does not implement this function.",
825 void turnOffSolverOutput(){
826 app_->turnOffOutput();}
827 void turnOnSolverOutput(){
828 app_->turnOnOutput();}
833 virtual double getObjValue()
const;
839 const TMINLP2TNLP *
problem()
const
849 const TMINLP * model()
const
864 TNLPSolver * solver()
876 virtual void extractLinearRelaxation(OsiSolverInterface &si,
const double *
x,
883 virtual void extractLinearRelaxation(OsiSolverInterface &si,
bool getObj = 1,
887 extractLinearRelaxation(si, getColSolution(), getObj);
889 app_->enableWarmStart();
890 setColSolution(
problem()->x_sol());
891 setRowPrice(
problem()->duals_sol());
898 void getOuterApproximation(OsiCuts &cs,
bool getObj,
const double *
x2,
bool global)
900 getOuterApproximation(cs, getColSolution(), getObj, x2, global);
906 void getOuterApproximation(OsiCuts &cs,
const double *
x,
bool getObj,
const double * x2,
bool global){
907 getOuterApproximation(cs, x, getObj, x2, 0., global);}
912 virtual void getOuterApproximation(OsiCuts &cs,
const double *
x,
bool getObj,
const double * x2,
913 double theta,
bool global);
916 virtual void getConstraintOuterApproximation(OsiCuts & cs,
int constraintNumber,
918 const double * x2,
bool global);
921 void getConstraintOuterApproximation(OsiCuts & cs,
int constraintNumber,
922 const double * x2,
bool global){
923 getConstraintOuterApproximation(cs, constraintNumber, getColSolution(),x2,global);
927 void getBendersCut(OsiCuts &cs,
const double *
x,
const double *lambda,
bool getObj = 1);
936 double getFeasibilityOuterApproximation(
int n,
const double * x_bar,
const int *ind, OsiCuts &cs,
bool addOnlyViolated,
bool global);
947 double solveFeasibilityProblem(
int n,
const double * x_bar,
const int* ind,
double a,
double s,
int L);
957 double solveFeasibilityProblem(
int n,
const double * x_bar,
const int* ind,
int L,
double cutoff);
961 void switchToFeasibilityProblem(
int n,
const double * x_bar,
const int* ind,
double a,
double s,
int L);
965 void switchToFeasibilityProblem(
int n,
const double * x_bar,
const int* ind,
966 double rhs_local_branching_constraint);
969 void switchToOriginalProblem();
975 enum OaMessagesTypes {
977 CUT_NOT_VIOLATED_ENOUGH = 0,
978 VIOLATED_OA_CUT_GENERATED,
980 OA_MESSAGES_DUMMY_END
984 class OaMessages :
public CoinMessages{
991 class OaMessageHandler :
public CoinMessageHandler{
994 OaMessageHandler():CoinMessageHandler(){
997 OaMessageHandler(FILE * fp):CoinMessageHandler(fp){
1000 virtual ~OaMessageHandler(){
1003 OaMessageHandler(
const OaMessageHandler &other):
1004 CoinMessageHandler(other){}
1006 OaMessageHandler(
const CoinMessageHandler &other):
1007 CoinMessageHandler(other){}
1009 OaMessageHandler & operator=(
const OaMessageHandler &rhs){
1010 CoinMessageHandler::operator=(rhs);
1013 virtual CoinMessageHandler* clone()
const{
1014 return new OaMessageHandler(*
this);}
1016 void print(OsiRowCut &row);
1019 void setOaMessageHandler(
const CoinMessageHandler &handler){
1021 oaHandler_ =
new OaMessageHandler(handler);
1028 virtual ApplyCutsReturnCode applyCuts(
const OsiCuts & cs,
1029 double effectivenessLb = 0.0){
1032 ApplyCutsReturnCode rc;
1036 virtual void applyRowCuts(
int numberCuts,
const OsiRowCut * cuts);
1040 virtual void applyRowCuts(
int numberCuts,
const OsiRowCut ** cuts)
1044 problem_->addCuts(numberCuts, cuts);
1048 obj the objective value of
x.
1049 double getConstraintsViolation(
const double *
x,
double & obj);
1052 value where obj is the estimated objective value of
x.
1053 double getNonLinearitiesViolation(
const double *
x,
const double obj);
1057 void extractInterfaceParams();
1068 return app_->roptions();
1079 virtual void markHotStart();
1083 virtual void solveFromHotStart();
1086 virtual void unmarkHotStart();
1093 enum RandomGenerationType{
1094 uniform =0, perturb=1, perturb_suffix=2};
1096 int initializeJacobianArrays();
1103 void solveAndCheckErrors(
bool doResolve,
bool throwOnFailure,
1104 const char * whereFrom);
1109 virtual void applyRowCut(
const OsiRowCut & rc )
1111 const OsiRowCut * cut = &rc;
1116 virtual void applyColCut(
const OsiColCut & cc )
1118 throw SimpleError(
"Ipopt model does not implement this function.",
1136 bool feasibility_mode_;
1141 std::list<Ipopt::SmartPtr<TNLPSolver> > debug_apps_;
1147 CoinWarmStart* warmstart_;
1151 void freeCachedColRim();
1154 void freeCachedRowRim();
1156 void freeCachedData();
1159 void extractSenseRhsAndRange()
const;
1161 mutable char *rowsense_;
1164 mutable double *rhs_;
1167 mutable double *rowrange_;
1170 mutable double *reducedCosts_;
1172 double OsiDualObjectiveLimit_;
1174 mutable bool hasVarNamesFile_;
1176 int nCallOptimizeTNLP_;
1179 double totalNlpSolveTime_;
1181 int totalIterations_;
1183 double maxRandomRadius_;
1185 int randomGenerationType_;
1187 double max_perturbation_;
1191 int numRetryInitial_;
1193 int numRetryResolve_;
1195 int numRetryInfeasibles_;
1197 int numRetryUnsolved_;
1203 int pretendFailIsInfeasible_;
1205 bool hasContinuedAfterNlpFailure_;
1208 int numIterationSuspect_ ;
1212 bool hasBeenOptimized_;
1216 mutable double * obj_;
1218 static bool hasPrintedOptions;
1237 Ipopt::TNLP::LinearityType * constTypes_;
1248 TNLPSolver::ReturnStatus optimizationStatus_;
1250 bool exposeWarmStart_;
1254 SmartPtr<CutStrengthener> cutStrengthener_;
1259 OaMessages oaMessages_;
1262 OaMessageHandler * oaHandler_;
1273 bool internal_setWarmStart(
const CoinWarmStart*
ws);
1276 CoinWarmStart* internal_getWarmStart()
const;
1279 SmartPtr<StrongBranchingSolver> strong_branching_solver_;
1281 TNLPSolver::ReturnStatus optimizationStatusBeforeHotStart_;
1282 static const char * OPT_SYMB;
1283 static const char * FAILED_SYMB;
1284 static const char * INFEAS_SYMB;
1285 static const char * UNBOUND_SYMB;
1287 const char * statusAsString(TNLPSolver::ReturnStatus
r){
1288 if(r == TNLPSolver::solvedOptimal || r == TNLPSolver::solvedOptimalTol){
1290 else if(r == TNLPSolver::provenInfeasible){
1291 return INFEAS_SYMB;}
1292 else if(r == TNLPSolver::unbounded){
1293 return UNBOUND_SYMB;}
1294 else return FAILED_SYMB;
1296 const char * statusAsString(){
1297 return statusAsString(optimizationStatus_);}
Base class for all MINLPs that use a standard triplet matrix form and dense vectors.
CouNumber solve(CouNumber *solution)
solves and returns the optimal objective function and the solution
void setInitSol(const CouNumber *sol)
sets the initial solution for the NLP solver
void setObj(int index, expression *newObj)
REMOVE — backward compatibility sets objective[index] at newObj.
void fint fint fint real * a
bool IsValid(const OSSmartPtr< U > &smart_ptr)
Ipopt interior point algorithm
This is a generic class for calling an NLP solver to solve a TNLP.
CouenneProblem * problem() const
return pointer to Couenne problem
Solver
Solvers for solving nonlinear programs.
Ipopt::OptionsList * options_
Options.
Ipopt::OptionsList * options() const
return pointer to options
filterSQP Sequential Quadratic Programming algorithm
virtual std::string appName()
Virtual callback for application specific stuff.
Class for MINLP problems with symbolic information.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
void fint fint fint real fint real real real real real real real * r
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
double CouNumber
main number type in Couenne
CouenneProblem * problem_
Symbolic representation of the problem.
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
void fint fint fint real fint real * x
bool isInteger(CouNumber x)
is this number integer?