CbcLinked.hpp
Go to the documentation of this file.
1 /* $Id: CbcLinked.hpp 1200 2009-07-25 08:44:13Z forrest $ */
2 // Copyright (C) 2006, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 #ifndef CglLinked_H
5 #define CglLinked_H
6 /* THIS CONTAINS STUFF THAT SHOULD BE IN
7  OsiSolverLink
8  OsiBranchLink
9  CglTemporary
10 */
11 #include "CoinModel.hpp"
12 #include "OsiClpSolverInterface.hpp"
13 #include "OsiChooseVariable.hpp"
14 #include "CbcFathom.hpp"
15 class CbcModel;
16 class CoinPackedMatrix;
17 class OsiLinkedBound;
18 class OsiObject;
19 class CglStored;
20 class CglTemporary;
27 class OsiSolverLink : public CbcOsiSolver {
28 
29 public:
30  //---------------------------------------------------------------------------
33 
34  virtual void initialSolve();
35 
37  virtual void resolve();
38 
46  virtual int fathom(bool allFixed) ;
53  double * nonlinearSLP(int numberPasses, double deltaTolerance);
57  double linearizedBAB(CglStored * cut) ;
66  double * heuristicSolution(int numberPasses, double deltaTolerance, int mode);
67 
69  int doAOCuts(CglTemporary * cutGen, const double * solution, const double * solution2);
71 
72 
75 
76  OsiSolverLink ();
77 
90  OsiSolverLink( CoinModel & modelObject);
91  // Other way with existing object
92  void load( CoinModel & modelObject, bool tightenBounds = false, int logLevel = 1);
94  virtual OsiSolverInterface * clone(bool copyData = true) const;
95 
97  OsiSolverLink (const OsiSolverLink &);
98 
100  OsiSolverLink & operator=(const OsiSolverLink& rhs);
101 
103  virtual ~OsiSolverLink ();
104 
106 
107 
110 
111  void addBoundModifier(bool upperBoundAffected, bool useUpperBound, int whichVariable, int whichVariableAffected,
112  double multiplier = 1.0);
114  int updateCoefficients(ClpSimplex * solver, CoinPackedMatrix * matrix);
116  void analyzeObjects();
118  void addTighterConstraints();
120  inline double bestObjectiveValue() const {
121  return bestObjectiveValue_;
122  }
124  inline void setBestObjectiveValue(double value) {
125  bestObjectiveValue_ = value;
126  }
128  inline const double * bestSolution() const {
129  return bestSolution_;
130  }
132  void setBestSolution(const double * solution, int numberColumns);
134  inline void setSpecialOptions2(int value) {
135  specialOptions2_ = value;
136  }
138  void sayConvex(bool convex);
140  inline int specialOptions2() const {
141  return specialOptions2_;
142  }
146  CoinPackedMatrix * cleanMatrix() const {
147  return matrix_;
148  }
153  CoinPackedMatrix * originalRowCopy() const {
154  return originalRowCopy_;
155  }
157  ClpSimplex * quadraticModel() const {
158  return quadraticModel_;
159  }
161  CoinPackedMatrix * quadraticRow(int rowNumber, double * linear) const;
163  inline double defaultMeshSize() const {
164  return defaultMeshSize_;
165  }
166  inline void setDefaultMeshSize(double value) {
167  defaultMeshSize_ = value;
168  }
170  inline double defaultBound() const {
171  return defaultBound_;
172  }
173  inline void setDefaultBound(double value) {
174  defaultBound_ = value;
175  }
177  inline void setIntegerPriority(int value) {
178  integerPriority_ = value;
179  }
181  inline int integerPriority() const {
182  return integerPriority_;
183  }
185  inline int objectiveVariable() const {
186  return objectiveVariable_;
187  }
189  inline void setBiLinearPriority(int value) {
190  biLinearPriority_ = value;
191  }
193  inline int biLinearPriority() const {
194  return biLinearPriority_;
195  }
197  inline const CoinModel * coinModel() const {
198  return &coinModel_;
199  }
201  void setBiLinearPriorities(int value, double meshSize = 1.0);
209  void setBranchingStrategyOnVariables(int strategyValue, int priorityValue = -1,
210  int mode = 7);
212  void setMeshSizes(double value);
216  void setFixedPriority(int priorityValue);
218 
219  //---------------------------------------------------------------------------
220 
221 protected:
222 
223 
226 
227  //void initialize(ClpSimplex * & solver, OsiObject ** & object) const;
229  void gutsOfDestructor(bool justNullify = false);
231  void gutsOfCopy(const OsiSolverLink & rhs) ;
233 
239  CoinPackedMatrix * matrix_;
243  CoinPackedMatrix * originalRowCopy_;
245  ClpSimplex * quadraticModel_;
255  int * convex_;
259  CoinModel coinModel_;
283  double * bestSolution_;
293 };
299 
300 public:
301  //---------------------------------------------------------------------------
304 
305  void updateBounds(ClpSimplex * solver);
307 
308 
311 
312  OsiLinkedBound ();
314  OsiLinkedBound(OsiSolverInterface * model, int variable,
315  int numberAffected, const int * positionL,
316  const int * positionU, const double * multiplier);
317 
319  OsiLinkedBound (const OsiLinkedBound &);
320 
323 
325  ~OsiLinkedBound ();
326 
328 
331 
332  inline int variable() const {
333  return variable_;
334  }
336  void addBoundModifier(bool upperBoundAffected, bool useUpperBound, int whichVariable,
337  double multiplier = 1.0);
339 
340 private:
341  typedef struct {
342  double multiplier; // to use in computation
343  int affected; // variable or element affected
344  /*
345  0 - LB of variable affected
346  1 - UB of variable affected
347  2 - element in position (affected) affected
348  */
349  unsigned char affect;
350  unsigned char ubUsed; // nonzero if UB of this variable is used
351  /*
352  0 - use x*multiplier
353  1 - use multiplier/x
354  2 - if UB use min of current upper and x*multiplier, if LB use max of current lower and x*multiplier
355  */
356  unsigned char type; // type of computation
358 
361 
362  OsiSolverInterface * model_;
372 };
373 #include "CbcHeuristic.hpp"
378 public:
379 
380  // Default Constructor
382 
383  /* Constructor with model
384  */
385  CbcHeuristicDynamic3 (CbcModel & model);
386 
387  // Copy constructor
389 
390  // Destructor
392 
394  virtual CbcHeuristic * clone() const;
395 
397  virtual void setModel(CbcModel * model);
398 
399  using CbcHeuristic::solution ;
410  virtual int solution(double & objectiveValue,
411  double * newSolution);
413  virtual void resetModel(CbcModel * model);
415  virtual bool canDealWithOdd() const {
416  return true;
417  }
418 
419 protected:
420 private:
423 };
424 
425 #include "OsiBranchingObject.hpp"
426 
430 class CoinWarmStartBasis;
431 
432 class OsiOldLink : public OsiSOS {
433 
434 public:
435 
436  // Default Constructor
437  OsiOldLink ();
438 
445  OsiOldLink (const OsiSolverInterface * solver, int numberMembers,
446  int numberLinks, int first,
447  const double * weights, int setNumber);
454  OsiOldLink (const OsiSolverInterface * solver, int numberMembers,
455  int numberLinks, int typeSOS, const int * which,
456  const double * weights, int setNumber);
457 
458  // Copy constructor
459  OsiOldLink ( const OsiOldLink &);
460 
462  virtual OsiObject * clone() const;
463 
464  // Assignment operator
465  OsiOldLink & operator=( const OsiOldLink& rhs);
466 
467  // Destructor
468  virtual ~OsiOldLink ();
469 
472  virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
473 
480  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
481 
486  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
487 
489  virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
490 
492  inline int numberLinks() const {
493  return numberLinks_;
494  }
495 
498  virtual bool canDoHeuristics() const {
499  return false;
500  }
503  virtual bool boundBranch() const {
504  return false;
505  }
506 
507 private:
509 
512 };
516 class OsiOldLinkBranchingObject : public OsiSOSBranchingObject {
517 
518 public:
519 
520  // Default Constructor
522 
523  // Useful constructor
524  OsiOldLinkBranchingObject (OsiSolverInterface * solver, const OsiOldLink * originalObject,
525  int way,
526  double separator);
527 
528  // Copy constructor
530 
531  // Assignment operator
533 
535  virtual OsiBranchingObject * clone() const;
536 
537  // Destructor
538  virtual ~OsiOldLinkBranchingObject ();
539 
542  virtual double branch(OsiSolverInterface * solver);
543 
547  virtual void print(const OsiSolverInterface * solver = NULL);
548 private:
550 };
556 class OsiOneLink {
557 
558 public:
559 
560  // Default Constructor
561  OsiOneLink ();
562 
566  OsiOneLink (const OsiSolverInterface * solver, int xRow, int xColumn, int xyRow,
567  const char * functionString);
568 
569  // Copy constructor
570  OsiOneLink ( const OsiOneLink &);
571 
572  // Assignment operator
573  OsiOneLink & operator=( const OsiOneLink& rhs);
574 
575  // Destructor
576  virtual ~OsiOneLink ();
577 
579 
581  int xRow_;
583  int xColumn_;
585  int xyRow;
587  std::string function_;
588 };
598 class OsiLink : public OsiSOS {
599 
600 public:
601 
602  // Default Constructor
603  OsiLink ();
604 
608  OsiLink (const OsiSolverInterface * solver, int yRow,
609  int yColumn, double meshSize);
610 
611  // Copy constructor
612  OsiLink ( const OsiLink &);
613 
615  virtual OsiObject * clone() const;
616 
617  // Assignment operator
618  OsiLink & operator=( const OsiLink& rhs);
619 
620  // Destructor
621  virtual ~OsiLink ();
622 
625  virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
626 
633  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
634 
639  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
640 
642  virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
643 
645  inline int numberLinks() const {
646  return numberLinks_;
647  }
648 
651  virtual bool canDoHeuristics() const {
652  return false;
653  }
656  virtual bool boundBranch() const {
657  return false;
658  }
659 
660 private:
663  double meshSize_;
669  int yRow_;
671  int yColumn_;
672 };
676 class OsiLinkBranchingObject : public OsiTwoWayBranchingObject {
677 
678 public:
679 
680  // Default Constructor
682 
683  // Useful constructor
684  OsiLinkBranchingObject (OsiSolverInterface * solver, const OsiLink * originalObject,
685  int way,
686  double separator);
687 
688  // Copy constructor
690 
691  // Assignment operator
693 
695  virtual OsiBranchingObject * clone() const;
696 
697  // Destructor
698  virtual ~OsiLinkBranchingObject ();
699 
702  virtual double branch(OsiSolverInterface * solver);
703 
707  virtual void print(const OsiSolverInterface * solver = NULL);
708 private:
710 };
718 class OsiBiLinear : public OsiObject2 {
719 
720 public:
721 
722  // Default Constructor
723  OsiBiLinear ();
724 
730  OsiBiLinear (OsiSolverInterface * solver, int xColumn,
731  int yColumn, int xyRow, double coefficient,
732  double xMesh, double yMesh,
733  int numberExistingObjects = 0, const OsiObject ** objects = NULL );
734 
740  OsiBiLinear (CoinModel * coinModel, int xColumn,
741  int yColumn, int xyRow, double coefficient,
742  double xMesh, double yMesh,
743  int numberExistingObjects = 0, const OsiObject ** objects = NULL );
744 
745  // Copy constructor
746  OsiBiLinear ( const OsiBiLinear &);
747 
749  virtual OsiObject * clone() const;
750 
751  // Assignment operator
752  OsiBiLinear & operator=( const OsiBiLinear& rhs);
753 
754  // Destructor
755  virtual ~OsiBiLinear ();
756 
759  virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
760 
767  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
768 
773  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
774 
776  virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
777 
778  // This does NOT set mutable stuff
779  virtual double checkInfeasibility(const OsiBranchingInformation * info) const;
780 
783  virtual bool canDoHeuristics() const {
784  return false;
785  }
788  virtual bool boundBranch() const {
789  return (branchingStrategy_&4) != 0;
790  }
792  inline int xColumn() const {
793  return xColumn_;
794  }
796  inline int yColumn() const {
797  return yColumn_;
798  }
800  inline int xRow() const {
801  return xRow_;
802  }
804  inline int yRow() const {
805  return yRow_;
806  }
808  inline int xyRow() const {
809  return xyRow_;
810  }
812  inline double coefficient() const {
813  return coefficient_;
814  }
816  inline void setCoefficient(double value) {
817  coefficient_ = value;
818  }
820  inline int firstLambda() const {
821  return firstLambda_;
822  }
824  inline double xSatisfied() const {
825  return xSatisfied_;
826  }
827  inline void setXSatisfied(double value) {
828  xSatisfied_ = value;
829  }
831  inline double ySatisfied() const {
832  return ySatisfied_;
833  }
834  inline void setYSatisfied(double value) {
835  ySatisfied_ = value;
836  }
838  inline double xOtherSatisfied() const {
839  return xOtherSatisfied_;
840  }
841  inline void setXOtherSatisfied(double value) {
842  xOtherSatisfied_ = value;
843  }
845  inline double yOtherSatisfied() const {
846  return yOtherSatisfied_;
847  }
848  inline void setYOtherSatisfied(double value) {
849  yOtherSatisfied_ = value;
850  }
852  inline double xMeshSize() const {
853  return xMeshSize_;
854  }
855  inline void setXMeshSize(double value) {
856  xMeshSize_ = value;
857  }
859  inline double yMeshSize() const {
860  return yMeshSize_;
861  }
862  inline void setYMeshSize(double value) {
863  yMeshSize_ = value;
864  }
866  inline double xySatisfied() const {
867  return xySatisfied_;
868  }
869  inline void setXYSatisfied(double value) {
870  xySatisfied_ = value;
871  }
873  void setMeshSizes(const OsiSolverInterface * solver, double x, double y);
884  inline int branchingStrategy() const {
885  return branchingStrategy_;
886  }
887  inline void setBranchingStrategy(int value) {
888  branchingStrategy_ = value;
889  }
897  inline int boundType() const {
898  return boundType_;
899  }
900  inline void setBoundType(int value) {
901  boundType_ = value;
902  }
904  void newBounds(OsiSolverInterface * solver, int way, short xOrY, double separator) const;
906  int updateCoefficients(const double * lower, const double * upper, double * objective,
907  CoinPackedMatrix * matrix, CoinWarmStartBasis * basis) const;
909  double xyCoefficient(const double * solution) const;
911  void getCoefficients(const OsiSolverInterface * solver, double xB[2], double yB[2], double xybar[4]) const;
913  double computeLambdas(const double xB[3], const double yB[3], const double xybar[4], double lambda[4]) const;
915  void addExtraRow(int row, double multiplier);
917  void getPseudoShadow(const OsiBranchingInformation * info);
919  double getMovement(const OsiBranchingInformation * info);
920 
921 protected:
923  void computeLambdas(const OsiSolverInterface * solver, double lambda[4]) const;
925 
927  double coefficient_;
929  double xMeshSize_;
931  double yMeshSize_;
933  double xSatisfied_;
935  double ySatisfied_;
941  double xySatisfied_;
943  mutable double xyBranchValue_;
945  int xColumn_;
947  int yColumn_;
970  int xRow_;
972  int yRow_;
974  int xyRow_;
980  double * multiplier_;
982  int * extraRow_;
984  mutable short chosen_;
985 };
989 class OsiBiLinearBranchingObject : public OsiTwoWayBranchingObject {
990 
991 public:
992 
993  // Default Constructor
995 
996  // Useful constructor
997  OsiBiLinearBranchingObject (OsiSolverInterface * solver, const OsiBiLinear * originalObject,
998  int way,
999  double separator, int chosen);
1000 
1001  // Copy constructor
1003 
1004  // Assignment operator
1006 
1008  virtual OsiBranchingObject * clone() const;
1009 
1010  // Destructor
1011  virtual ~OsiBiLinearBranchingObject ();
1012 
1015  virtual double branch(OsiSolverInterface * solver);
1016 
1020  virtual void print(const OsiSolverInterface * solver = NULL);
1023  virtual bool boundBranch() const;
1024 private:
1027  short chosen_;
1028 };
1037 
1038 public:
1039 
1040  // Default Constructor
1042 
1048  OsiBiLinearEquality (OsiSolverInterface * solver, int xColumn,
1049  int yColumn, int xyRow, double rhs,
1050  double xMesh);
1051 
1052  // Copy constructor
1054 
1056  virtual OsiObject * clone() const;
1057 
1058  // Assignment operator
1060 
1061  // Destructor
1062  virtual ~OsiBiLinearEquality ();
1063 
1065  virtual double improvement(const OsiSolverInterface * solver) const;
1071  double newGrid(OsiSolverInterface * solver, int type) const;
1073  inline int numberPoints() const {
1074  return numberPoints_;
1075  }
1076  inline void setNumberPoints(int value) {
1077  numberPoints_ = value;
1078  }
1079 
1080 private:
1083 };
1085 
1086 
1087 class OsiSimpleFixedInteger : public OsiSimpleInteger {
1088 
1089 public:
1090 
1093 
1095  OsiSimpleFixedInteger (const OsiSolverInterface * solver, int iColumn);
1096 
1098  OsiSimpleFixedInteger (int iColumn, double lower, double upper);
1099 
1101  OsiSimpleFixedInteger (const OsiSimpleInteger &);
1102 
1105 
1107  virtual OsiObject * clone() const;
1108 
1111 
1113  virtual ~OsiSimpleFixedInteger ();
1114 
1115  using OsiObject::infeasibility ;
1117  virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
1118 
1123  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
1124 protected:
1126 
1127 };
1137 class OsiUsesBiLinear : public OsiSimpleInteger {
1138 
1139 public:
1140 
1142  OsiUsesBiLinear ();
1143 
1145  OsiUsesBiLinear (const OsiSolverInterface * solver, int iColumn, int type);
1146 
1148  OsiUsesBiLinear (int iColumn, double lower, double upper, int type);
1149 
1151  OsiUsesBiLinear (const OsiSimpleInteger & rhs, int type);
1152 
1154  OsiUsesBiLinear ( const OsiUsesBiLinear & rhs);
1155 
1157  virtual OsiObject * clone() const;
1158 
1160  OsiUsesBiLinear & operator=( const OsiUsesBiLinear& rhs);
1161 
1163  virtual ~OsiUsesBiLinear ();
1164 
1165  using OsiObject::infeasibility ;
1167  virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
1168 
1173  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
1174 
1181  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
1182 
1184  void addBiLinearObjects(OsiSolverLink * solver);
1185 protected:
1190  int type_;
1192  OsiObject ** objects_;
1193 };
1201 class OsiChooseStrongSubset : public OsiChooseStrong {
1202 
1203 public:
1204 
1207 
1209  OsiChooseStrongSubset (const OsiSolverInterface * solver);
1210 
1213 
1216 
1218  virtual OsiChooseVariable * clone() const;
1219 
1221  virtual ~OsiChooseStrongSubset ();
1222 
1227  virtual int setupList ( OsiBranchingInformation *info, bool initialize);
1241  virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
1242 
1244  inline int numberObjectsToUse() const {
1245  return numberObjectsToUse_;
1246  }
1248  inline void setNumberObjectsToUse(int value) {
1249  numberObjectsToUse_ = value;
1250  }
1251 
1252 protected:
1253  // Data
1256 };
1257 
1258 #include <string>
1259 
1260 #include "CglStored.hpp"
1261 
1262 class CoinWarmStartBasis;
1264 class CglTemporary : public CglStored {
1265 
1266 public:
1267 
1268 
1279  virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
1280  const CglTreeInfo info = CglTreeInfo()) const;
1282 
1285 
1286  CglTemporary ();
1287 
1289  CglTemporary (const CglTemporary & rhs);
1290 
1292  virtual CglCutGenerator * clone() const;
1293 
1295  CglTemporary &
1296  operator=(const CglTemporary& rhs);
1297 
1299  virtual
1300  ~CglTemporary ();
1302 
1303 private:
1304 
1305 // Private member methods
1306 
1307  // Private member data
1308 };
1309 //#############################################################################
1310 
1316 class OsiSolverLinearizedQuadratic : public OsiClpSolverInterface {
1317 
1318 public:
1319  //---------------------------------------------------------------------------
1322 
1323  virtual void initialSolve();
1325 
1326 
1329 
1334  virtual OsiSolverInterface * clone(bool copyData = true) const;
1335 
1338 
1341 
1343  virtual ~OsiSolverLinearizedQuadratic ();
1344 
1346 
1347 
1350 
1351  inline double bestObjectiveValue() const {
1352  return bestObjectiveValue_;
1353  }
1355  const double * bestSolution() const {
1356  return bestSolution_;
1357  }
1359  inline void setSpecialOptions3(int value) {
1360  specialOptions3_ = value;
1361  }
1363  inline int specialOptions3() const {
1364  return specialOptions3_;
1365  }
1367  ClpSimplex * quadraticModel() const {
1368  return quadraticModel_;
1369  }
1371 
1372  //---------------------------------------------------------------------------
1373 
1374 protected:
1375 
1376 
1379 
1382 
1385  ClpSimplex * quadraticModel_;
1387  double * bestSolution_;
1394 };
1395 class ClpSimplex;
1400 ClpSimplex * approximateSolution(CoinModel & coinModel,
1401  int numberPasses, double deltaTolerance,
1402  int mode = 0);
1403 #endif
1404