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

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

for pseudo shadow prices in LOS

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