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

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

update branches/devel for threads

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