Bonmin  1.8.8
BonOsiTMINLPInterface.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation, Carnegie Mellon University 2004, 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, Carnegie Mellon University,
7 // Carl D. Laird, Carnegie Mellon University,
8 // Andreas Waechter, International Business Machines Corporation
9 //
10 // Date : 12/01/2004
11 
12 
13 #ifndef OsiTMINLPInterface_H
14 #define OsiTMINLPInterface_H
15 
16 #define INT_BIAS 0e-8
17 
18 #include <string>
19 #include <iostream>
20 
21 #include "OsiSolverInterface.hpp"
22 #include "CoinWarmStartBasis.hpp"
23 
24 #include "BonCutStrengthener.hpp"
25 //#include "BonRegisteredOptions.hpp"
26 
27 namespace Bonmin {
28  class TMINLP;
29  class TMINLP2TNLP;
30  class TMINLP2OsiLP;
31  class TNLP2FPNLP;
32  class TNLPSolver;
33  class RegisteredOptions;
34  class StrongBranchingSolver;
35 
37  enum Solver{
38  EIpopt=0 ,
41  };
48 class OsiTMINLPInterface : public OsiSolverInterface
49 {
50  friend class BonminParam;
51 
52 public:
53 
54  //#############################################################################
55 
60 class SimpleError : public CoinError
61  {
62  private:
63  SimpleError();
64 
65  public:
67  SimpleError(std::string message,
68  std::string methodName,
69  std::string f = std::string(),
70  int l = -1)
71  :
72  CoinError(message,methodName,std::string("OsiTMINLPInterface"), f, l)
73  {}
74  }
75  ;
76 
77 #ifdef __LINE__
78 #define SimpleError(x, y) SimpleError((x), (y), __FILE__, __LINE__)
79 #endif
80 
81  // Error when problem is not solved
82  TNLPSolver::UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr<TMINLP2TNLP> problem, std::string name){
83  return app_->newUnsolvedError(num, problem, name);
84  }
85  //#############################################################################
86 
92 
118  };
119 
120  //#############################################################################
121 
122 
124 class Messages : public CoinMessages
125  {
126  public:
128  Messages();
129  };
130 
131 
132  //#############################################################################
133 
134 
139 
141  void initialize(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
142  Ipopt::SmartPtr<Ipopt::OptionsList> options,
143  Ipopt::SmartPtr<Ipopt::Journalist> journalist,
144  const std::string & prefix,
145  Ipopt::SmartPtr<TMINLP> tminlp);
146 
148  void initialize(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
149  Ipopt::SmartPtr<Ipopt::OptionsList> options,
150  Ipopt::SmartPtr<Ipopt::Journalist> journalist,
151  Ipopt::SmartPtr<TMINLP> tminlp){
152  initialize(roptions, options, journalist, "bonmin.", tminlp);
153  }
154 
156  void setModel(Ipopt::SmartPtr<TMINLP> tminlp);
158  void setSolver(Ipopt::SmartPtr<TNLPSolver> app);
160  void use(Ipopt::SmartPtr<TMINLP2TNLP> tminlp2tnlp);
164 
166  OsiSolverInterface * clone(bool copyData = true) const;
167 
170 
172  virtual ~OsiTMINLPInterface ();
173 
174 
176  void readOptionFile(const std::string & fileName);
177 
179  const Ipopt::SmartPtr<Ipopt::OptionsList> options() const;
181  Ipopt::SmartPtr<Ipopt::OptionsList> options();
182 
183  const char * prefix() const{
184  if(!IsValid(app_)) {
185  messageHandler()->message(ERROR_NO_TNLPSOLVER, messages_)<<CoinMessageEol;
186  return NULL;
187  }
188  else
189  return app_->prefix();
190  }
192  //---------------------------------------------------------------------------
195  virtual void initialSolve();
197 
199  virtual void initialSolve(const char * whereFrom);
200 
206  virtual void resolve();
207 
213  virtual void resolve(const char * whereFrom);
214 
217  virtual void resolveForCost(int numretry, bool keepWs);
218 
222  virtual void resolveForRobustness(int numretry);
223 
225  virtual void branchAndBound()
226  {
227  throw SimpleError("Function not implemented for OsiTMINLPInterface","branchAndBound()");
228  }
230 
231 
232 
233  //---------------------------------------------------------------------------
235 
236  virtual bool isAbandoned() const;
239  virtual bool isProvenOptimal() const;
241  virtual bool isProvenPrimalInfeasible() const;
243  virtual bool isProvenDualInfeasible() const;
245  virtual bool isPrimalObjectiveLimitReached() const;
247  virtual bool isDualObjectiveLimitReached() const;
249  virtual bool isIterationLimitReached() const;
250 
253  {
254  hasContinuedAfterNlpFailure_ = true;
255  }
256 
257 
258  //Added by Claudia
259 
261  {
262  return newCutoffDecr;
263  }
264 
265  void setNewCutoffDecr(double d)
266  {
267  newCutoffDecr = d;
268  }
269 
270 
273  {
274  return hasContinuedAfterNlpFailure_;
275  }
278  {
279  pretendFailIsInfeasible_ = 2;
280  }
283  {
284  problem_->set_obj_value(1e200);
285  }
288  {
289  problem_->set_obj_value(-1e200);
290  problem_->force_fractionnal_sol();
291  }
293 
294 
295  //---------------------------------------------------------------------------
311  // Set an integer parameter
312  bool setIntParam(OsiIntParam key, int value);
313  // Set an double parameter
314  bool setDblParam(OsiDblParam key, double value);
315  // Set a string parameter
316  bool setStrParam(OsiStrParam key, const std::string & value);
317  // Get an integer parameter
318  bool getIntParam(OsiIntParam key, int& value) const;
319  // Get an double parameter
320  bool getDblParam(OsiDblParam key, double& value) const;
321  // Get a string parameter
322  bool getStrParam(OsiStrParam key, std::string& value) const;
323 
324  // Get the push values for starting point
325  inline double getPushFact() const
326  {
327  return pushValue_;
328  }
329 
331 
332 
333  //---------------------------------------------------------------------------
346  virtual int getNumCols() const;
348 
350  virtual int getNumRows() const;
351 
353  const OsiSolverInterface::OsiNameVec& getVarNames() ;
355  virtual const double * getColLower() const;
356 
358  virtual const double * getColUpper() const;
359 
369  virtual const char * getRowSense() const;
370 
379  virtual const double * getRightHandSide() const;
380 
389  virtual const double * getRowRange() const;
390 
392  virtual const double * getRowLower() const;
393 
395  virtual const double * getRowUpper() const;
396 
399  virtual double getObjSense() const
400  {
401  return 1;
402  }
403 
405  virtual bool isContinuous(int colNumber) const;
406 
408  virtual bool isBinary(int columnNumber) const;
409 
414  virtual bool isInteger(int columnNumber) const;
415 
417  virtual bool isIntegerNonBinary(int columnNumber) const;
418 
420  virtual bool isFreeBinary(int columnNumber) const;
421 
423  virtual double getInfinity() const;
424 
426  const int * getPriorities() const
427  {
428  const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
429  if(branch)
430  return branch->priorities;
431  else return NULL;
432  }
434  const int * getBranchingDirections() const
435  {
436  const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
437  if(branch)
438  return branch->branchingDirections;
439  else return NULL;
440  }
441  const double * getUpPsCosts() const
442  {
443  const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
444  if(branch)
445  return branch->upPsCosts;
446  else return NULL;
447  }
448  const double * getDownPsCosts() const
449  {
450  const TMINLP::BranchingInfo * branch = tminlp_->branchingInfo();
451  if(branch)
452  return branch->downPsCosts;
453  else return NULL;
454  }
455 
456 
458 
461  virtual const double * getColSolution() const;
463 
465  virtual const double * getRowPrice() const;
466 
468  virtual const double * getReducedCost() const;
469 
472  virtual const double * getRowActivity() const;
473 
474 
479  virtual int getIterationCount() const;
480 
483  {
484  return nCallOptimizeTNLP_;
485  }
488  {
489  return totalNlpSolveTime_;
490  }
493  {
494  return totalIterations_;
495  }
496 
497 
499  //-------------------------------------------------------------------------
503 
506  virtual void setColLower( int elementIndex, double elementValue );
507 
510  virtual void setColUpper( int elementIndex, double elementValue );
511 
515  virtual void setColLower(const double * array);
516 
520  virtual void setColUpper(const double * array);
521 
522 
525  virtual void setRowLower( int elementIndex, double elementValue );
526 
529  virtual void setRowUpper( int elementIndex, double elementValue );
530 
532  virtual void setRowType(int index, char sense, double rightHandSide,
533  double range);
534 
535 
540  virtual void setObjSense(double s);
541 
546  virtual void setColSolution(const double *colsol);
547 
552  virtual void setRowPrice(const double * rowprice);
553 
555 
556 
557  //---------------------------------------------------------------------------
560 
567  virtual CoinWarmStart *getEmptyWarmStart () const;
568 
570  virtual CoinWarmStart* getWarmStart() const;
571 
574  virtual bool setWarmStart(const CoinWarmStart* warmstart);
575 
576  void setWarmStartMode(int mode) {
577  warmStartMode_ = (WarmStartModes) mode;
578  }
580  return warmStartMode_;
581  }
582 
583  void randomStartingPoint();
584 
585  //Returns true if a basis is available
586  virtual bool basisIsAvailable() const
587  {
588  // Throw an exception
589  throw SimpleError("Needs coding for this interface", "basisIsAvailable");
590  }
591 
592 
594 
595  //-------------------------------------------------------------------------
599  virtual void setContinuous(int index);
601  virtual void setInteger(int index);
603 
604  //Set numIterationSuspect_
605  void setNumIterationSuspect(int value)
606  {
607  numIterationSuspect_ = value;
608  }
609 
615 
618  virtual int getNumElements() const
619  {
620  return -1;
621  }
622 
623 
628  virtual const double * getObjCoefficients() const;
629 
632  virtual const CoinPackedMatrix * getMatrixByRow() const
633  {
634  return NULL;
635  }
636 
637 
640  virtual const CoinPackedMatrix * getMatrixByCol() const
641  {
642  return NULL;
643  }
644 
647  virtual void setObjCoeff( int elementIndex, double elementValue )
648  {
649  throw SimpleError("OsiTMINLPInterface does not implement this function.",
650  "setObjCoeff");
651  }
652 
655  virtual void addCol(const CoinPackedVectorBase& vec,
656  const double collb, const double colub,
657  const double obj)
658  {
659  throw SimpleError("OsiTMINLPInterface does not implement this function.",
660  "addCol");
661  }
664  virtual void deleteCols(const int num, const int * colIndices)
665  {
666  throw SimpleError("OsiTMINLPInterface does not implement this function.",
667  "deleteCols");
668  }
669 
672  virtual void addRow(const CoinPackedVectorBase& vec,
673  const double rowlb, const double rowub)
674  {
675  throw SimpleError("OsiTMINLPInterface does not implement this function.",
676  "addRow");
677  }
680  virtual void addRow(const CoinPackedVectorBase& vec,
681  const char rowsen, const double rowrhs,
682  const double rowrng)
683  {
684  throw SimpleError("OsiTMINLPInterface model does not implement this function.",
685  "addRow");
686  }
689  virtual void deleteRows(const int num, const int * rowIndices)
690  {
691  if(num)
692  freeCachedRowRim();
693  problem_->removeCuts(num, rowIndices);
694  }
695 
696 
699  virtual void loadProblem(const CoinPackedMatrix& matrix,
700  const double* collb, const double* colub,
701  const double* obj,
702  const double* rowlb, const double* rowub)
703  {
704  throw SimpleError("OsiTMINLPInterface does not implement this function.",
705  "loadProblem");
706  }
707 
708 
711  virtual void assignProblem(CoinPackedMatrix*& matrix,
712  double*& collb, double*& colub, double*& obj,
713  double*& rowlb, double*& rowub)
714  {
715  throw SimpleError("OsiTMINLPInterface does not implement this function.",
716  "assignProblem");
717  }
718 
721  virtual void loadProblem(const CoinPackedMatrix& matrix,
722  const double* collb, const double* colub,
723  const double* obj,
724  const char* rowsen, const double* rowrhs,
725  const double* rowrng)
726  {
727  throw SimpleError("OsiTMINLPInterface does not implement this function.",
728  "loadProblem");
729  }
730 
733  virtual void assignProblem(CoinPackedMatrix*& matrix,
734  double*& collb, double*& colub, double*& obj,
735  char*& rowsen, double*& rowrhs,
736  double*& rowrng)
737  {
738  throw SimpleError("OsiTMINLPInterface does not implement this function.",
739  "assignProblem");
740  }
741 
742 
745  virtual void loadProblem(const int numcols, const int numrows,
746  const int* start, const int* index,
747  const double* value,
748  const double* collb, const double* colub,
749  const double* obj,
750  const double* rowlb, const double* rowub)
751  {
752  throw SimpleError("OsiTMINLPInterface does not implement this function.",
753  "loadProblem");
754  }
755 
758  virtual void loadProblem(const int numcols, const int numrows,
759  const int* start, const int* index,
760  const double* value,
761  const double* collb, const double* colub,
762  const double* obj,
763  const char* rowsen, const double* rowrhs,
764  const double* rowrng)
765  {
766  throw SimpleError("OsiTMINLPInterface model does not implement this function.",
767  "loadProblem");
768  }
769 
772  virtual int readMps(const char *filename,
773  const char *extension = "mps")
774  {
775  throw SimpleError("OsiTMINLPInterface does not implement this function.",
776  "readMps");
777  }
778 
779 
782  virtual void writeMps(const char *filename,
783  const char *extension = "mps",
784  double objSense=0.0) const
785  {
786  throw SimpleError("OsiTMINLPInterface does not implement this function.",
787  "writeMps");
788  }
789 
791  virtual std::vector<double*> getDualRays(int maxNumRays, bool fullRay = false) const
792  {
793  throw SimpleError("OsiTMINLPInterface does not implement this function.",
794  "getDualRays");
795  }
796 
798  virtual std::vector<double*> getPrimalRays(int maxNumRays) const
799  {
800  throw SimpleError("OsiTMINLPInterface does not implement this function.",
801  "getPrimalRays");
802  }
803 
805 
806 
807 
808  //---------------------------------------------------------------------------
809 
810 
811 
816  app_->setOutputToDefault();}
817  void forceSolverOutput(int log_level){
818  app_->forceSolverOutput(log_level);}
820 
823  virtual double getObjValue() const;
825 
827 
829  const TMINLP2TNLP * problem() const
830  {
831  return GetRawPtr(problem_);
832  }
833 
835  {
836  return GetRawPtr(problem_);
837  }
838 
839  const TMINLP * model() const
840  {
841  return GetRawPtr(tminlp_);
842  }
843 
845  {
846  return GetRawPtr(tminlp_);
847  }
848 
849  const Bonmin::TNLPSolver * solver() const
850  {
851  return GetRawPtr(app_);
852  }
853 
854  const std::list<Ipopt::SmartPtr<TNLPSolver> >& debug_apps() const{
855  return debug_apps_;
856  }
857 
859  {
860  return GetRawPtr(app_);
861  }
870  virtual void extractLinearRelaxation(OsiSolverInterface &si, const double *x,
871  bool getObj = 1);
872 
874  virtual void addObjectiveFunction(OsiSolverInterface &si, const double * x);
875 #if 1
876 
880  virtual void extractLinearRelaxation(OsiSolverInterface &si, bool getObj = 1,
881  bool solveNlp = 1){
882  if(solveNlp)
883  initialSolve("build initial OA");
884  extractLinearRelaxation(si, getColSolution(), getObj);
885  if(solveNlp){
886  app_->enableWarmStart();
887  setColSolution(problem()->x_sol());
888  setRowPrice(problem()->duals_sol());
889  }
890  }
891 #endif
892 
895  void getOuterApproximation(OsiCuts &cs, int getObj, const double * x2, bool global)
896 {
897  getOuterApproximation(cs, getColSolution(), getObj, x2, global);
898 }
899 
903  void getOuterApproximation(OsiCuts &cs, const double * x, int getObj, const double * x2, bool global){
904  getOuterApproximation(cs, x, getObj, x2, 0., global);}
905 
909  virtual void getOuterApproximation(OsiCuts &cs, const double * x, int getObj, const double * x2,
910  double theta, bool global);
911 
913  virtual void getConstraintOuterApproximation(OsiCuts & cs, int constraintNumber,
914  const double * x,
915  const double * x2, bool global);
916 
918  void getConstraintOuterApproximation(OsiCuts & cs, int constraintNumber,
919  const double * x2, bool global){
920  getConstraintOuterApproximation(cs, constraintNumber, getColSolution(),x2,global);
921  }
922 
923 
925 void getBendersCut(OsiCuts &cs, bool global);
926 
936  double solveFeasibilityProblem(size_t n, const double * x_bar, const int* ind, double a, double s, int L);
937 
946  double solveFeasibilityProblem(size_t n, const double * x_bar, const int* ind, int L, double cutoff);
947 
950  void switchToFeasibilityProblem(size_t n, const double * x_bar, const int* ind, double a, double s, int L);
951 
954  void switchToFeasibilityProblem(size_t n, const double * x_bar, const int* ind,
955  double rhs_local_branching_constraint);
956 
958  void switchToOriginalProblem();
959 
961  void round_and_check(double tolerance,
962  OsiObject ** objects = 0, int nObjects = -1){
963  if(!problem_->check_solution(objects, nObjects)){
964  optimizationStatus_ = TNLPSolver::provenInfeasible;
965  }
966  }
968 
973  enum OaMessagesTypes {
974  CUT_NOT_VIOLATED_ENOUGH = 0,
975  VIOLATED_OA_CUT_GENERATED,
976  OA_CUT_GENERATED,
977  OA_MESSAGES_DUMMY_END};
979  class OaMessages :public CoinMessages{
980  public:
982  OaMessages();
983  };
985  class OaMessageHandler : public CoinMessageHandler{
986  public:
988  OaMessageHandler():CoinMessageHandler(){
989  }
991  OaMessageHandler(FILE * fp):CoinMessageHandler(fp){
992  }
994  virtual ~OaMessageHandler(){
995  }
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);
1005  return *this;}
1007  virtual CoinMessageHandler* clone() const{
1008  return new OaMessageHandler(*this);}
1010  void print(OsiRowCut &row);
1011  };
1012  void setOaMessageHandler(const CoinMessageHandler &handler){
1013  delete oaHandler_;
1014  oaHandler_ = new OaMessageHandler(handler);
1015  }
1017 
1018  //-----------------------------------------------------------------------
1021  virtual ApplyCutsReturnCode applyCuts(const OsiCuts & cs,
1022  double effectivenessLb = 0.0){
1023  freeCachedRowRim();
1024  problem_->addCuts(cs);
1025  ApplyCutsReturnCode rc;
1026  return rc;}
1027 
1029  virtual void applyRowCuts(int numberCuts, const OsiRowCut * cuts);
1030 
1031 
1033  virtual void applyRowCuts(int numberCuts, const OsiRowCut ** cuts)
1034  {
1035  if(numberCuts)
1036  freeCachedRowRim();
1037  problem_->addCuts(numberCuts, cuts);
1038  }
1039 
1042  double getConstraintsViolation(const double * x, double & obj);
1043 
1046  double getNonLinearitiesViolation(const double *x, const double obj);
1047 
1048 //---------------------------------------------------------------------------
1049 
1050  void extractInterfaceParams();
1051 
1052 
1054  virtual void setAppDefaultOptions(Ipopt::SmartPtr<Ipopt::OptionsList> Options);
1055 
1057  static void registerOptions (Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
1058 
1059  Ipopt::SmartPtr<Bonmin::RegisteredOptions> regOptions(){
1060  if(IsValid(app_))
1061  return app_->roptions();
1062  else
1063  return NULL;
1064  }
1065 
1068  void SetStrongBrachingSolver(Ipopt::SmartPtr<StrongBranchingSolver> strong_branching_solver);
1072  virtual void markHotStart();
1076  virtual void solveFromHotStart();
1079  virtual void unmarkHotStart();
1081 
1083  void get_tolerances(double &tiny, double&very_tiny, double &rhsRelax, double &infty){
1084  tiny = tiny_;
1085  very_tiny = veryTiny_;
1086  rhsRelax = rhsRelax_;
1087  infty = infty_;
1088  }
1089 
1090  void set_linearizer(Ipopt::SmartPtr<TMINLP2OsiLP> linearizer);
1091 
1092  Ipopt::SmartPtr<TMINLP2OsiLP> linearizer();
1093 protected:
1094 
1096 
1097  enum RandomGenerationType{
1098  uniform =0, perturb=1, perturb_suffix=2};
1100  int initializeJacobianArrays();
1101 
1103 
1104  virtual std::string appName()
1105  {
1106  return "bonmin";
1107  }
1109 
1111 
1113  void solveAndCheckErrors(bool doResolve, bool throwOnFailure,
1114  const char * whereFrom);
1115 
1116 
1119  virtual void applyRowCut( const OsiRowCut & rc )
1120  {
1121  const OsiRowCut * cut = &rc;
1122  problem_->addCuts(1, &cut);
1123  }
1126  virtual void applyColCut( const OsiColCut & cc )
1127  {
1128  throw SimpleError("Ipopt model does not implement this function.",
1129  "applyColCut");
1130  }
1131 
1132 // /** Read the name of the variables in an ampl .col file. */
1133 // void readVarNames() const;
1134 
1136 
1140  Ipopt::SmartPtr<TMINLP> tminlp_;
1142  Ipopt::SmartPtr<TMINLP2TNLP> problem_;
1144  Ipopt::SmartPtr<Ipopt::TNLP> problem_to_optimize_;
1146  bool feasibility_mode_;
1148  Ipopt::SmartPtr<TNLPSolver> app_;
1149 
1151  std::list<Ipopt::SmartPtr<TNLPSolver> > debug_apps_;
1153  bool testOthers_;
1155 
1157  CoinWarmStart* warmstart_;
1158 
1162  void freeCachedColRim();
1164  void freeCachedRowRim();
1166  void freeCachedData();
1169  void extractSenseRhsAndRange() const;
1171  mutable char *rowsense_;
1172 
1174  mutable double *rhs_;
1175 
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_;
1199  double pushValue_;
1201  int numRetryInitial_;
1203  int numRetryResolve_;
1205  int numRetryInfeasibles_;
1207  int numRetryUnsolved_;
1209  double infeasibility_epsilon_;
1210 
1211 
1212  //Added by Claudia
1214  int dynamicCutOff_;
1216  double coeff_var_threshold_;
1218  double first_perc_for_cutoff_decr_;
1220  double second_perc_for_cutoff_decr_;
1221 
1222 
1224  Messages messages_;
1228  int pretendFailIsInfeasible_;
1229 
1230  mutable int pretendSucceededNext_;
1231 
1233  bool hasContinuedAfterNlpFailure_;
1236  int numIterationSuspect_ ;
1240  bool hasBeenOptimized_;
1244  mutable double * obj_;
1246  static bool hasPrintedOptions;
1247 
1249  Ipopt::SmartPtr<TNLP2FPNLP> feasibilityProblem_;
1250 
1252  Ipopt::SmartPtr<TMINLP2OsiLP> linearizer_;
1253 
1257  int * jRow_;
1259  int * jCol_;
1261  double * jValues_;
1263  int nnz_jac;
1265 
1267  Ipopt::TNLP::LinearityType * constTypes_;
1270  int nNonLinear_;
1272  double tiny_;
1274  double veryTiny_;
1276  double rhsRelax_;
1278  double infty_;
1280  TNLPSolver::ReturnStatus optimizationStatus_;
1282  WarmStartModes warmStartMode_;
1284  bool firstSolve_;
1286  Ipopt::SmartPtr<CutStrengthener> cutStrengthener_;
1287 
1292  OaMessages oaMessages_;
1294  OaMessageHandler * oaHandler_;
1296 
1297  double newCutoffDecr;
1298 protected:
1300  void createApplication(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
1301  Ipopt::SmartPtr<Ipopt::OptionsList> options,
1302  Ipopt::SmartPtr<Ipopt::Journalist> journalist,
1303  const std::string & prefix);
1305  OsiTMINLPInterface(Ipopt::SmartPtr<TNLPSolver> app);
1306 
1308  bool internal_setWarmStart(const CoinWarmStart* ws);
1309 
1311  CoinWarmStart* internal_getWarmStart() const;
1312 
1314  CoinWarmStart* build_fake_basis() const;
1315 private:
1316 
1318  Ipopt::SmartPtr<StrongBranchingSolver> strong_branching_solver_;
1320  TNLPSolver::ReturnStatus optimizationStatusBeforeHotStart_;
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;
1327  const char * statusAsString(TNLPSolver::ReturnStatus r){
1329  return OPT_SYMB;}
1330  else if(r == TNLPSolver::provenInfeasible){
1331  return INFEAS_SYMB;}
1332  else if(r == TNLPSolver::unbounded){
1333  return UNBOUND_SYMB;}
1334  else if(r == TNLPSolver::timeLimit){
1335  return TIME_SYMB;}
1336  else return FAILED_SYMB;
1337  }
1338  const char * statusAsString(){
1339  return statusAsString(optimizationStatus_);}
1340 };
1341 }
1342 #endif
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.
bool getIntParam(OsiIntParam key, int &value) const
virtual bool isFreeBinary(int columnNumber) const
Return true if column is binary and not fixed at either bound.
virtual const double * getRightHandSide() const
Get pointer to array[getNumRows()] of rows right-hand sides.
TNLPSolver::UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
Base class for all MINLPs that use a standard triplet matrix form and dense vectors.
Definition: BonTMINLP.hpp:59
virtual void setRowLower(int elementIndex, double elementValue)
Set a single row lower bound.
virtual bool isIntegerNonBinary(int columnNumber) const
Return true if column is general integer.
double getNewCutoffDecr()
Are there a numerical difficulties?
virtual void setRowPrice(const double *rowprice)
Set dual solution variable values.
void getOuterApproximation(OsiCuts &cs, int getObj, const double *x2, bool global)
Get the outer approximation constraints at the current optimal point.
virtual bool isDualObjectiveLimitReached() const
Is the given dual objective limit reached?
virtual const double * getRowRange() const
Get pointer to array[getNumRows()] of row ranges.
virtual bool isInteger(int columnNumber) const
Return true if column is integer.
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.
const double * getDownPsCosts() const
Get number of columns.
WarmStartModes getWarmStartMode()
Get an empty warm start object.
filterSQP Sequential Quadratic Programming algorithm.
virtual void addObjectiveFunction(OsiSolverInterface &si, const double *x)
Add constraint corresponding to objective function.
virtual bool isAbandoned() const
Are there a numerical difficulties?
virtual void extractLinearRelaxation(OsiSolverInterface &si, const double *x, bool getObj=1)
Extract a linear relaxation of the MINLP.
virtual void setRowType(int index, char sense, double rightHandSide, double range)
Set the type of a single row.
virtual bool isContinuous(int colNumber) const
Return true if column is continuous.
virtual CoinWarmStart * getEmptyWarmStart() const
Get an empty warm start object.
Use all solvers.
const TMINLP2TNLP * problem() const
get pointer to the TMINLP2TNLP adapter
const double * getUpPsCosts() const
Get number of columns.
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 void setRowUpper(int elementIndex, double elementValue)
Set a single row upper bound.
virtual bool isProvenOptimal() const
Is optimality proven?
virtual int getNumCols() const
Get number of columns.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
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.
Head of &quot;civilized&quot; log.
virtual void branchAndBound()
Nescessary for compatibility with OsiSolverInterface but does nothing.
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
This is a generic class for calling an NLP solver to solve a TNLP.
double * downPsCosts
User set down pseudo costs.
Definition: BonTMINLP.hpp:122
void use(Ipopt::SmartPtr< TMINLP2TNLP > tminlp2tnlp)
Sets the TMINLP2TNLP to be used by the interface.
virtual bool isPrimalObjectiveLimitReached() const
Is the given primal objective limit reached?
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound.
virtual bool isProvenDualInfeasible() const
Is dual infeasiblity proven?
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
const int * getBranchingDirections() const
get prefered branching directions
Different solver gives different status for problem.
virtual const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warmstarting information.
const int * getPriorities() const
Get priorities on integer variables.
int * branchingDirections
User set preferered branching direction.
Definition: BonTMINLP.hpp:118
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.
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&#39;s.
void ignoreFailures()
tell to ignore the failures (don&#39;t throw, don&#39;t fathom, don&#39;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 void setObjCoeff(int elementIndex, double elementValue)
We have to keep this but it will throw an error.
int * priorities
User set priorities on variables.
Definition: BonTMINLP.hpp:116
Error class to throw exceptions from OsiTMINLPInterface.
virtual void resolveForRobustness(int numretry)
Method to be called when a problem has failed to be solved.
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 getBendersCut(OsiCuts &cs, bool global)
Get a benders cut from solution.
virtual void setColSolution(const double *colsol)
Set the primal solution variable values Set the values for the starting point.
virtual int getIterationCount() const
Get how many iterations it took to solve the problem (whatever &quot;iteration&quot; mean to the solver...
virtual CoinWarmStart * getWarmStart() const
Get warmstarting information.
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.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
bool hasContinuedOnAFailure()
Did we continue on a failure.
virtual void initialSolve()
Solve initial continuous relaxation.
bool setStrParam(OsiStrParam key, const std::string &value)
void forceInfeasible()
Force current solution to be infeasible.
Found a better solution with random values.
virtual bool isProvenPrimalInfeasible() const
Is primal infeasiblity proven?
virtual void deleteCols(const int num, const int *colIndices)
We have to keep this but it will throw an error.
virtual void setObjSense(double s)
Set the objective function sense (disabled).
const OsiSolverInterface::OsiNameVec & getVarNames()
get name of variables
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 const char * getRowSense() const
Get pointer to array[getNumRows()] of row constraint senses.
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
virtual const double * getObjCoefficients() const
This returns the objective function gradient at the current point.
void setWarmStartMode(int mode)
Get an empty warm start object.
virtual void resolveForCost(int numretry, bool keepWs)
Resolve the problem with different random starting points to try to find a better solution (only make...
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual prices.
virtual void resolve()
Resolve the continuous relaxation after problem modification.
virtual void setColLower(int elementIndex, double elementValue)
Set a single column lower bound.
virtual ~OsiTMINLPInterface()
Destructor.
OsiSolverInterface * clone(bool copyData=true) const
Virtual copy constructor.
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.
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.
void setNewCutoffDecr(double d)
Are there a numerical difficulties?
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 bool isBinary(int columnNumber) const
Return true if column is binary.
Warn that there are equality or ranged constraints and OA may works bad.
const Ipopt::SmartPtr< Ipopt::OptionsList > options() const
Retrieve OsiTMINLPApplication option list.
int nCallOptimizeTNLP()
get total number of calls to solve.
OsiTMINLPInterface & operator=(const OsiTMINLPInterface &rhs)
Assignment operator.
MessagesTypes
Type of the messages specifically written by OsiTMINLPInterface.
resolve() has been called but there was no previous call to initialSolve().
We will throw this error when a problem is not solved.
Stores branching priorities information.
Definition: BonTMINLP.hpp:111
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.
bool setIntParam(OsiIntParam key, int value)
void randomStartingPoint()
Get an empty warm start object.
virtual double getInfinity() const
Get solver&#39;s value for infinity.
Trying to access non-existent TNLPSolver.
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.
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.
virtual double getObjValue() const
Get objective function value (can&#39;t use default)
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 const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
virtual int getNumRows() const
Get number of rows.
This is an adapter class that converts a TMINLP to a TNLP to be solved by Ipopt.
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
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.
void continuingOnAFailure()
Warn solver that branch-and-bound is continuing after a failure.
virtual void setContinuous(int index)
Set the index-th variable to be a continuous variable.
OsiTMINLPInterface()
Default Constructor.
virtual bool isIterationLimitReached() const
Iteration limit reached?
Subproblem not solve with warm start but solved with random point.
Output summary statistics on Ipopt solution.
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.
Definition: BonTMINLP.hpp:120
virtual void extractLinearRelaxation(OsiSolverInterface &si, bool getObj=1, bool solveNlp=1)
Extract a linear relaxation of the MINLP.