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

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

for heuristics and quadratic

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