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

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

for nonlinear

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