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

Last change on this file since 579 was 579, checked in by forrest, 13 years ago

add time and try two level bilinear

File size: 31.1 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 meshSize
759  inline double xMeshSize() const
760  { return xMeshSize_;};
761  inline void setXMeshSize(double value)
762  { xMeshSize_=value;};
763  /// Y meshSize
764  inline double yMeshSize() const
765  { return yMeshSize_;};
766  inline void setYMeshSize(double value)
767  { yMeshSize_=value;};
768  /// XY satisfied if two version differ by less than this
769  inline double xySatisfied() const
770  { return xySatisfied_;};
771  inline void setXYSatisfied(double value)
772  { xySatisfied_=value;};
773  /** branching strategy etc
774      bottom 2 bits
775      0 branch on either, 1 branch on x, 2 branch on y
776      next bit
777      4 set to say don't update coefficients
778      next bit
779      8 set to say don't use in feasible region
780  */
781  inline int branchingStrategy() const
782  { return branchingStrategy_;};
783  inline void setBranchingStrategy(int value)
784  { branchingStrategy_=value;};
785  /** Simple quadratic bound marker.
786      0 no
787      1 L if coefficient pos, G if negative i.e. value is ub on xy
788      2 G if coefficient pos, L if negative i.e. value is lb on xy
789      3 E
790      If bound then real coefficient is 1.0 and coefficient_ is bound
791  */
792  inline int boundType() const
793  { return boundType_;};
794  inline void setBoundType(int value)
795  { boundType_ = value;};
796  /// Does work of branching
797  void newBounds(OsiSolverInterface * solver, int way, short xOrY, double separator) const;
798  /// Updates coefficients - returns number updated
799  int updateCoefficients(const double * lower, const double * upper, double * objective,
800                          CoinPackedMatrix * matrix, CoinWarmStartBasis * basis) const;
801  /// Returns true value of single xyRow coefficient
802  double xyCoefficient(const double * solution) const;
803  /// Get LU coefficients from matrix
804  void getCoefficients(const OsiSolverInterface * solver,double xB[2], double yB[2], double xybar[4]) const;
805  /// Compute lambdas (third entry in each .B is current value) (nonzero if bad)
806  double computeLambdas(const double xB[3], const double yB[3],const double xybar[4],double lambda[4]) const;
807
808protected:
809  /// Compute lambdas if coefficients not changing
810  void computeLambdas(const OsiSolverInterface * solver,double lambda[4]) const;
811  /// data
812 
813  /// Coefficient
814  double coefficient_;
815  /// x mesh
816  double xMeshSize_;
817  /// y mesh
818  double yMeshSize_;
819  /// x satisfied if less than this away from mesh
820  double xSatisfied_;
821  /// y satisfied if less than this away from mesh
822  double ySatisfied_;
823  /// xy satisfied if less than this away from true
824  double xySatisfied_;
825  /// value of x or y to branch about
826  mutable double xyBranchValue_;
827  /// x column
828  int xColumn_;
829  /// y column
830  int yColumn_;
831  /// First lambda (of 4)
832  int firstLambda_;
833  /** branching strategy etc
834      bottom 2 bits
835      0 branch on either, 1 branch on x, 2 branch on y
836      next bit
837      4 set to say don't update coefficients
838      next bit
839      8 set to say don't use in feasible region
840  */
841  int branchingStrategy_;
842  /** Simple quadratic bound marker.
843      0 no
844      1 L if coefficient pos, G if negative i.e. value is ub on xy
845      2 G if coefficient pos, L if negative i.e. value is lb on xy
846      3 E
847      If bound then real coefficient is 1.0 and coefficient_ is bound
848  */
849  int boundType_;
850  /// x row
851  int xRow_;
852  /// y row (-1 if x*x)
853  int yRow_;
854  /// Output row
855  int xyRow_;
856  /// Convexity row
857  int convexity_;
858  /// Which chosen -1 none, 0 x, 1 y
859  mutable short chosen_;
860};
861/** Branching object for BiLinear objects
862
863 */
864class OsiBiLinearBranchingObject : public OsiTwoWayBranchingObject {
865
866public:
867
868  // Default Constructor
869  OsiBiLinearBranchingObject ();
870
871  // Useful constructor
872  OsiBiLinearBranchingObject (OsiSolverInterface * solver,  const OsiBiLinear * originalObject,
873                          int way,
874                          double separator, int chosen);
875 
876  // Copy constructor
877  OsiBiLinearBranchingObject ( const OsiBiLinearBranchingObject &);
878   
879  // Assignment operator
880  OsiBiLinearBranchingObject & operator=( const OsiBiLinearBranchingObject& rhs);
881
882  /// Clone
883  virtual OsiBranchingObject * clone() const;
884
885  // Destructor
886  virtual ~OsiBiLinearBranchingObject ();
887 
888  /// Does next branch and updates state
889  virtual double branch(OsiSolverInterface * solver);
890
891  /** \brief Print something about branch - only if log level high
892  */
893  virtual void print(const OsiSolverInterface * solver=NULL);
894  /** \brief Return true if branch should only bound variables
895  */
896  virtual bool boundBranch() const; 
897private:
898  /// data
899  /// 1 means branch on x, 2 branch on y
900  short chosen_;
901};
902/** Define Continuous BiLinear objects for an == bound
903
904    This models x*y = b where both are continuous
905
906*/
907
908
909class OsiBiLinearEquality : public OsiBiLinear {
910
911public:
912
913  // Default Constructor
914  OsiBiLinearEquality ();
915
916  /** Useful constructor -
917      This Adds in rows and variables to construct Ordered Set
918      for x*y = b
919      So note not const solver
920  */
921  OsiBiLinearEquality (OsiSolverInterface * solver, int xColumn,
922               int yColumn, int xyRow, double rhs,
923                       double xMesh);
924 
925  // Copy constructor
926  OsiBiLinearEquality ( const OsiBiLinearEquality &);
927   
928  /// Clone
929  virtual OsiObject * clone() const;
930
931  // Assignment operator
932  OsiBiLinearEquality & operator=( const OsiBiLinearEquality& rhs);
933
934  // Destructor
935  virtual ~OsiBiLinearEquality ();
936 
937  /// Possible improvement
938  virtual double improvement(const OsiSolverInterface * solver) const;
939  /** change grid
940      if type 0 then use solution and make finer
941      if 1 then back to original
942      returns mesh size
943  */
944  double newGrid(OsiSolverInterface * solver, int type) const;
945  /// Number of points
946  inline int numberPoints() const
947  { return numberPoints_;};
948  inline void setNumberPoints(int value)
949  { numberPoints_ = value;};
950
951private:
952  /// Number of points
953  int numberPoints_;
954};
955/// Define a single integer class - but one where you kep branching until fixed even if satsified
956
957
958class OsiSimpleFixedInteger : public OsiSimpleInteger {
959
960public:
961
962  /// Default Constructor
963  OsiSimpleFixedInteger ();
964
965  /// Useful constructor - passed solver index
966  OsiSimpleFixedInteger (const OsiSolverInterface * solver, int iColumn);
967 
968  /// Useful constructor - passed solver index and original bounds
969  OsiSimpleFixedInteger (int iColumn, double lower, double upper);
970 
971  /// Useful constructor - passed simple integer
972  OsiSimpleFixedInteger (const OsiSimpleInteger &);
973 
974  /// Copy constructor
975  OsiSimpleFixedInteger ( const OsiSimpleFixedInteger &);
976   
977  /// Clone
978  virtual OsiObject * clone() const;
979
980  /// Assignment operator
981  OsiSimpleFixedInteger & operator=( const OsiSimpleFixedInteger& rhs);
982
983  /// Destructor
984  virtual ~OsiSimpleFixedInteger ();
985 
986  /// Infeasibility - large is 0.5
987  virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
988  /** Creates a branching object
989
990    The preferred direction is set by \p way, 0 for down, 1 for up.
991  */
992  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
993protected:
994  /// data
995 
996};
997
998#include <string>
999
1000#include "CglStored.hpp"
1001
1002class CoinWarmStartBasis;
1003/** Stored Temporary Cut Generator Class - destroyed after first use */
1004class CglTemporary : public CglStored {
1005 
1006public:
1007   
1008 
1009  /**@name Generate Cuts */
1010  //@{
1011  /** Generate Mixed Integer Stored cuts for the model of the
1012      solver interface, si.
1013
1014      Insert the generated cuts into OsiCut, cs.
1015
1016      This generator just looks at previously stored cuts
1017      and inserts any that are violated by enough
1018  */
1019  virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
1020                             const CglTreeInfo info = CglTreeInfo()) const;
1021  //@}
1022
1023  /**@name Constructors and destructors */
1024  //@{
1025  /// Default constructor
1026  CglTemporary ();
1027 
1028  /// Copy constructor
1029  CglTemporary (const CglTemporary & rhs);
1030
1031  /// Clone
1032  virtual CglCutGenerator * clone() const;
1033
1034  /// Assignment operator
1035  CglTemporary &
1036    operator=(const CglTemporary& rhs);
1037 
1038  /// Destructor
1039  virtual
1040    ~CglTemporary ();
1041  //@}
1042     
1043private:
1044 
1045 // Private member methods
1046
1047  // Private member data
1048};
1049//#############################################################################
1050
1051/**
1052   
1053This is to allow the user to replace initialSolve and resolve
1054*/
1055
1056class OsiSolverLinearizedQuadratic : public OsiClpSolverInterface {
1057 
1058public:
1059  //---------------------------------------------------------------------------
1060  /**@name Solve methods */
1061  //@{
1062  /// Solve initial LP relaxation
1063  virtual void initialSolve();
1064  //@}
1065 
1066 
1067  /**@name Constructors and destructors */
1068  //@{
1069  /// Default Constructor
1070  OsiSolverLinearizedQuadratic ();
1071  /// Useful constructor (solution should be good)
1072  OsiSolverLinearizedQuadratic(  ClpSimplex * quadraticModel);
1073  /// Clone
1074  virtual OsiSolverInterface * clone(bool copyData=true) const;
1075 
1076  /// Copy constructor
1077  OsiSolverLinearizedQuadratic (const OsiSolverLinearizedQuadratic &);
1078 
1079  /// Assignment operator
1080  OsiSolverLinearizedQuadratic & operator=(const OsiSolverLinearizedQuadratic& rhs);
1081 
1082  /// Destructor
1083  virtual ~OsiSolverLinearizedQuadratic ();
1084 
1085  //@}
1086 
1087 
1088  /**@name Sets and Gets */
1089  //@{
1090  /// Objective value of best solution found internally
1091  inline double bestObjectiveValue() const
1092  { return bestObjectiveValue_;};
1093  /// Best solution found internally
1094  const double * bestSolution() const
1095  { return bestSolution_;};
1096  /// Set special options
1097  inline void setSpecialOptions3(int value)
1098  { specialOptions3_=value;};
1099  /// Get special options
1100  inline int specialOptions3() const
1101  { return specialOptions3_;};
1102  /// Copy of quadratic model if one
1103  ClpSimplex * quadraticModel() const
1104  { return quadraticModel_;};
1105  //@}
1106 
1107  //---------------------------------------------------------------------------
1108 
1109protected:
1110 
1111 
1112  /**@name functions */
1113  //@{
1114 
1115  /**@name Private member data */
1116  //@{
1117  /// Objective value of best solution found internally
1118  double bestObjectiveValue_;
1119  /// Copy of quadratic model if one
1120  ClpSimplex * quadraticModel_;
1121  /// Best solution found internally
1122  double * bestSolution_;
1123  /**
1124     0 bit (1) - don't do mini B&B
1125     1 bit (2) - quadratic only in objective
1126  */
1127  int specialOptions3_;
1128  //@}
1129};
1130#endif
1131#endif
Note: See TracBrowser for help on using the repository browser.