source: branches/devel/Cbc/src/CbcLinked.hpp @ 588

Last change on this file since 588 was 588, checked in by forrest, 12 years ago

for dubiois optionas

File size: 31.6 KB
Line 
1// Copyright (C) 2006, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef CglLinked_H
4#define CglLinked_H
5/* THIS CONTAINS STUFF THAT SHOULD BE IN
6   OsiSolverLink
7   OsiBranchLink
8   CglTemporary
9*/
10#ifndef COIN_HAS_LINK
11#ifdef COIN_HAS_ASL
12#define COIN_HAS_LINK
13#endif
14#endif
15#ifdef COIN_HAS_LINK
16#include "OsiClpSolverInterface.hpp"
17#include "CoinModel.hpp"
18class CbcModel;
19class CoinPackedMatrix;
20class OsiLinkedBound;
21class OsiObject;
22class CglStored;
23//#############################################################################
24
25/**
26   
27This is to allow the user to replace initialSolve and resolve
28This version changes coefficients
29*/
30
31class OsiSolverLink : public OsiClpSolverInterface {
32 
33public:
34  //---------------------------------------------------------------------------
35  /**@name Solve methods */
36  //@{
37  /// Solve initial LP relaxation
38  virtual void initialSolve();
39 
40  /// Resolve an LP relaxation after problem modification
41  virtual void resolve();
42
43  /**
44     Problem specific
45     Returns -1 if node fathomed and no solution
46              0 if did nothing
47              1 if node fathomed and solution
48     allFixed is true if all LinkedBound variables are fixed
49  */
50  virtual int fathom(bool allFixed) ;
51  /** Solves nonlinear problem from CoinModel using SLP - may be used as crash
52      for other algorithms when number of iterations small.
53      Also exits if all problematical variables are changing
54      less than deltaTolerance
55      Returns solution array
56  */
57  double * nonlinearSLP(int numberPasses,double deltaTolerance);
58  /** Solve linearized quadratic objective branch and bound.
59      Return cutoff and OA cut
60  */
61  double linearizedBAB(CglStored * cut) ;
62  //@}
63 
64 
65  /**@name Constructors and destructors */
66  //@{
67  /// Default Constructor
68  OsiSolverLink ();
69 
70  /** This creates from a coinModel object
71
72      if errors.then number of sets is -1
73     
74      This creates linked ordered sets information.  It assumes -
75
76      for product terms syntax is yy*f(zz)
77      also just f(zz) is allowed
78      and even a constant
79
80      modelObject not const as may be changed as part of process.
81  */
82  OsiSolverLink(  CoinModel & modelObject);
83  // Other way with existing object
84  void load(  CoinModel & modelObject,bool tightenBounds=false,int logLevel=1);
85  /// Clone
86  virtual OsiSolverInterface * clone(bool copyData=true) const;
87 
88  /// Copy constructor
89  OsiSolverLink (const OsiSolverLink &);
90 
91  /// Assignment operator
92  OsiSolverLink & operator=(const OsiSolverLink& rhs);
93 
94  /// Destructor
95  virtual ~OsiSolverLink ();
96 
97  //@}
98 
99 
100  /**@name Sets and Gets */
101  //@{
102  /// Add a bound modifier
103  void addBoundModifier(bool upperBoundAffected, bool useUpperBound, int whichVariable, int whichVariableAffected, 
104                        double multiplier=1.0);
105  /// Update coefficients - returns number updated if in updating mode
106  int updateCoefficients(ClpSimplex * solver, CoinPackedMatrix * matrix);
107  /// Analyze constraints to see which are convex (quadratic)
108  void analyzeObjects();
109  /// Objective value of best solution found internally
110  inline double bestObjectiveValue() const
111  { return bestObjectiveValue_;};
112  /// Set objective value of best solution found internally
113  inline void setBestObjectiveValue(double value)
114  { bestObjectiveValue_ = value;};
115  /// Best solution found internally
116  inline const double * bestSolution() const
117  { return bestSolution_;};
118  /// Set best solution found internally
119  void setBestSolution(const double * solution, int numberColumns);
120  /// Set special options
121  inline void setSpecialOptions2(int value)
122  { specialOptions2_=value;};
123  /// Say convex (should work it out) - if convex false then strictly concave
124  void sayConvex(bool convex);
125  /// Get special options
126  inline int specialOptions2() const
127  { return specialOptions2_;};
128  /** Clean copy of matrix
129      So we can add rows
130  */
131  CoinPackedMatrix * cleanMatrix() const
132  { return matrix_;};
133  /** Row copy of matrix
134      Just genuine columns and rows
135      Linear part
136  */
137  CoinPackedMatrix * originalRowCopy() const
138  { return originalRowCopy_;};
139  /// Copy of quadratic model if one
140  ClpSimplex * quadraticModel() const
141  { return quadraticModel_;};
142  /// Gets correct form for a quadratic row - user to delete
143  CoinPackedMatrix * quadraticRow(int rowNumber,double * linear) const;
144  /// Default meshSize
145  inline double defaultMeshSize() const
146  { return defaultMeshSize_;};
147  inline void setDefaultMeshSize(double value)
148  { defaultMeshSize_=value;};
149  /// Default maximumbound
150  inline double defaultBound() const
151  { return defaultBound_;};
152  inline void setDefaultBound(double value)
153  { defaultBound_=value;};
154  /// Set integer priority
155  inline void setIntegerPriority(int value)
156  { integerPriority_=value;};
157  /// Get integer priority
158  inline int integerPriority() const
159  { return integerPriority_;};
160  /// Set biLinear priority
161  inline void setBiLinearPriority(int value)
162  { biLinearPriority_=value;};
163  /// Get biLinear priority
164  inline int biLinearPriority() const
165  { return biLinearPriority_;};
166  /// Set Cbc Model
167  inline void setCbcModel(CbcModel * model)
168  { cbcModel_=model;};
169  /// Return CoinModel
170  inline const CoinModel * coinModel() const
171  { return &coinModel_;};
172  /// Set all biLinear priorities on x-x variables
173  void setBiLinearPriorities(int value, double meshSize=1.0);
174  /// Set all mesh sizes on x-x variables
175  void setMeshSizes(double value);
176  /** Two tier integer problem where when set of variables with priority
177      less than this are fixed the problem becomes an easier integer problem
178  */
179  void setFixedPriority(int priorityValue);
180  //@}
181 
182  //---------------------------------------------------------------------------
183 
184protected:
185 
186 
187  /**@name functions */
188  //@{
189  /// Do real work of initialize
190  //void initialize(ClpSimplex * & solver, OsiObject ** & object) const;
191  /// Do real work of delete
192  void gutsOfDestructor(bool justNullify=false);
193  /// Do real work of copy
194  void gutsOfCopy(const OsiSolverLink & rhs) ;
195  //@}
196 
197  /**@name Private member data */
198  //@{
199  /** Clean copy of matrix
200      Marked coefficients will be multiplied by L or U
201  */
202  CoinPackedMatrix * matrix_;
203  /** Row copy of matrix
204      Just genuine columns and rows
205  */
206  CoinPackedMatrix * originalRowCopy_;
207  /// Copy of quadratic model if one
208  ClpSimplex * quadraticModel_;
209  /// Pointer back to CbcModel
210  CbcModel * cbcModel_;
211  /// Number of rows with nonLinearities
212  int numberNonLinearRows_;
213  /// Starts of lists
214  int * startNonLinear_;
215  /// Row number for a list
216  int * rowNonLinear_;
217  /** Indicator whether is convex, concave or neither
218      -1 concave, 0 neither, +1 convex
219  */
220  int * convex_;
221  /// Indices in a list/row
222  int * whichNonLinear_;
223  /// Model in CoinModel format
224  CoinModel coinModel_;
225  /// Number of variables in tightening phase
226  int numberVariables_;
227  /// Information
228  OsiLinkedBound * info_;
229  /**
230     0 bit (1) - call fathom (may do mini B&B)
231     1 bit (2) - quadratic only in objective (add OA cuts)
232     2 bit (4) - convex
233     4 bit (8) - try adding OA cuts
234  */
235  int specialOptions2_;
236  /// Objective transfer row if one
237  int objectiveRow_;
238  /// Objective transfer variable if one
239  int objectiveVariable_;
240  /// Objective value of best solution found internally
241  double bestObjectiveValue_;
242  /// Default mesh
243  double defaultMeshSize_;
244  /// Default maximum bound
245  double defaultBound_;
246  /// Best solution found internally
247  double * bestSolution_;
248  /// Priority for integers
249  int integerPriority_;
250  /// Priority for bilinear
251  int biLinearPriority_;
252  /// Number of variables which when fixed help
253  int numberFix_;
254  /// list of fixed variables
255  int * fixVariables_;
256  //@}
257};
258/**
259   List of bounds which depend on other bounds
260*/
261
262class OsiLinkedBound {
263 
264public:
265  //---------------------------------------------------------------------------
266  /**@name Action methods */
267  //@{
268  /// Update other bounds
269  void updateBounds(ClpSimplex * solver);
270  //@}
271 
272 
273  /**@name Constructors and destructors */
274  //@{
275  /// Default Constructor
276  OsiLinkedBound ();
277  /// Useful Constructor
278  OsiLinkedBound(OsiSolverInterface * model, int variable,
279                 int numberAffected, const int * positionL, 
280                 const int * positionU, const double * multiplier);
281 
282  /// Copy constructor
283  OsiLinkedBound (const OsiLinkedBound &);
284 
285  /// Assignment operator
286  OsiLinkedBound & operator=(const OsiLinkedBound& rhs);
287 
288  /// Destructor
289  ~OsiLinkedBound ();
290 
291  //@}
292 
293  /**@name Sets and Gets */
294  //@{
295  /// Get variable
296  inline int variable() const
297  { return variable_;};
298  /// Add a bound modifier
299  void addBoundModifier(bool upperBoundAffected, bool useUpperBound, int whichVariable, 
300                        double multiplier=1.0);
301  //@}
302 
303private:
304  typedef struct {
305    /*
306      0 - LB of variable affected
307      1 - UB of variable affected
308      2 - element in position (affected) affected
309    */
310    unsigned int affect:2;
311    unsigned int ubUsed:1; // nonzero if UB of this variable is used
312    /*
313       0 - use x*multiplier
314       1 - use multiplier/x
315       2 - if UB use min of current upper and x*multiplier, if LB use max of current lower and x*multiplier
316    */
317    unsigned int type:4; // type of computation
318    unsigned int affected:25; // variable or element affected
319    float multiplier; // to use in computation
320  } boundElementAction;
321 
322  /**@name Private member data */
323  //@{
324  /// Pointer back to model
325  OsiSolverInterface * model_;
326  /// Variable
327  int variable_;
328  /// Number of variables/elements affected
329  int numberAffected_;
330  /// Maximum number of variables/elements affected
331  int maximumAffected_;
332  /// Actions
333  boundElementAction * affected_;
334  //@}
335};
336#include "CbcHeuristic.hpp"
337/** heuristic - just picks up any good solution
338 */
339
340class CbcHeuristicDynamic3 : public CbcHeuristic {
341public:
342 
343  // Default Constructor
344  CbcHeuristicDynamic3 ();
345 
346  /* Constructor with model
347   */
348  CbcHeuristicDynamic3 (CbcModel & model);
349 
350  // Copy constructor
351  CbcHeuristicDynamic3 ( const CbcHeuristicDynamic3 &);
352 
353  // Destructor
354  ~CbcHeuristicDynamic3 ();
355 
356  /// Clone
357  virtual CbcHeuristic * clone() const;
358 
359  /// update model
360  virtual void setModel(CbcModel * model);
361 
362  /** returns 0 if no solution, 1 if valid solution.
363      Sets solution values if good, sets objective value (only if good)
364      We leave all variables which are at one at this node of the
365      tree to that value and will
366      initially set all others to zero.  We then sort all variables in order of their cost
367      divided by the number of entries in rows which are not yet covered.  We randomize that
368      value a bit so that ties will be broken in different ways on different runs of the heuristic.
369      We then choose the best one and set it to one and repeat the exercise. 
370     
371  */
372  virtual int solution(double & objectiveValue,
373                       double * newSolution);
374  /// Resets stuff if model changes
375  virtual void resetModel(CbcModel * model);
376  /// Returns true if can deal with "odd" problems e.g. sos type 2
377  virtual bool canDealWithOdd() const
378  { return true;};
379 
380protected:
381private:
382  /// Illegal Assignment operator
383  CbcHeuristicDynamic3 & operator=(const CbcHeuristicDynamic3& rhs);
384};
385
386#include "OsiBranchingObject.hpp"
387
388/** Define Special Linked Ordered Sets.
389
390*/
391class CoinWarmStartBasis;
392
393class OsiOldLink : public OsiSOS {
394
395public:
396
397  // Default Constructor
398  OsiOldLink ();
399
400  /** Useful constructor - A valid solution is if all variables are zero
401      apart from k*numberLink to (k+1)*numberLink-1 where k is 0 through
402      numberInSet-1.  The length of weights array is numberInSet.
403      For this constructor the variables in matrix are the numberInSet*numberLink
404      starting at first. If weights null then 0,1,2..
405  */
406  OsiOldLink (const OsiSolverInterface * solver, int numberMembers,
407           int numberLinks, int first,
408           const double * weights, int setNumber);
409  /** Useful constructor - A valid solution is if all variables are zero
410      apart from k*numberLink to (k+1)*numberLink-1 where k is 0 through
411      numberInSet-1.  The length of weights array is numberInSet.
412      For this constructor the variables are given by list - grouped.
413      If weights null then 0,1,2..
414  */
415  OsiOldLink (const OsiSolverInterface * solver, int numberMembers,
416           int numberLinks, int typeSOS, const int * which,
417           const double * weights, int setNumber);
418 
419  // Copy constructor
420  OsiOldLink ( const OsiOldLink &);
421   
422  /// Clone
423  virtual OsiObject * clone() const;
424
425  // Assignment operator
426  OsiOldLink & operator=( const OsiOldLink& rhs);
427
428  // Destructor
429  virtual ~OsiOldLink ();
430 
431  /// Infeasibility - large is 0.5
432  virtual double infeasibility(const OsiBranchingInformation * info,int & whichWay) const;
433
434  /** Set bounds to fix the variable at the current (integer) value.
435
436    Given an integer value, set the lower and upper bounds to fix the
437    variable. Returns amount it had to move variable.
438  */
439  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
440
441  /** Creates a branching object
442
443    The preferred direction is set by \p way, 0 for down, 1 for up.
444  */
445  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
446
447  /// Redoes data when sequence numbers change
448  virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
449
450  /// Number of links for each member
451  inline int numberLinks() const
452  {return numberLinks_;};
453
454  /** \brief Return true if object can take part in normal heuristics
455  */
456  virtual bool canDoHeuristics() const 
457  {return false;};
458  /** \brief Return true if branch should only bound variables
459  */
460  virtual bool boundBranch() const 
461  {return false;};
462
463private:
464  /// data
465
466  /// Number of links
467  int numberLinks_;
468};
469/** Branching object for Linked ordered sets
470
471 */
472class OsiOldLinkBranchingObject : public OsiSOSBranchingObject {
473
474public:
475
476  // Default Constructor
477  OsiOldLinkBranchingObject ();
478
479  // Useful constructor
480  OsiOldLinkBranchingObject (OsiSolverInterface * solver,  const OsiOldLink * originalObject,
481                          int way,
482                          double separator);
483 
484  // Copy constructor
485  OsiOldLinkBranchingObject ( const OsiOldLinkBranchingObject &);
486   
487  // Assignment operator
488  OsiOldLinkBranchingObject & operator=( const OsiOldLinkBranchingObject& rhs);
489
490  /// Clone
491  virtual OsiBranchingObject * clone() const;
492
493  // Destructor
494  virtual ~OsiOldLinkBranchingObject ();
495 
496  /// Does next branch and updates state
497  virtual double branch(OsiSolverInterface * solver);
498
499  /** \brief Print something about branch - only if log level high
500  */
501  virtual void print(const OsiSolverInterface * solver=NULL);
502private:
503  /// data
504};
505/** Define data for one link
506   
507*/
508
509
510class OsiOneLink {
511
512public:
513
514  // Default Constructor
515  OsiOneLink ();
516
517  /** Useful constructor -
518     
519  */
520  OsiOneLink (const OsiSolverInterface * solver, int xRow, int xColumn, int xyRow,
521              const char * functionString);
522 
523  // Copy constructor
524  OsiOneLink ( const OsiOneLink &);
525   
526  // Assignment operator
527  OsiOneLink & operator=( const OsiOneLink& rhs);
528
529  // Destructor
530  virtual ~OsiOneLink ();
531 
532  /// data
533
534  /// Row which defines x (if -1 then no x)
535  int xRow_;
536  /// Column which defines x
537  int xColumn_;
538  /// Output row
539  int xyRow;
540  /// Function
541  std::string function_;
542};
543/** Define Special Linked Ordered Sets. New style
544
545    members and weights may be stored in SOS object
546
547    This is for y and x*f(y) and z*g(y) etc
548
549*/
550
551
552class OsiLink : public OsiSOS {
553
554public:
555
556  // Default Constructor
557  OsiLink ();
558
559  /** Useful constructor -
560     
561  */
562  OsiLink (const OsiSolverInterface * solver, int yRow,
563           int yColumn, double meshSize);
564 
565  // Copy constructor
566  OsiLink ( const OsiLink &);
567   
568  /// Clone
569  virtual OsiObject * clone() const;
570
571  // Assignment operator
572  OsiLink & operator=( const OsiLink& rhs);
573
574  // Destructor
575  virtual ~OsiLink ();
576 
577  /// Infeasibility - large is 0.5
578  virtual double infeasibility(const OsiBranchingInformation * info,int & whichWay) const;
579
580  /** Set bounds to fix the variable at the current (integer) value.
581
582    Given an integer value, set the lower and upper bounds to fix the
583    variable. Returns amount it had to move variable.
584  */
585  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
586
587  /** Creates a branching object
588
589    The preferred direction is set by \p way, 0 for down, 1 for up.
590  */
591  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
592
593  /// Redoes data when sequence numbers change
594  virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
595
596  /// Number of links for each member
597  inline int numberLinks() const
598  {return numberLinks_;};
599
600  /** \brief Return true if object can take part in normal heuristics
601  */
602  virtual bool canDoHeuristics() const 
603  {return false;};
604  /** \brief Return true if branch should only bound variables
605  */
606  virtual bool boundBranch() const 
607  {return false;};
608
609private:
610  /// data
611  /// Current increment for y points
612  double meshSize_;
613  /// Links
614  OsiOneLink * data_;
615  /// Number of links
616  int numberLinks_;
617  /// Row which defines y
618  int yRow_;
619  /// Column which defines y
620  int yColumn_;
621};
622/** Branching object for Linked ordered sets
623
624 */
625class OsiLinkBranchingObject : public OsiTwoWayBranchingObject {
626
627public:
628
629  // Default Constructor
630  OsiLinkBranchingObject ();
631
632  // Useful constructor
633  OsiLinkBranchingObject (OsiSolverInterface * solver,  const OsiLink * originalObject,
634                          int way,
635                          double separator);
636 
637  // Copy constructor
638  OsiLinkBranchingObject ( const OsiLinkBranchingObject &);
639   
640  // Assignment operator
641  OsiLinkBranchingObject & operator=( const OsiLinkBranchingObject& rhs);
642
643  /// Clone
644  virtual OsiBranchingObject * clone() const;
645
646  // Destructor
647  virtual ~OsiLinkBranchingObject ();
648 
649  /// Does next branch and updates state
650  virtual double branch(OsiSolverInterface * solver);
651
652  /** \brief Print something about branch - only if log level high
653  */
654  virtual void print(const OsiSolverInterface * solver=NULL);
655private:
656  /// data
657};
658/** Define BiLinear objects
659
660    This models x*y where one or both are integer
661
662*/
663
664
665class OsiBiLinear : public OsiObject2 {
666
667public:
668
669  // Default Constructor
670  OsiBiLinear ();
671
672  /** Useful constructor -
673      This Adds in rows and variables to construct valid Linked Ordered Set
674      Adds extra constraints to match other x/y
675      So note not const solver
676  */
677  OsiBiLinear (OsiSolverInterface * solver, int xColumn,
678               int yColumn, int xyRow, double coefficient,
679               double xMesh, double yMesh,
680               int numberExistingObjects=0,const OsiObject ** objects=NULL );
681 
682  // Copy constructor
683  OsiBiLinear ( const OsiBiLinear &);
684   
685  /// Clone
686  virtual OsiObject * clone() const;
687
688  // Assignment operator
689  OsiBiLinear & operator=( const OsiBiLinear& rhs);
690
691  // Destructor
692  virtual ~OsiBiLinear ();
693 
694  /// Infeasibility - large is 0.5
695  virtual double infeasibility(const OsiBranchingInformation * info,int & whichWay) const;
696
697  /** Set bounds to fix the variable at the current (integer) value.
698
699    Given an integer value, set the lower and upper bounds to fix the
700    variable. Returns amount it had to move variable.
701  */
702  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
703
704  /** Creates a branching object
705
706    The preferred direction is set by \p way, 0 for down, 1 for up.
707  */
708  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
709
710  /// Redoes data when sequence numbers change
711  virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
712
713  // This does NOT set mutable stuff
714  virtual double checkInfeasibility(const OsiBranchingInformation * info) const;
715 
716  /** \brief Return true if object can take part in normal heuristics
717  */
718  virtual bool canDoHeuristics() const 
719  {return false;};
720  /** \brief Return true if branch should only bound variables
721  */
722  virtual bool boundBranch() const 
723  { return (branchingStrategy_&4)!=0;};
724  /// X column
725  inline int xColumn() const
726  { return xColumn_;};
727  /// Y column
728  inline int yColumn() const
729  { return yColumn_;};
730  /// X row
731  inline int xRow() const
732  { return xRow_;};
733  /// Y row
734  inline int yRow() const
735  { return yRow_;};
736  /// XY row
737  inline int xyRow() const
738  { return xyRow_;};
739  /// Coefficient
740  inline double coefficient() const
741  { return coefficient_;};
742  /// Set coefficient
743  inline void setCoefficient(double value)
744  { coefficient_ = value;};
745  /// First lambda (of 4)
746  inline int firstLambda() const
747  { return firstLambda_;};
748  /// X satisfied if less than this away from mesh
749  inline double xSatisfied() const
750  { return xSatisfied_;};
751  inline void setXSatisfied(double value)
752  { xSatisfied_=value;};
753  /// Y satisfied if less than this away from mesh
754  inline double ySatisfied() const
755  { return ySatisfied_;};
756  inline void setYSatisfied(double value)
757  { ySatisfied_=value;};
758  /// X other satisfied if less than this away from mesh
759  inline double xOtherSatisfied() const
760  { return xOtherSatisfied_;};
761  inline void setXOtherSatisfied(double value)
762  { xOtherSatisfied_=value;};
763  /// Y other satisfied if less than this away from mesh
764  inline double yOtherSatisfied() const
765  { return yOtherSatisfied_;};
766  inline void setYOtherSatisfied(double value)
767  { yOtherSatisfied_=value;};
768  /// X meshSize
769  inline double xMeshSize() const
770  { return xMeshSize_;};
771  inline void setXMeshSize(double value)
772  { xMeshSize_=value;};
773  /// Y meshSize
774  inline double yMeshSize() const
775  { return yMeshSize_;};
776  inline void setYMeshSize(double value)
777  { yMeshSize_=value;};
778  /// XY satisfied if two version differ by less than this
779  inline double xySatisfied() const
780  { return xySatisfied_;};
781  inline void setXYSatisfied(double value)
782  { xySatisfied_=value;};
783  /** branching strategy etc
784      bottom 2 bits
785      0 branch on either, 1 branch on x, 2 branch on y
786      next bit
787      4 set to say don't update coefficients
788      next bit
789      8 set to say don't use in feasible region
790  */
791  inline int branchingStrategy() const
792  { return branchingStrategy_;};
793  inline void setBranchingStrategy(int value)
794  { branchingStrategy_=value;};
795  /** Simple quadratic bound marker.
796      0 no
797      1 L if coefficient pos, G if negative i.e. value is ub on xy
798      2 G if coefficient pos, L if negative i.e. value is lb on xy
799      3 E
800      If bound then real coefficient is 1.0 and coefficient_ is bound
801  */
802  inline int boundType() const
803  { return boundType_;};
804  inline void setBoundType(int value)
805  { boundType_ = value;};
806  /// Does work of branching
807  void newBounds(OsiSolverInterface * solver, int way, short xOrY, double separator) const;
808  /// Updates coefficients - returns number updated
809  int updateCoefficients(const double * lower, const double * upper, double * objective,
810                          CoinPackedMatrix * matrix, CoinWarmStartBasis * basis) const;
811  /// Returns true value of single xyRow coefficient
812  double xyCoefficient(const double * solution) const;
813  /// Get LU coefficients from matrix
814  void getCoefficients(const OsiSolverInterface * solver,double xB[2], double yB[2], double xybar[4]) const;
815  /// Compute lambdas (third entry in each .B is current value) (nonzero if bad)
816  double computeLambdas(const double xB[3], const double yB[3],const double xybar[4],double lambda[4]) const;
817
818protected:
819  /// Compute lambdas if coefficients not changing
820  void computeLambdas(const OsiSolverInterface * solver,double lambda[4]) const;
821  /// data
822 
823  /// Coefficient
824  double coefficient_;
825  /// x mesh
826  double xMeshSize_;
827  /// y mesh
828  double yMeshSize_;
829  /// x satisfied if less than this away from mesh
830  double xSatisfied_;
831  /// y satisfied if less than this away from mesh
832  double ySatisfied_;
833  /// X other satisfied if less than this away from mesh
834  double xOtherSatisfied_;
835  /// Y other satisfied if less than this away from mesh
836  double yOtherSatisfied_;
837  /// xy satisfied if less than this away from true
838  double xySatisfied_;
839  /// value of x or y to branch about
840  mutable double xyBranchValue_;
841  /// x column
842  int xColumn_;
843  /// y column
844  int yColumn_;
845  /// First lambda (of 4)
846  int firstLambda_;
847  /** branching strategy etc
848      bottom 2 bits
849      0 branch on either, 1 branch on x, 2 branch on y
850      next bit
851      4 set to say don't update coefficients
852      next bit
853      8 set to say don't use in feasible region
854  */
855  int branchingStrategy_;
856  /** Simple quadratic bound marker.
857      0 no
858      1 L if coefficient pos, G if negative i.e. value is ub on xy
859      2 G if coefficient pos, L if negative i.e. value is lb on xy
860      3 E
861      If bound then real coefficient is 1.0 and coefficient_ is bound
862  */
863  int boundType_;
864  /// x row
865  int xRow_;
866  /// y row (-1 if x*x)
867  int yRow_;
868  /// Output row
869  int xyRow_;
870  /// Convexity row
871  int convexity_;
872  /// Which chosen -1 none, 0 x, 1 y
873  mutable short chosen_;
874};
875/** Branching object for BiLinear objects
876
877 */
878class OsiBiLinearBranchingObject : public OsiTwoWayBranchingObject {
879
880public:
881
882  // Default Constructor
883  OsiBiLinearBranchingObject ();
884
885  // Useful constructor
886  OsiBiLinearBranchingObject (OsiSolverInterface * solver,  const OsiBiLinear * originalObject,
887                          int way,
888                          double separator, int chosen);
889 
890  // Copy constructor
891  OsiBiLinearBranchingObject ( const OsiBiLinearBranchingObject &);
892   
893  // Assignment operator
894  OsiBiLinearBranchingObject & operator=( const OsiBiLinearBranchingObject& rhs);
895
896  /// Clone
897  virtual OsiBranchingObject * clone() const;
898
899  // Destructor
900  virtual ~OsiBiLinearBranchingObject ();
901 
902  /// Does next branch and updates state
903  virtual double branch(OsiSolverInterface * solver);
904
905  /** \brief Print something about branch - only if log level high
906  */
907  virtual void print(const OsiSolverInterface * solver=NULL);
908  /** \brief Return true if branch should only bound variables
909  */
910  virtual bool boundBranch() const; 
911private:
912  /// data
913  /// 1 means branch on x, 2 branch on y
914  short chosen_;
915};
916/** Define Continuous BiLinear objects for an == bound
917
918    This models x*y = b where both are continuous
919
920*/
921
922
923class OsiBiLinearEquality : public OsiBiLinear {
924
925public:
926
927  // Default Constructor
928  OsiBiLinearEquality ();
929
930  /** Useful constructor -
931      This Adds in rows and variables to construct Ordered Set
932      for x*y = b
933      So note not const solver
934  */
935  OsiBiLinearEquality (OsiSolverInterface * solver, int xColumn,
936               int yColumn, int xyRow, double rhs,
937                       double xMesh);
938 
939  // Copy constructor
940  OsiBiLinearEquality ( const OsiBiLinearEquality &);
941   
942  /// Clone
943  virtual OsiObject * clone() const;
944
945  // Assignment operator
946  OsiBiLinearEquality & operator=( const OsiBiLinearEquality& rhs);
947
948  // Destructor
949  virtual ~OsiBiLinearEquality ();
950 
951  /// Possible improvement
952  virtual double improvement(const OsiSolverInterface * solver) const;
953  /** change grid
954      if type 0 then use solution and make finer
955      if 1 then back to original
956      returns mesh size
957  */
958  double newGrid(OsiSolverInterface * solver, int type) const;
959  /// Number of points
960  inline int numberPoints() const
961  { return numberPoints_;};
962  inline void setNumberPoints(int value)
963  { numberPoints_ = value;};
964
965private:
966  /// Number of points
967  int numberPoints_;
968};
969/// Define a single integer class - but one where you kep branching until fixed even if satsified
970
971
972class OsiSimpleFixedInteger : public OsiSimpleInteger {
973
974public:
975
976  /// Default Constructor
977  OsiSimpleFixedInteger ();
978
979  /// Useful constructor - passed solver index
980  OsiSimpleFixedInteger (const OsiSolverInterface * solver, int iColumn);
981 
982  /// Useful constructor - passed solver index and original bounds
983  OsiSimpleFixedInteger (int iColumn, double lower, double upper);
984 
985  /// Useful constructor - passed simple integer
986  OsiSimpleFixedInteger (const OsiSimpleInteger &);
987 
988  /// Copy constructor
989  OsiSimpleFixedInteger ( const OsiSimpleFixedInteger &);
990   
991  /// Clone
992  virtual OsiObject * clone() const;
993
994  /// Assignment operator
995  OsiSimpleFixedInteger & operator=( const OsiSimpleFixedInteger& rhs);
996
997  /// Destructor
998  virtual ~OsiSimpleFixedInteger ();
999 
1000  /// Infeasibility - large is 0.5
1001  virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
1002  /** Creates a branching object
1003
1004    The preferred direction is set by \p way, 0 for down, 1 for up.
1005  */
1006  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
1007protected:
1008  /// data
1009 
1010};
1011
1012#include <string>
1013
1014#include "CglStored.hpp"
1015
1016class CoinWarmStartBasis;
1017/** Stored Temporary Cut Generator Class - destroyed after first use */
1018class CglTemporary : public CglStored {
1019 
1020public:
1021   
1022 
1023  /**@name Generate Cuts */
1024  //@{
1025  /** Generate Mixed Integer Stored cuts for the model of the
1026      solver interface, si.
1027
1028      Insert the generated cuts into OsiCut, cs.
1029
1030      This generator just looks at previously stored cuts
1031      and inserts any that are violated by enough
1032  */
1033  virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
1034                             const CglTreeInfo info = CglTreeInfo()) const;
1035  //@}
1036
1037  /**@name Constructors and destructors */
1038  //@{
1039  /// Default constructor
1040  CglTemporary ();
1041 
1042  /// Copy constructor
1043  CglTemporary (const CglTemporary & rhs);
1044
1045  /// Clone
1046  virtual CglCutGenerator * clone() const;
1047
1048  /// Assignment operator
1049  CglTemporary &
1050    operator=(const CglTemporary& rhs);
1051 
1052  /// Destructor
1053  virtual
1054    ~CglTemporary ();
1055  //@}
1056     
1057private:
1058 
1059 // Private member methods
1060
1061  // Private member data
1062};
1063//#############################################################################
1064
1065/**
1066   
1067This is to allow the user to replace initialSolve and resolve
1068*/
1069
1070class OsiSolverLinearizedQuadratic : public OsiClpSolverInterface {
1071 
1072public:
1073  //---------------------------------------------------------------------------
1074  /**@name Solve methods */
1075  //@{
1076  /// Solve initial LP relaxation
1077  virtual void initialSolve();
1078  //@}
1079 
1080 
1081  /**@name Constructors and destructors */
1082  //@{
1083  /// Default Constructor
1084  OsiSolverLinearizedQuadratic ();
1085  /// Useful constructor (solution should be good)
1086  OsiSolverLinearizedQuadratic(  ClpSimplex * quadraticModel);
1087  /// Clone
1088  virtual OsiSolverInterface * clone(bool copyData=true) const;
1089 
1090  /// Copy constructor
1091  OsiSolverLinearizedQuadratic (const OsiSolverLinearizedQuadratic &);
1092 
1093  /// Assignment operator
1094  OsiSolverLinearizedQuadratic & operator=(const OsiSolverLinearizedQuadratic& rhs);
1095 
1096  /// Destructor
1097  virtual ~OsiSolverLinearizedQuadratic ();
1098 
1099  //@}
1100 
1101 
1102  /**@name Sets and Gets */
1103  //@{
1104  /// Objective value of best solution found internally
1105  inline double bestObjectiveValue() const
1106  { return bestObjectiveValue_;};
1107  /// Best solution found internally
1108  const double * bestSolution() const
1109  { return bestSolution_;};
1110  /// Set special options
1111  inline void setSpecialOptions3(int value)
1112  { specialOptions3_=value;};
1113  /// Get special options
1114  inline int specialOptions3() const
1115  { return specialOptions3_;};
1116  /// Copy of quadratic model if one
1117  ClpSimplex * quadraticModel() const
1118  { return quadraticModel_;};
1119  //@}
1120 
1121  //---------------------------------------------------------------------------
1122 
1123protected:
1124 
1125 
1126  /**@name functions */
1127  //@{
1128 
1129  /**@name Private member data */
1130  //@{
1131  /// Objective value of best solution found internally
1132  double bestObjectiveValue_;
1133  /// Copy of quadratic model if one
1134  ClpSimplex * quadraticModel_;
1135  /// Best solution found internally
1136  double * bestSolution_;
1137  /**
1138     0 bit (1) - don't do mini B&B
1139     1 bit (2) - quadratic only in objective
1140  */
1141  int specialOptions3_;
1142  //@}
1143};
1144#endif
1145#endif
Note: See TracBrowser for help on using the repository browser.