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

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

for tighter linear constraints in bilinear

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