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

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

for nonlinear

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 67.9 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef CbcModel_H
4#define CbcModel_H
5#include <string>
6#include <vector>
7#include "CoinFinite.hpp"
8#include "CoinMessageHandler.hpp"
9#include "OsiSolverInterface.hpp"
10#include "OsiBranchingObject.hpp"
11#include "OsiCuts.hpp"
12#include "CoinWarmStartBasis.hpp"
13#include "CbcCompareBase.hpp"
14#include "CbcMessage.hpp"
15
16//class OsiSolverInterface;
17
18class CbcCutGenerator;
19class OsiRowCut;
20class OsiBabSolver;
21class OsiRowCutDebugger;
22class CglCutGenerator;
23class CbcCutModifier;
24class CglTreeProbingInfo;
25class CbcHeuristic;
26class OsiObject;
27class CbcTree;
28class CbcStrategy;
29class CbcFeasibilityBase;
30class CbcStatistics;
31class CbcEventHandler ;
32class CglPreProcess;
33
34//#############################################################################
35
36/** Simple Branch and bound class
37
38  The initialSolve() method solves the initial LP relaxation of the MIP
39  problem. The branchAndBound() method can then be called to finish using
40  a branch and cut algorithm.
41
42  <h3>Search Tree Traversal</h3>
43
44  Subproblems (aka nodes) requiring additional evaluation are stored using
45  the CbcNode and CbcNodeInfo objects. Ancestry linkage is maintained in the
46  CbcNodeInfo object. Evaluation of a subproblem within branchAndBound()
47  proceeds as follows:
48  <ul>
49    <li> The node representing the most promising parent subproblem is popped
50         from the heap which holds the set of subproblems requiring further
51         evaluation.
52    <li> Using branching instructions stored in the node, and information in
53         its ancestors, the model and solver are adjusted to create the
54         active subproblem.
55    <li> If the parent subproblem will require further evaluation
56         (<i>i.e.</i>, there are branches remaining) its node is pushed back
57         on the heap. Otherwise, the node is deleted.  This may trigger
58         recursive deletion of ancestors.
59    <li> The newly created subproblem is evaluated.
60    <li> If the subproblem requires further evaluation, a node is created.
61         All information needed to recreate the subproblem (branching
62         information, row and column cuts) is placed in the node and the node
63         is added to the set of subproblems awaiting further evaluation.
64  </ul>
65  Note that there is never a node representing the active subproblem; the model
66  and solver represent the active subproblem.
67
68  <h3>Row (Constraint) Cut Handling</h3>
69
70  For a typical subproblem, the sequence of events is as follows:
71  <ul>
72    <li> The subproblem is rebuilt for further evaluation: One result of a
73         call to addCuts() is a traversal of ancestors, leaving a list of all
74         cuts used in the ancestors in #addedCuts_. This list is then scanned
75         to construct a basis that includes only tight cuts. Entries for
76         loose cuts are set to NULL.
77    <li> The subproblem is evaluated: One result of a call to solveWithCuts()
78         is the return of a set of newly generated cuts for the subproblem.
79         #addedCuts_ is also kept up-to-date as old cuts become loose.
80    <li> The subproblem is stored for further processing: A call to
81         CbcNodeInfo::addCuts() adds the newly generated cuts to the
82         CbcNodeInfo object associated with this node.
83  </ul>
84  See CbcCountRowCut for details of the bookkeeping associated with cut
85  management.
86*/
87
88class CbcModel  {
89 
90public:
91
92enum CbcIntParam {
93  /** The maximum number of nodes before terminating */
94  CbcMaxNumNode=0,
95  /** The maximum number of solutions before terminating */
96  CbcMaxNumSol,
97  /** Fathoming discipline
98
99    Controls objective function comparisons for purposes of fathoming by bound
100    or determining monotonic variables.
101
102    If 1, action is taken only when the current objective is strictly worse
103    than the target. Implementation is handled by adding a small tolerance to
104    the target.
105  */
106  CbcFathomDiscipline,
107  /** Adjusts printout
108      1 does different node message with number unsatisfied on last branch
109  */
110  CbcPrinting,
111  /** Just a marker, so that a static sized array can store parameters. */
112  CbcLastIntParam
113};
114
115enum CbcDblParam {
116  /** The maximum amount the value of an integer variable can vary from
117      integer and still be considered feasible. */
118  CbcIntegerTolerance=0,
119  /** The objective is assumed to worsen by this amount for each
120      integer infeasibility. */
121  CbcInfeasibilityWeight,
122  /** The amount by which to tighten the objective function cutoff when
123      a new solution is discovered. */
124  CbcCutoffIncrement,
125  /** Stop when the gap between the objective value of the best known solution
126    and the best bound on the objective of any solution is less than this.
127 
128    This is an absolute value. Conversion from a percentage is left to the
129    client.
130  */
131  CbcAllowableGap,
132  /** Stop when the gap between the objective value of the best known solution
133    and the best bound on the objective of any solution is less than this
134    fraction of of the absolute value of best known solution.
135 
136    Code stops if either this test or CbcAllowableGap test succeeds
137  */
138  CbcAllowableFractionGap,
139  /** \brief The maximum number of seconds before terminating.
140             A double should be adequate! */
141  CbcMaximumSeconds,
142  /// Cutoff - stored for speed
143  CbcCurrentCutoff,
144  /// Optimization direction - stored for speed
145  CbcOptimizationDirection,
146  /// Current objective value
147  CbcCurrentObjectiveValue,
148  /// Current minimization objective value
149  CbcCurrentMinimizationObjectiveValue,
150  /** \brief The time at start of model.
151             So that other pieces of code can access */
152  CbcStartSeconds,
153  /** Just a marker, so that a static sized array can store parameters. */
154  CbcLastDblParam
155};
156
157  //---------------------------------------------------------------------------
158
159public:
160  ///@name Solve methods
161  //@{
162    /** \brief Solve the initial LP relaxation
163
164      Invoke the solver's %initialSolve() method.
165    */
166    void initialSolve(); 
167
168    /** \brief Invoke the branch \& cut algorithm
169
170      The method assumes that initialSolve() has been called to solve the
171      LP relaxation. It processes the root node, then proceeds to explore the
172      branch & cut search tree. The search ends when the tree is exhausted or
173      one of several execution limits is reached.
174      If doStatistics is 1 summary statistics are printed
175      if 2 then also the path to best solution (if found by branching)
176      if 3 then also one line per node
177    */
178     void branchAndBound(int doStatistics=0);
179
180    /** \brief create a clean model from partially fixed problem
181
182      The method creates a new model with given bounds and with no tree.
183    */
184     CbcModel *  cleanModel(const double * lower, const double * upper);
185    /** \brief Invoke the branch \& cut algorithm on partially fixed problem
186
187      The method presolves the given model and does branch and cut. The search
188      ends when the tree is exhausted or maximum nodes is reached.
189
190      If better solution found then it is saved.
191
192      Returns 0 if search completed and solution, 1 if not completed and solution,
193      2 if completed and no solution, 3 if not completed and no solution.
194
195      Normally okay to do cleanModel immediately followed by subBranchandBound
196      (== other form of subBranchAndBound)
197      but may need to get at model for advanced features.
198
199      Deletes model2
200    */
201     int subBranchAndBound(CbcModel * model2,
202                           CbcModel * presolvedModel,
203                           int maximumNodes);
204    /** \brief Invoke the branch \& cut algorithm on partially fixed problem
205
206      The method creates a new model with given bounds, presolves it
207      then proceeds to explore the branch & cut search tree. The search
208      ends when the tree is exhausted or maximum nodes is reached.
209
210      If better solution found then it is saved.
211
212      Returns 0 if search completed and solution, 1 if not completed and solution,
213      2 if completed and no solution, 3 if not completed and no solution.
214
215      This is just subModel immediately followed by other version of
216      subBranchandBound.
217
218    */
219     int subBranchAndBound(const double * lower, const double * upper,
220                            int maximumNodes);
221
222    /** \brief Process root node and return a strengthened model
223
224      The method assumes that initialSolve() has been called to solve the
225      LP relaxation. It processes the root node and then returns a pointer
226      to the strengthened model (or NULL if infeasible)
227    */
228     OsiSolverInterface *  strengthenedModel();
229  /** preProcess problem - replacing solver
230      If makeEquality true then <= cliques converted to ==.
231      Presolve will be done numberPasses times.
232
233      Returns NULL if infeasible
234
235      If makeEquality is 1 add slacks to get cliques,
236      if 2 add slacks to get sos (but only if looks plausible) and keep sos info
237  */
238  CglPreProcess * preProcess( int makeEquality=0, int numberPasses=5,
239                  int tuning=5);
240  /** Does postprocessing - original solver back.
241      User has to delete process */
242  void postProcess(CglPreProcess * process);
243private:
244    /** \brief Evaluate a subproblem using cutting planes and heuristics
245
246      The method invokes a main loop which generates cuts, applies heuristics,
247      and reoptimises using the solver's native %resolve() method.
248      It returns true if the subproblem remains feasible at the end of the
249      evaluation.
250    */
251  bool solveWithCuts(OsiCuts & cuts, int numberTries,CbcNode * node);
252  /** Input one node output N nodes to put on tree and optional solution update
253      This should be able to operate in parallel so is given a solver and is const(ish)
254      However we will need to keep an array of solver_ and bases and more
255      status is 0 for normal, 1 if solution
256      Calling code should always push nodes back on tree
257  */
258  CbcNode ** solveOneNode(int whichSolver,CbcNode * node, 
259                          int & numberNodesOutput, int & status) ;
260  /// Update size of whichGenerator
261  void resizeWhichGenerator(int numberNow, int numberAfter);
262public:
263    /** \brief Reoptimise an LP relaxation
264   
265      Invoke the solver's %resolve() method.
266      whereFrom -
267      0 - initial continuous
268      1 - resolve on branch (before new cuts)
269      2 - after new cuts
270      3  - obsolete code or something modified problem in unexpected way
271      10 - after strong branching has fixed variables at root
272      11 - after strong branching has fixed variables in tree
273
274      returns 1 feasible, 0 infeasible, -1 feasible but skip cuts
275    */
276    int resolve(CbcNodeInfo * parent, int whereFrom);
277    /// Make given rows (L or G) into global cuts and remove from lp
278    void makeGlobalCuts(int numberRows,const int * which); 
279    /// Make given cut into a global cut
280    void makeGlobalCut(const OsiRowCut * cut); 
281    /// Make given cut into a global cut
282    void makeGlobalCut(const OsiRowCut & cut); 
283  //@}
284
285  /** \name Presolve methods */
286  //@{
287
288  /** Identify cliques and construct corresponding objects.
289
290      Find cliques with size in the range
291      [\p atLeastThisMany, \p lessThanThis] and construct corresponding
292      CbcClique objects.
293      If \p makeEquality is true then a new model may be returned if
294      modifications had to be made, otherwise \c this is returned.
295      If the problem is infeasible #numberObjects_ is set to -1.
296      A client must use deleteObjects() before a second call to findCliques().
297      If priorities exist, clique priority is set to the default.
298  */
299  CbcModel * findCliques(bool makeEquality, int atLeastThisMany,
300                         int lessThanThis, int defaultValue=1000);
301
302  /** Do integer presolve, creating a new (presolved) model.
303
304    Returns the new model, or NULL if feasibility is lost.
305    If weak is true then just does a normal presolve
306 
307    \todo It remains to work out the cleanest way of getting a solution to
308          the original problem at the end. So this is very preliminary.
309   */
310  CbcModel * integerPresolve(bool weak=false);
311
312  /** Do integer presolve, modifying the current model.
313
314      Returns true if the model remains feasible after presolve.
315  */
316  bool integerPresolveThisModel(OsiSolverInterface * originalSolver,bool weak=false);
317
318
319  /// Put back information into the original model after integer presolve.
320  void originalModel(CbcModel * presolvedModel,bool weak);
321
322  /** \brief For variables involved in VUB constraints, see if we can tighten
323             bounds by solving lp's
324
325      Returns false if feasibility is lost.
326      If CglProbing is available, it will be tried as well to see if it can
327      tighten bounds.
328      This routine is just a front end for tightenVubs(int,const int*,double).
329
330      If <tt>type = -1</tt> all variables are processed (could be very slow).
331      If <tt>type = 0</tt> only variables involved in VUBs are processed.
332      If <tt>type = n > 0</tt>, only the n most expensive VUB variables
333      are processed, where it is assumed that x is at its maximum so delta
334      would have to go to 1 (if x not at bound).
335
336      If \p allowMultipleBinary is true, then a VUB constraint is a row with
337      one continuous variable and any number of binary variables.
338
339      If <tt>useCutoff < 1.0e30</tt>, the original objective is installed as a
340      constraint with \p useCutoff as a bound.
341  */
342  bool tightenVubs(int type,bool allowMultipleBinary=false,
343                   double useCutoff=1.0e50);
344 
345  /** \brief For variables involved in VUB constraints, see if we can tighten
346             bounds by solving lp's
347
348    This version is just handed a list of variables to be processed.
349  */
350  bool tightenVubs(int numberVubs, const int * which,
351                   double useCutoff=1.0e50);
352  /**
353    Analyze problem to find a minimum change in the objective function.
354  */
355  void analyzeObjective();
356
357
358  //@}
359
360  /** \name Object manipulation routines
361 
362    See OsiObject for an explanation of `object' in the context of CbcModel.
363  */
364  //@{
365
366  /// Get the number of objects
367  inline int numberObjects() const { return numberObjects_;};
368  /// Set the number of objects
369  inline void setNumberObjects(int number) 
370  {  numberObjects_=number;};
371
372  /// Get the array of objects
373  inline OsiObject ** objects() const { return object_;};
374
375  /// Get the specified object
376  const inline OsiObject * object(int which) const { return object_[which];};
377  /// Get the specified object
378  inline OsiObject * modifiableObject(int which) const { return object_[which];};
379
380  /// Delete all object information (and just back to integers if true)
381  void deleteObjects(bool findIntegers=true);
382
383  /** Add in object information.
384 
385    Objects are cloned; the owner can delete the originals.
386  */
387  void addObjects(int numberObjects, OsiObject ** objects);
388
389  /** Add in object information.
390 
391    Objects are cloned; the owner can delete the originals.
392  */
393  void addObjects(int numberObjects, CbcObject ** objects);
394
395  /// Ensure attached objects point to this model.
396  void synchronizeModel() ;
397
398  /** \brief Identify integer variables and create corresponding objects.
399 
400    Record integer variables and create an CbcSimpleInteger object for each
401    one.
402    If \p startAgain is true, a new scan is forced, overwriting any existing
403    integer variable information.
404    If type > 0 then 1==PseudoCost
405  */
406
407  void findIntegers(bool startAgain,int type=0);
408
409  //@}
410
411  //---------------------------------------------------------------------------
412
413  /**@name Parameter set/get methods
414
415     The set methods return true if the parameter was set to the given value,
416     false if the value of the parameter is out of range.
417
418     The get methods return the value of the parameter.
419
420  */
421  //@{
422  /// Set an integer parameter
423  inline bool setIntParam(CbcIntParam key, int value) {
424    intParam_[key] = value;
425    return true;
426  }
427  /// Set a double parameter
428  inline bool setDblParam(CbcDblParam key, double value) {
429    dblParam_[key] = value;
430    return true;
431  }
432  /// Get an integer parameter
433  inline int getIntParam(CbcIntParam key) const {
434    return intParam_[key];
435  }
436  /// Get a double parameter
437  inline double getDblParam(CbcDblParam key) const {
438    return dblParam_[key];
439  }
440  /*! \brief Set cutoff bound on the objective function.
441
442    When using strict comparison, the bound is adjusted by a tolerance to
443    avoid accidentally cutting off the optimal solution.
444  */
445  void setCutoff(double value) ;
446
447  /// Get the cutoff bound on the objective function - always as minimize
448  inline double getCutoff() const
449  { //double value ;
450    //solver_->getDblParam(OsiDualObjectiveLimit,value) ;
451    //assert( dblParam_[CbcCurrentCutoff]== value * solver_->getObjSense());
452    return dblParam_[CbcCurrentCutoff];
453  }
454
455  /// Set the \link CbcModel::CbcMaxNumNode maximum node limit \endlink
456  inline bool setMaximumNodes( int value)
457  { return setIntParam(CbcMaxNumNode,value); }
458
459  /// Get the \link CbcModel::CbcMaxNumNode maximum node limit \endlink
460  inline int getMaximumNodes() const
461  { return getIntParam(CbcMaxNumNode); }
462
463  /** Set the
464      \link CbcModel::CbcMaxNumSol maximum number of solutions \endlink
465      desired.
466  */
467  inline bool setMaximumSolutions( int value) {
468    return setIntParam(CbcMaxNumSol,value);
469  }
470  /** Get the
471      \link CbcModel::CbcMaxNumSol maximum number of solutions \endlink
472      desired.
473  */
474  inline int getMaximumSolutions() const {
475    return getIntParam(CbcMaxNumSol);
476  }
477  /// Set the printing mode
478  inline bool setPrintingMode( int value)
479  { return setIntParam(CbcPrinting,value); }
480
481  /// Get the printing mode
482  inline int getPrintingMode() const
483  { return getIntParam(CbcPrinting); }
484
485  /** Set the
486      \link CbcModel::CbcMaximumSeconds maximum number of seconds \endlink
487      desired.
488  */
489  inline bool setMaximumSeconds( double value) {
490    return setDblParam(CbcMaximumSeconds,value);
491  }
492  /** Get the
493      \link CbcModel::CbcMaximumSeconds maximum number of seconds \endlink
494      desired.
495  */
496  inline double getMaximumSeconds() const {
497    return getDblParam(CbcMaximumSeconds);
498  }
499  /// Current time since start of branchAndbound
500  double getCurrentSeconds() const ;
501
502  /** Set the
503    \link CbcModel::CbcIntegerTolerance integrality tolerance \endlink
504  */
505  inline bool setIntegerTolerance( double value) {
506    return setDblParam(CbcIntegerTolerance,value);
507  }
508  /** Get the
509    \link CbcModel::CbcIntegerTolerance integrality tolerance \endlink
510  */
511  inline double getIntegerTolerance() const {
512    return getDblParam(CbcIntegerTolerance);
513  }
514
515  /** Set the
516      \link CbcModel::CbcInfeasibilityWeight
517            weight per integer infeasibility \endlink
518  */
519  inline bool setInfeasibilityWeight( double value) {
520    return setDblParam(CbcInfeasibilityWeight,value);
521  }
522  /** Get the
523      \link CbcModel::CbcInfeasibilityWeight
524            weight per integer infeasibility \endlink
525  */
526  inline double getInfeasibilityWeight() const {
527    return getDblParam(CbcInfeasibilityWeight);
528  }
529
530  /** Set the \link CbcModel::CbcAllowableGap allowable gap \endlink
531      between the best known solution and the best possible solution.
532  */
533  inline bool setAllowableGap( double value) {
534    return setDblParam(CbcAllowableGap,value);
535  }
536  /** Get the \link CbcModel::CbcAllowableGap allowable gap \endlink
537      between the best known solution and the best possible solution.
538  */
539  inline double getAllowableGap() const {
540    return getDblParam(CbcAllowableGap);
541  }
542
543  /** Set the \link CbcModel::CbcAllowableFractionGap fraction allowable gap \endlink
544      between the best known solution and the best possible solution.
545  */
546  inline bool setAllowableFractionGap( double value) {
547    return setDblParam(CbcAllowableFractionGap,value);
548  }
549  /** Get the \link CbcModel::CbcAllowableFractionGap fraction allowable gap \endlink
550      between the best known solution and the best possible solution.
551  */
552  inline double getAllowableFractionGap() const {
553    return getDblParam(CbcAllowableFractionGap);
554  }
555  /** Set the \link CbcModel::CbcAllowableFractionGap percentage allowable gap \endlink
556      between the best known solution and the best possible solution.
557  */
558  inline bool setAllowablePercentageGap( double value) {
559    return setDblParam(CbcAllowableFractionGap,value*0.01);
560  }
561  /** Get the \link CbcModel::CbcAllowableFractionGap percentage allowable gap \endlink
562      between the best known solution and the best possible solution.
563  */
564  inline double getAllowablePercentageGap() const {
565    return 100.0*getDblParam(CbcAllowableFractionGap);
566  }
567  /** Set the
568      \link CbcModel::CbcCutoffIncrement  \endlink
569      desired.
570  */
571  inline bool setCutoffIncrement( double value) {
572    return setDblParam(CbcCutoffIncrement,value);
573  }
574  /** Get the
575      \link CbcModel::CbcCutoffIncrement  \endlink
576      desired.
577  */
578  inline double getCutoffIncrement() const {
579    return getDblParam(CbcCutoffIncrement);
580  }
581
582  /** Pass in target solution and optional priorities.
583      If priorities then >0 means only branch if incorrect
584      while <0 means branch even if correct. +1 or -1 are
585      highest priority */
586  void setHotstartSolution(const double * solution, const int * priorities=NULL) ;
587 
588  /// Set the minimum drop to continue cuts
589  inline void setMinimumDrop(double value)
590  {minimumDrop_=value;};
591  /// Get the minimum drop to continue cuts
592  inline double getMinimumDrop() const
593  { return minimumDrop_;};
594
595  /** Set the maximum number of cut passes at root node (default 20)
596      Minimum drop can also be used for fine tuning */
597  inline void setMaximumCutPassesAtRoot(int value)
598  {maximumCutPassesAtRoot_=value;};
599  /** Get the maximum number of cut passes at root node */
600  inline int getMaximumCutPassesAtRoot() const
601  { return maximumCutPassesAtRoot_;};
602
603  /** Set the maximum number of cut passes at other nodes (default 10)
604      Minimum drop can also be used for fine tuning */
605  inline void setMaximumCutPasses(int value)
606  {maximumCutPasses_=value;};
607  /** Get the maximum number of cut passes at other nodes (default 10) */
608  inline int getMaximumCutPasses() const
609  { return maximumCutPasses_;};
610  /** Get current cut pass number in this round of cuts.
611      (1 is first pass) */
612  inline int getCurrentPassNumber() const
613  { return currentPassNumber_;};
614
615  /** Set the maximum number of candidates to be evaluated for strong
616    branching.
617
618    A value of 0 disables strong branching.
619  */
620  void setNumberStrong(int number);
621  /** Get the maximum number of candidates to be evaluated for strong
622    branching.
623  */
624  inline int numberStrong() const
625  { return numberStrong_;};
626  /** Set global preferred way to branch
627      -1 down, +1 up, 0 no preference */
628  inline void setPreferredWay(int value)
629  {preferredWay_=value;};
630  /** Get the preferred way to branch (default 0) */
631  inline int getPreferredWay() const
632  { return preferredWay_;};
633  /** Set size of mini - tree.  If > 1 then does total enumeration of
634      tree given by this best variables to branch on
635  */
636  inline void setSizeMiniTree(int value)
637  { sizeMiniTree_=value;};
638  inline int sizeMiniTree() const
639  { return sizeMiniTree_;};
640
641  /** Set the number of branches before pseudo costs believed
642      in dynamic strong branching.
643
644    A value of 0 disables dynamic strong branching.
645  */
646  void setNumberBeforeTrust(int number);
647  /** get the number of branches before pseudo costs believed
648      in dynamic strong branching. */
649  inline int numberBeforeTrust() const
650  { return numberBeforeTrust_;};
651  /** Set the number of variables for which to compute penalties
652      in dynamic strong branching.
653
654    A value of 0 disables penalties.
655  */
656  void setNumberPenalties(int number);
657  /** get the number of variables for which to compute penalties
658      in dynamic strong branching. */
659  inline int numberPenalties() const
660  { return numberPenalties_;};
661  /// Number of analyze iterations to do
662  inline void setNumberAnalyzeIterations(int number)
663  { numberAnalyzeIterations_=number;};
664  inline int numberAnalyzeIterations() const
665  { return numberAnalyzeIterations_;};
666  /** Get scale factor to make penalties match strong.
667      Should/will be computed */
668  inline double penaltyScaleFactor() const
669  { return penaltyScaleFactor_;};
670  /** Set scale factor to make penalties match strong.
671      Should/will be computed */
672  void setPenaltyScaleFactor(double value);
673  /** Problem type as set by user or found by analysis.  This will be extended
674      0 - not known
675      1 - Set partitioning <=
676      2 - Set partitioning ==
677      3 - Set covering
678      4 - all +- 1 or all +1 and odd
679  */
680  void inline setProblemType(int number)
681  { problemType_=number;};
682  inline int problemType() const
683  { return problemType_;};
684
685  /// Set how often to scan global cuts
686  void setHowOftenGlobalScan(int number);
687  /// Get how often to scan global cuts
688  inline int howOftenGlobalScan() const
689  { return howOftenGlobalScan_;};
690  /// Original columns as created by integerPresolve
691  inline int * originalColumns() const
692  { return originalColumns_;};
693
694  /** Set the print frequency.
695 
696    Controls the number of nodes evaluated between status prints.
697    If <tt>number <=0</tt> the print frequency is set to 100 nodes for large
698    problems, 1000 for small problems.
699    Print frequency has very slight overhead if small.
700  */
701  inline void setPrintFrequency(int number)
702  { printFrequency_=number;};
703  /// Get the print frequency
704  inline int printFrequency() const
705  { return printFrequency_;};
706  //@}
707
708  //---------------------------------------------------------------------------
709  ///@name Methods returning info on how the solution process terminated
710  //@{
711    /// Are there a numerical difficulties?
712    bool isAbandoned() const;
713    /// Is optimality proven?
714    bool isProvenOptimal() const;
715    /// Is  infeasiblity proven (or none better than cutoff)?
716    bool isProvenInfeasible() const;
717    /// Was continuous solution unbounded
718    bool isContinuousUnbounded() const;
719    /// Was continuous solution unbounded
720    bool isProvenDualInfeasible() const;
721    /// Node limit reached?
722    bool isNodeLimitReached() const;
723    /// Time limit reached?
724    bool isSecondsLimitReached() const;
725    /// Solution limit reached?
726    bool isSolutionLimitReached() const;
727    /// Get how many iterations it took to solve the problem.
728    inline int getIterationCount() const
729    { return numberIterations_;};
730    /// Get how many Nodes it took to solve the problem.
731    inline int getNodeCount() const
732    { return numberNodes_;};
733    /** Final status of problem
734        Some of these can be found out by is...... functions
735        -1 before branchAndBound
736        0 finished - check isProvenOptimal or isProvenInfeasible to see if solution found
737        (or check value of best solution)
738        1 stopped - on maxnodes, maxsols, maxtime
739        2 difficulties so run was abandoned
740        (5 event user programmed event occurred)
741    */
742    inline int status() const
743    { return status_;};
744    inline void setProblemStatus(int value)
745    { status_=value;};
746    /** Secondary status of problem
747        -1 unset (status_ will also be -1)
748        0 search completed with solution
749        1 linear relaxation not feasible (or worse than cutoff)
750        2 stopped on gap
751        3 stopped on nodes
752        4 stopped on time
753        5 stopped on user event
754        6 stopped on solutions
755        7 linear relaxation unbounded
756    */
757    inline int secondaryStatus() const
758    { return secondaryStatus_;};
759    inline void setSecondaryStatus(int value)
760    { secondaryStatus_=value;};
761    /// Are there numerical difficulties (for initialSolve) ?
762    bool isInitialSolveAbandoned() const ;
763    /// Is optimality proven (for initialSolve) ?
764    bool isInitialSolveProvenOptimal() const ;
765    /// Is primal infeasiblity proven (for initialSolve) ?
766    bool isInitialSolveProvenPrimalInfeasible() const ;
767    /// Is dual infeasiblity proven (for initialSolve) ?
768    bool isInitialSolveProvenDualInfeasible() const ;
769
770  //@}
771
772  //---------------------------------------------------------------------------
773  /**@name Problem information methods
774     
775     These methods call the solver's query routines to return
776     information about the problem referred to by the current object.
777     Querying a problem that has no data associated with it result in
778     zeros for the number of rows and columns, and NULL pointers from
779     the methods that return vectors.
780     
781     Const pointers returned from any data-query method are valid as
782     long as the data is unchanged and the solver is not called.
783  */
784  //@{
785  /// Number of rows in continuous (root) problem.
786  inline int numberRowsAtContinuous() const
787  { return numberRowsAtContinuous_;};
788
789  /// Get number of columns
790  inline int getNumCols() const
791  { return solver_->getNumCols();};
792 
793  /// Get number of rows
794  inline int getNumRows() const
795  { return solver_->getNumRows();};
796 
797  /// Get number of nonzero elements
798  inline CoinBigIndex getNumElements() const
799  { return solver_->getNumElements();};
800
801  /// Number of integers in problem
802  inline int numberIntegers() const
803  { return numberIntegers_;};
804  // Integer variables
805  inline const int * integerVariable() const 
806  { return integerVariable_;};
807  /// Whether or not integer
808  inline const char integerType(int i) const
809  { return integerInfo_[i];};
810  /// Whether or not integer
811  inline const char * integerType() const
812  { return integerInfo_;};
813
814  /// Get pointer to array[getNumCols()] of column lower bounds
815  inline const double * getColLower() const
816  { return solver_->getColLower();};
817 
818  /// Get pointer to array[getNumCols()] of column upper bounds
819  inline const double * getColUpper() const
820  { return solver_->getColUpper();};
821 
822  /** Get pointer to array[getNumRows()] of row constraint senses.
823      <ul>
824      <li>'L': <= constraint
825      <li>'E': =  constraint
826      <li>'G': >= constraint
827      <li>'R': ranged constraint
828      <li>'N': free constraint
829      </ul>
830  */
831  inline const char * getRowSense() const
832  { return solver_->getRowSense();};
833 
834  /** Get pointer to array[getNumRows()] of rows right-hand sides
835      <ul>
836      <li> if rowsense()[i] == 'L' then rhs()[i] == rowupper()[i]
837      <li> if rowsense()[i] == 'G' then rhs()[i] == rowlower()[i]
838      <li> if rowsense()[i] == 'R' then rhs()[i] == rowupper()[i]
839      <li> if rowsense()[i] == 'N' then rhs()[i] == 0.0
840      </ul>
841  */
842  inline const double * getRightHandSide() const
843  { return solver_->getRightHandSide();};
844 
845  /** Get pointer to array[getNumRows()] of row ranges.
846      <ul>
847      <li> if rowsense()[i] == 'R' then
848      rowrange()[i] == rowupper()[i] - rowlower()[i]
849      <li> if rowsense()[i] != 'R' then
850      rowrange()[i] is 0.0
851      </ul>
852  */
853  inline const double * getRowRange() const
854  { return solver_->getRowRange();};
855 
856  /// Get pointer to array[getNumRows()] of row lower bounds
857  inline const double * getRowLower() const
858  { return solver_->getRowLower();};
859 
860  /// Get pointer to array[getNumRows()] of row upper bounds
861  inline const double * getRowUpper() const
862  { return solver_->getRowUpper();};
863 
864  /// Get pointer to array[getNumCols()] of objective function coefficients
865  inline const double * getObjCoefficients() const
866  { return solver_->getObjCoefficients();};
867 
868  /// Get objective function sense (1 for min (default), -1 for max)
869  inline double getObjSense() const
870  {
871    //assert (dblParam_[CbcOptimizationDirection]== solver_->getObjSense());
872    return dblParam_[CbcOptimizationDirection];};
873 
874  /// Return true if variable is continuous
875  inline bool isContinuous(int colIndex) const
876  { return solver_->isContinuous(colIndex);};
877 
878  /// Return true if variable is binary
879  inline bool isBinary(int colIndex) const
880  { return solver_->isBinary(colIndex);};
881 
882  /** Return true if column is integer.
883      Note: This function returns true if the the column
884      is binary or a general integer.
885  */
886  inline bool isInteger(int colIndex) const
887  { return solver_->isInteger(colIndex);};
888 
889  /// Return true if variable is general integer
890  inline bool isIntegerNonBinary(int colIndex) const
891  { return solver_->isIntegerNonBinary(colIndex);};
892 
893  /// Return true if variable is binary and not fixed at either bound
894  inline bool isFreeBinary(int colIndex) const
895  { return solver_->isFreeBinary(colIndex) ;};
896 
897  /// Get pointer to row-wise copy of matrix
898  inline const CoinPackedMatrix * getMatrixByRow() const
899  { return solver_->getMatrixByRow();};
900 
901  /// Get pointer to column-wise copy of matrix
902  inline const CoinPackedMatrix * getMatrixByCol() const
903  { return solver_->getMatrixByCol();};
904 
905  /// Get solver's value for infinity
906  inline double getInfinity() const
907  { return solver_->getInfinity();};
908  /// Get pointer to array[getNumCols()] (for speed) of column lower bounds
909  inline const double * getCbcColLower() const
910  { return cbcColLower_;};
911  /// Get pointer to array[getNumCols()] (for speed) of column upper bounds
912  inline const double * getCbcColUpper() const
913  { return cbcColUpper_;};
914  /// Get pointer to array[getNumRows()] (for speed) of row lower bounds
915  inline const double * getCbcRowLower() const
916  { return cbcRowLower_;};
917  /// Get pointer to array[getNumRows()] (for speed) of row upper bounds
918  inline const double * getCbcRowUpper() const
919  { return cbcRowUpper_;};
920  /// Get pointer to array[getNumCols()] (for speed) of primal solution vector
921  inline const double * getCbcColSolution() const
922  { return cbcColSolution_;};
923  /// Get pointer to array[getNumRows()] (for speed) of dual prices
924  inline const double * getCbcRowPrice() const
925  { return cbcRowPrice_;};
926  /// Get a pointer to array[getNumCols()] (for speed) of reduced costs
927  inline const double * getCbcReducedCost() const
928  { return cbcReducedCost_;};
929  /// Get pointer to array[getNumRows()] (for speed) of row activity levels.
930  inline const double * getCbcRowActivity() const
931  { return cbcRowActivity_;};
932  //@}
933 
934 
935  /**@name Methods related to querying the solution */
936  //@{
937  /// Holds solution at continuous (after cuts if branchAndBound called)
938  inline double * continuousSolution() const
939  { return continuousSolution_;};
940  /** Array marked whenever a solution is found if non-zero.
941      Code marks if heuristic returns better so heuristic
942      need only mark if it wants to on solutions which
943      are worse than current */
944  inline int * usedInSolution() const
945  { return usedInSolution_;};
946  /// Increases usedInSolution for nonzeros
947  void incrementUsed(const double * solution);
948  /// Record a new incumbent solution and update objectiveValue
949  void setBestSolution(CBC_Message how,
950                       double & objectiveValue, const double *solution,
951                       bool fixVariables=false);
952  /// Just update objectiveValue
953  void setBestObjectiveValue( double objectiveValue);
954
955  /** Call this to really test if a valid solution can be feasible
956      Solution is number columns in size.
957      If fixVariables true then bounds of continuous solver updated.
958      Returns objective value (worse than cutoff if not feasible)
959      Previously computed objective value is now passed in (in case user does not do solve)
960 */
961  double checkSolution(double cutoff, const double * solution,
962                       bool fixVariables, double originalObjValue);
963  /** Test the current solution for feasiblility.
964
965    Scan all objects for indications of infeasibility. This is broken down
966    into simple integer infeasibility (\p numberIntegerInfeasibilities)
967    and all other reports of infeasibility (\p numberObjectInfeasibilities).
968  */
969  bool feasibleSolution(int & numberIntegerInfeasibilities,
970                        int & numberObjectInfeasibilities) const;
971
972  /** Solution to the most recent lp relaxation.
973
974    The solver's solution to the most recent lp relaxation.
975  */
976   
977  inline double * currentSolution() const
978  { return currentSolution_;};
979  /** For testing infeasibilities - will point to
980      currentSolution_ or solver-->getColSolution()
981  */
982  inline const double * testSolution() const
983  { return testSolution_;};
984  inline void setTestSolution(const double * solution)
985  { testSolution_ = solution;};
986  /// Make sure region there and optionally copy solution
987  void reserveCurrentSolution(const double * solution=NULL);
988
989  /// Get pointer to array[getNumCols()] of primal solution vector
990  inline const double * getColSolution() const
991  { return solver_->getColSolution();};
992 
993  /// Get pointer to array[getNumRows()] of dual prices
994  inline const double * getRowPrice() const
995  { return solver_->getRowPrice();};
996 
997  /// Get a pointer to array[getNumCols()] of reduced costs
998  inline const double * getReducedCost() const
999  { return solver_->getReducedCost();};
1000 
1001  /// Get pointer to array[getNumRows()] of row activity levels.
1002  inline const double * getRowActivity() const
1003  { return solver_->getRowActivity();};
1004 
1005  /// Get current objective function value
1006  inline double getCurrentObjValue() const
1007  { return dblParam_[CbcCurrentObjectiveValue]; }
1008  /// Get current minimization objective function value
1009  inline double getCurrentMinimizationObjValue() const
1010  { return dblParam_[CbcCurrentMinimizationObjectiveValue];}
1011 
1012  /// Get best objective function value as minimization
1013  inline double getMinimizationObjValue() const
1014  { return bestObjective_;};
1015  /// Set best objective function value as minimization
1016  inline void setMinimizationObjValue(double value) 
1017  { bestObjective_=value;};
1018 
1019  /// Get best objective function value
1020  inline double getObjValue() const
1021  { return bestObjective_ * solver_->getObjSense() ; } ;
1022  /** Get best possible objective function value.
1023      This is better of best possible left on tree
1024      and best solution found.
1025      If called from within branch and cut may be optimistic.
1026  */
1027  double getBestPossibleObjValue() const;
1028  /// Set best objective function value
1029  inline void setObjValue(double value) 
1030  { bestObjective_=value * solver_->getObjSense() ;};
1031 
1032  /** The best solution to the integer programming problem.
1033
1034    The best solution to the integer programming problem found during
1035    the search. If no solution is found, the method returns null.
1036  */
1037
1038  inline double * bestSolution() const
1039  { return bestSolution_;};
1040 
1041  /// Get number of solutions
1042  inline int getSolutionCount() const
1043  { return numberSolutions_;};
1044 
1045  /// Set number of solutions (so heuristics will be different)
1046  inline void setSolutionCount(int value) 
1047  { numberSolutions_=value;};
1048  /** Current phase (so heuristics etc etc can find out).
1049      0 - initial solve
1050      1 - solve with cuts at root
1051      2 - solve with cuts
1052      3 - other e.g. strong branching
1053      4 - trying to validate a solution
1054      5 - at end of search
1055  */
1056  inline int phase() const
1057  { return phase_;};
1058 
1059  /// Get number of heuristic solutions
1060  inline int getNumberHeuristicSolutions() const { return numberHeuristicSolutions_;};
1061
1062  /// Set objective function sense (1 for min (default), -1 for max,)
1063  inline void setObjSense(double s) { dblParam_[CbcOptimizationDirection]=s;
1064  solver_->setObjSense(s);};
1065
1066  /// Value of objective at continuous
1067  inline double getContinuousObjective() const
1068  { return originalContinuousObjective_;};
1069  inline void setContinuousObjective(double value)
1070  { originalContinuousObjective_=value;};
1071  /// Number of infeasibilities at continuous
1072  inline int getContinuousInfeasibilities() const
1073  { return continuousInfeasibilities_;};
1074  inline void setContinuousInfeasibilities(int value)
1075  { continuousInfeasibilities_=value;};
1076  /// Value of objective after root node cuts added
1077  inline double rootObjectiveAfterCuts() const
1078  { return continuousObjective_;};
1079  /// Sum of Changes to objective by first solve
1080  inline double sumChangeObjective() const
1081  { return sumChangeObjective1_;};
1082  /** Number of times global cuts violated.  When global cut pool then this
1083      should be kept for each cut and type of cut */
1084  inline int numberGlobalViolations() const
1085  { return numberGlobalViolations_;};
1086  inline void clearNumberGlobalViolations()
1087  { numberGlobalViolations_=0;};
1088  /// Whether to force a resolve after takeOffCuts
1089  inline bool resolveAfterTakeOffCuts() const
1090  { return resolveAfterTakeOffCuts_;};
1091  inline void setResolveAfterTakeOffCuts(bool yesNo)
1092  { resolveAfterTakeOffCuts_=yesNo;};
1093  //@}
1094
1095  /** \name Node selection */
1096  //@{
1097  // Comparison functions (which may be overridden by inheritance)
1098  inline CbcCompareBase * nodeComparison() const
1099  { return nodeCompare_;};
1100  void setNodeComparison(CbcCompareBase * compare);
1101  void setNodeComparison(CbcCompareBase & compare);
1102  //@}
1103
1104  /** \name Problem feasibility checking */
1105  //@{
1106  // Feasibility functions (which may be overridden by inheritance)
1107  inline CbcFeasibilityBase * problemFeasibility() const
1108  { return problemFeasibility_;};
1109  void setProblemFeasibility(CbcFeasibilityBase * feasibility);
1110  void setProblemFeasibility(CbcFeasibilityBase & feasibility);
1111  //@}
1112
1113  /** \name Tree methods and subtree methods */
1114  //@{
1115  /// Tree method e.g. heap (which may be overridden by inheritance)
1116  inline CbcTree * tree() const
1117  { return tree_;};
1118  /// For modifying tree handling (original is cloned)
1119  void passInTreeHandler(CbcTree & tree);
1120  /** For passing in an CbcModel to do a sub Tree (with derived tree handlers).
1121      Passed in model must exist for duration of branch and bound
1122  */
1123  void passInSubTreeModel(CbcModel & model);
1124  /** For retrieving a copy of subtree model with given OsiSolver.
1125      If no subtree model will use self (up to user to reset cutoff etc).
1126      If solver NULL uses current
1127  */
1128  CbcModel * subTreeModel(OsiSolverInterface * solver=NULL) const;
1129  /// Returns number of times any subtree stopped on nodes, time etc
1130  inline int numberStoppedSubTrees() const
1131  { return numberStoppedSubTrees_;}
1132  /// Says a sub tree was stopped
1133  inline void incrementSubTreeStopped()
1134  { numberStoppedSubTrees_++;};
1135  /** Whether to automatically do presolve before branch and bound (subTrees).
1136      0 - no
1137      1 - ordinary presolve
1138      2 - integer presolve (dodgy)
1139  */
1140  inline int typePresolve() const
1141  { return presolve_;};
1142  inline void setTypePresolve(int value)
1143  { presolve_=value;};
1144  //@}
1145
1146  /** \name Branching Decisions
1147 
1148    See the CbcBranchDecision class for additional information.
1149  */
1150  //@{
1151
1152  /// Get the current branching decision method.
1153  inline CbcBranchDecision * branchingMethod() const
1154  { return branchingMethod_;};
1155  /// Set the branching decision method.
1156  inline void setBranchingMethod(CbcBranchDecision * method)
1157  { delete branchingMethod_; branchingMethod_ = method->clone();};
1158  /** Set the branching method
1159 
1160    \overload
1161  */
1162  inline void setBranchingMethod(CbcBranchDecision & method)
1163  { delete branchingMethod_; branchingMethod_ = method.clone();};
1164  /// Get the current cut modifier method
1165  inline CbcCutModifier * cutModifier() const
1166  { return cutModifier_;};
1167  /// Set the cut modifier method
1168  void setCutModifier(CbcCutModifier * modifier);
1169  /** Set the cut modifier method
1170 
1171    \overload
1172  */
1173  void setCutModifier(CbcCutModifier & modifier);
1174  //@}
1175
1176  /** \name Row (constraint) and Column (variable) cut generation */
1177  //@{
1178
1179  /** State of search
1180      0 - no solution
1181      1 - only heuristic solutions
1182      2 - branched to a solution
1183      3 - no solution but many nodes
1184  */
1185  inline int stateOfSearch() const
1186  { return stateOfSearch_;};
1187  inline void setStateOfSearch(int state)
1188  { stateOfSearch_=state;};
1189  /// Strategy worked out - mainly at root node for use by CbcNode
1190  inline int searchStrategy() const
1191  { return searchStrategy_;};
1192  /// Set strategy worked out - mainly at root node for use by CbcNode
1193  inline void setSearchStrategy(int value)
1194  { searchStrategy_ = value; };
1195
1196  /// Get the number of cut generators
1197  inline int numberCutGenerators() const
1198  { return numberCutGenerators_;};
1199  /// Get the list of cut generators
1200  inline CbcCutGenerator ** cutGenerators() const
1201  { return generator_;};
1202  ///Get the specified cut generator
1203  inline CbcCutGenerator * cutGenerator(int i) const
1204  { return generator_[i];};
1205  ///Get the specified cut generator before any changes
1206  inline CbcCutGenerator * virginCutGenerator(int i) const
1207  { return virginGenerator_[i];};
1208  /** Add one generator - up to user to delete generators.
1209      howoften affects how generator is used. 0 or 1 means always,
1210      >1 means every that number of nodes.  Negative values have same
1211      meaning as positive but they may be switched off (-> -100) by code if
1212      not many cuts generated at continuous.  -99 is just done at root.
1213      Name is just for printout.
1214      If depth >0 overrides how often generator is called (if howOften==-1 or >0).
1215  */
1216  void addCutGenerator(CglCutGenerator * generator,
1217                       int howOften=1, const char * name=NULL,
1218                       bool normal=true, bool atSolution=false, 
1219                       bool infeasible=false,int howOftenInSub=-100,
1220                       int whatDepth=-1, int whatDepthInSub=-1);
1221//@}
1222  /** \name Strategy and sub models
1223 
1224    See the CbcStrategy class for additional information.
1225  */
1226  //@{
1227
1228  /// Get the current strategy
1229  inline CbcStrategy * strategy() const
1230  { return strategy_;};
1231  /// Set the strategy. Clones
1232  void setStrategy(CbcStrategy & strategy);
1233  /// Get the current parent model
1234  inline CbcModel * parentModel() const
1235  { return parentModel_;};
1236  /// Set the parent model
1237  inline void setParentModel(CbcModel & parentModel)
1238  { parentModel_ = &parentModel;};
1239  //@}
1240
1241
1242  /** \name Heuristics and priorities */
1243  //@{
1244  /// Add one heuristic - up to user to delete
1245  void addHeuristic(CbcHeuristic * generator);
1246  ///Get the specified heuristic
1247  inline CbcHeuristic * heuristic(int i) const
1248  { return heuristic_[i];};
1249  /// Get the number of heuristics
1250  inline int numberHeuristics() const
1251  { return numberHeuristics_;};
1252  /// Pointer to heuristic solver which found last solution (or NULL)
1253  inline CbcHeuristic * lastHeuristic() const
1254  { return lastHeuristic_;};
1255  /// set last heuristic which found a solution
1256  inline void setLastHeuristic(CbcHeuristic * last)
1257  { lastHeuristic_=last;};
1258
1259  /** Pass in branching priorities.
1260 
1261      If ifClique then priorities are on cliques otherwise priorities are
1262      on integer variables. 
1263      Other type (if exists set to default)
1264      1 is highest priority. (well actually -INT_MAX is but that's ugly)
1265      If hotstart > 0 then branches are created to force
1266      the variable to the value given by best solution.  This enables a
1267      sort of hot start.  The node choice should be greatest depth
1268      and hotstart should normally be switched off after a solution.
1269
1270      If ifNotSimpleIntegers true then appended to normal integers
1271
1272      This is now deprecated except for simple usage.  If user
1273      creates Cbcobjects then set priority in them
1274
1275      \internal Added for Kurt Spielberg.
1276  */
1277  void passInPriorities(const int * priorities, bool ifNotSimpleIntegers);
1278
1279  /// Returns priority level for an object (or 1000 if no priorities exist)
1280  inline int priority(int sequence) const
1281  { return object_[sequence]->priority();}; 
1282
1283  /*! \brief Set an event handler
1284 
1285    A clone of the handler passed as a parameter is stored in CbcModel.
1286  */
1287  void passInEventHandler(const CbcEventHandler *eventHandler) ;
1288
1289  /*! \brief Retrieve a pointer to the event handler */
1290  inline CbcEventHandler* getEventHandler() const
1291  { return (eventHandler_) ; } ;
1292
1293  //@}
1294   
1295  /**@name Setting/Accessing application data */
1296  //@{
1297    /** Set application data.
1298
1299        This is a pointer that the application can store into and
1300        retrieve from the solver interface.
1301        This field is available for the application to optionally
1302        define and use.
1303    */
1304    void setApplicationData (void * appData);
1305
1306    /// Get application data
1307    void * getApplicationData() const;
1308  /**
1309      For advanced applications you may wish to modify the behavior of Cbc
1310      e.g. if the solver is a NLP solver then you may not have an exact
1311      optimum solution at each step.  Information could be built into
1312      OsiSolverInterface but this is an alternative so that that interface
1313      does not have to be changed.  If something similar is useful to
1314      enough solvers then it could be migrated
1315      You can also pass in by using solver->setAuxiliaryInfo.
1316      You should do that if solver is odd - if solver is normal simplex
1317      then use this.
1318      NOTE - characteristics are not cloned
1319  */
1320  void passInSolverCharacteristics(OsiBabSolver * solverCharacteristics);
1321  /// Get solver characteristics
1322  inline const OsiBabSolver * solverCharacteristics() const
1323  { return solverCharacteristics_;};
1324  //@}
1325 
1326  //---------------------------------------------------------------------------
1327
1328  /**@name Message handling */
1329  //@{
1330  /// Pass in Message handler (not deleted at end)
1331  void passInMessageHandler(CoinMessageHandler * handler);
1332  /// Set language
1333  void newLanguage(CoinMessages::Language language);
1334  inline void setLanguage(CoinMessages::Language language)
1335  {newLanguage(language);};
1336  /// Return handler
1337  inline CoinMessageHandler * messageHandler() const
1338  {return handler_;};
1339  /// Return messages
1340  inline CoinMessages & messages() 
1341  {return messages_;};
1342  /// Return pointer to messages
1343  inline CoinMessages * messagesPointer() 
1344  {return &messages_;};
1345  /// Set log level
1346  void setLogLevel(int value);
1347  /// Get log level
1348  inline int logLevel() const
1349  { return handler_->logLevel();};
1350  //@}
1351  //---------------------------------------------------------------------------
1352  ///@name Specialized
1353  //@{
1354
1355  /**
1356      Set special options
1357      0 bit (1) - check if cuts valid (if on debugger list)
1358      1 bit (2) - use current basis to check integer solution (rather than all slack)
1359      2 bit (4) - don't check integer solution (by solving LP)
1360      3 bit (8) - fast analyze
1361      4 bit (16) - non-linear model - so no well defined CoinPackedMatrix
1362      5 bit (32) - keep names
1363      6 bit (64) - try for dominated columns
1364  */
1365  /// Set special options
1366  inline void setSpecialOptions(int value)
1367  { specialOptions_=value;};
1368  /// Get special options
1369  inline int specialOptions() const
1370  { return specialOptions_;};
1371  /// Says if normal solver i.e. has well defined CoinPackedMatrix
1372  inline bool normalSolver() const
1373  { return (specialOptions_&16)==0;};
1374  /// Now we may not own objects - just point to solver's objects
1375  inline bool ownObjects() const
1376  { return ownObjects_;};
1377  //@}
1378  //---------------------------------------------------------------------------
1379
1380  ///@name Constructors and destructors etc
1381  //@{
1382    /// Default Constructor
1383    CbcModel(); 
1384   
1385    /// Constructor from solver
1386    CbcModel(const OsiSolverInterface &);
1387 
1388    /** Assign a solver to the model (model assumes ownership)
1389
1390      On return, \p solver will be NULL.
1391      If deleteSolver then current solver deleted (if model owned)
1392
1393      \note Parameter settings in the outgoing solver are not inherited by
1394            the incoming solver.
1395    */
1396    void assignSolver(OsiSolverInterface *&solver,bool deleteSolver=true);
1397 
1398    /** Copy constructor .
1399      If noTree is true then tree and cuts are not copied
1400    */ 
1401    CbcModel(const CbcModel & rhs, bool noTree=false);
1402 
1403    /// Assignment operator
1404    CbcModel & operator=(const CbcModel& rhs);
1405 
1406    /// Destructor
1407     ~CbcModel ();
1408
1409    /// Returns solver - has current state
1410    inline OsiSolverInterface * solver() const
1411    { return solver_;};
1412
1413    /// Returns solver with continuous state
1414    inline OsiSolverInterface * continuousSolver() const
1415    { return continuousSolver_;};
1416
1417  /// A copy of the solver, taken at constructor or by saveReferenceSolver
1418  inline OsiSolverInterface * referenceSolver() const
1419  { return referenceSolver_;};
1420
1421  /// Save a copy of the current solver so can be reset to
1422  void saveReferenceSolver();
1423
1424  /** Uses a copy of reference solver to be current solver.
1425      Because of possible mismatches all exotic integer information is loat
1426      (apart from normal information in OsiSolverInterface)
1427      so SOS etc and priorities will have to be redone
1428  */
1429  void resetToReferenceSolver();
1430
1431  /// Clears out as much as possible (except solver)
1432  void gutsOfDestructor();
1433  /** Clears out enough to reset CbcModel as if no branch and bound done
1434   */
1435  void gutsOfDestructor2();
1436  //@}
1437
1438  ///@semi-private i.e. users should not use
1439  //@{
1440    /// Get how many Nodes it took to solve the problem.
1441    int getNodeCount2() const
1442    { return numberNodes2_;};
1443  /// Set pointers for speed
1444  void setPointers(const OsiSolverInterface * solver);
1445  /** Perform reduced cost fixing
1446
1447    Fixes integer variables at their current value based on reduced cost
1448    penalties.  Returns number fixed
1449  */
1450  int reducedCostFix() ;
1451  /// Encapsulates solver resolve
1452  int resolve(OsiSolverInterface * solver);
1453
1454  /** Encapsulates choosing a variable -
1455      anyAction -2, infeasible (-1 round again), 0 done
1456  */
1457  int chooseBranch(CbcNode * newNode, int numberPassesLeft,
1458                   CbcNode * oldNode, OsiCuts & cuts,
1459                   bool & resolved, CoinWarmStartBasis *lastws,
1460                   const double * lowerBefore,const double * upperBefore,
1461                   OsiSolverBranch * & branches);
1462  int chooseBranch(CbcNode * newNode, int numberPassesLeft, bool & resolved);
1463
1464  /** Return an empty basis object of the specified size
1465
1466    A useful utility when constructing a basis for a subproblem from scratch.
1467    The object returned will be of the requested capacity and appropriate for
1468    the solver attached to the model.
1469  */
1470  CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
1471
1472  /** Remove inactive cuts from the model
1473
1474    An OsiSolverInterface is expected to maintain a valid basis, but not a
1475    valid solution, when loose cuts are deleted. Restoring a valid solution
1476    requires calling the solver to reoptimise. If it's certain the solution
1477    will not be required, set allowResolve to false to suppress
1478    reoptimisation.
1479    If saveCuts then slack cuts will be saved
1480  */
1481  void takeOffCuts(OsiCuts &cuts, 
1482                     bool allowResolve,OsiCuts * saveCuts) ;
1483
1484  /** Determine and install the active cuts that need to be added for
1485    the current subproblem
1486
1487    The whole truth is a bit more complicated. The first action is a call to
1488    addCuts1(). addCuts() then sorts through the list, installs the tight
1489    cuts in the model, and does bookkeeping (adjusts reference counts).
1490    The basis returned from addCuts1() is adjusted accordingly.
1491   
1492    If it turns out that the node should really be fathomed by bound,
1493    addCuts() simply treats all the cuts as loose as it does the bookkeeping.
1494
1495    canFix true if extra information being passed
1496  */
1497  int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws,bool canFix);
1498
1499  /** Traverse the tree from node to root and prep the model
1500
1501    addCuts1() begins the job of prepping the model to match the current
1502    subproblem. The model is stripped of all cuts, and the search tree is
1503    traversed from node to root to determine the changes required. Appropriate
1504    bounds changes are installed, a list of cuts is collected but not
1505    installed, and an appropriate basis (minus the cuts, but big enough to
1506    accommodate them) is constructed.
1507
1508    \todo addCuts1() is called in contexts where it's known in advance that
1509          all that's desired is to determine a list of cuts and do the
1510          bookkeeping (adjust the reference counts). The work of installing
1511          bounds and building a basis goes to waste.
1512  */
1513  void addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
1514  /** Set objective value in a node.  This is separated out so that
1515     odd solvers can use.  It may look at extra information in
1516     solverCharacteriscs_ and will also use bound from parent node
1517  */
1518  void setObjectiveValue(CbcNode * thisNode, const CbcNode * parentNode) const;
1519
1520  /** If numberBeforeTrust >0 then we are going to use CbcBranchDynamic.
1521      Scan and convert CbcSimpleInteger objects
1522  */
1523  void convertToDynamic();
1524  /// Use cliques for pseudocost information - return nonzero if infeasible
1525  int cliquePseudoCosts(int doStatistics);
1526  /// Fill in useful estimates
1527  void pseudoShadow(double * down, double * up);
1528
1529  /// Get the hotstart solution
1530  inline const double * hotstartSolution() const
1531  { return hotstartSolution_;};
1532  /// Get the hotstart priorities
1533  inline const int * hotstartPriorities() const
1534  { return hotstartPriorities_;};
1535
1536  /// Return the list of cuts initially collected for this subproblem
1537  inline CbcCountRowCut ** addedCuts() const
1538  { return addedCuts_;};
1539  /// Number of entries in the list returned by #addedCuts()
1540  inline int currentNumberCuts() const
1541  { return currentNumberCuts_;};
1542  /// Global cuts
1543  inline OsiCuts * globalCuts() 
1544  { return &globalCuts_;};
1545  /// Copy and set a pointer to a row cut which will be added instead of normal branching.
1546  void setNextRowCut(const OsiRowCut & cut);
1547  /// Get a pointer to current node (be careful)
1548  inline CbcNode * currentNode() const
1549  { return currentNode_;};
1550  /// Get a pointer to probing info
1551  inline CglTreeProbingInfo * probingInfo() const
1552  { return probingInfo_;};
1553  /// Set the number of iterations done in strong branching.
1554  inline void setNumberStrongIterations(int number)
1555  { numberStrongIterations_ = number;};
1556  /// Get the number of iterations done in strong branching.
1557  inline int numberStrongIterations() const
1558  { return numberStrongIterations_;};
1559  /// Increment strong info
1560  void incrementStrongInfo(int numberTimes, int numberIterations,
1561                           int numberFixed, bool ifInfeasible);
1562  /// Create C++ lines to get to current state
1563  void generateCpp( FILE * fp,int options);
1564  /// Generate an OsiBranchingInformation object
1565  OsiBranchingInformation usefulInformation() const;
1566  //@}
1567
1568//---------------------------------------------------------------------------
1569
1570private:
1571  ///@name Private member data
1572  //@{
1573
1574  /// The solver associated with this model.
1575  OsiSolverInterface * solver_;
1576
1577  /** Ownership of the solver object
1578
1579    The convention is that CbcModel owns the null solver. Currently there
1580    is no public method to give CbcModel a solver without giving ownership,
1581    but the hook is here.
1582  */
1583  bool ourSolver_ ;
1584
1585  /// A copy of the solver, taken at the continuous (root) node.
1586  OsiSolverInterface * continuousSolver_;
1587
1588  /// A copy of the solver, taken at constructor or by saveReferenceSolver
1589  OsiSolverInterface * referenceSolver_;
1590
1591   /// Message handler
1592  CoinMessageHandler * handler_;
1593
1594  /** Flag to say if handler_ is the default handler.
1595 
1596    The default handler is deleted when the model is deleted. Other
1597    handlers (supplied by the client) will not be deleted.
1598  */
1599  bool defaultHandler_;
1600
1601  /// Cbc messages
1602  CoinMessages messages_;
1603
1604  /// Array for integer parameters
1605  int intParam_[CbcLastIntParam];
1606
1607  /// Array for double parameters
1608  double dblParam_[CbcLastDblParam];
1609
1610  /** Pointer to an empty warm start object
1611
1612    It turns out to be useful to have this available as a base from
1613    which to build custom warm start objects. This is typed as CoinWarmStart
1614    rather than CoinWarmStartBasis to allow for the possibility that a
1615    client might want to apply a solver that doesn't use a basis-based warm
1616    start. See getEmptyBasis for an example of how this field can be used.
1617  */
1618  mutable CoinWarmStart *emptyWarmStart_ ;
1619
1620  /// Best objective
1621  double bestObjective_;
1622  /// Best possible objective
1623  double bestPossibleObjective_;
1624  /// Sum of Changes to objective by first solve
1625  double sumChangeObjective1_;
1626  /// Sum of Changes to objective by subsequent solves
1627  double sumChangeObjective2_;
1628
1629  /// Array holding the incumbent (best) solution.
1630  double * bestSolution_;
1631
1632  /** Array holding the current solution.
1633
1634    This array is used more as a temporary.
1635  */
1636  double * currentSolution_;
1637  /** For testing infeasibilities - will point to
1638      currentSolution_ or solver-->getColSolution()
1639  */
1640  mutable const double * testSolution_;
1641  /// Global cuts
1642  OsiCuts globalCuts_;
1643
1644  /// Minimum degradation in objective value to continue cut generation
1645  double minimumDrop_;
1646  /// Number of solutions
1647  int numberSolutions_;
1648  /** State of search
1649      0 - no solution
1650      1 - only heuristic solutions
1651      2 - branched to a solution
1652      3 - no solution but many nodes
1653  */
1654  int stateOfSearch_;
1655  /// Hotstart solution
1656  double * hotstartSolution_;
1657  /// Hotstart priorities
1658  int * hotstartPriorities_;
1659  /// Number of heuristic solutions
1660  int numberHeuristicSolutions_;
1661  /// Cumulative number of nodes
1662  int numberNodes_;
1663  /** Cumulative number of nodes for statistics.
1664      Must fix to match up
1665  */
1666  int numberNodes2_;
1667  /// Cumulative number of iterations
1668  int numberIterations_;
1669  /// Status of problem - 0 finished, 1 stopped, 2 difficulties
1670  int status_;
1671  /** Secondary status of problem
1672      -1 unset (status_ will also be -1)
1673      0 search completed with solution
1674      1 linear relaxation not feasible (or worse than cutoff)
1675      2 stopped on gap
1676      3 stopped on nodes
1677      4 stopped on time
1678      5 stopped on user event
1679      6 stopped on solutions
1680   */
1681  int secondaryStatus_;
1682  /// Number of integers in problem
1683  int numberIntegers_;
1684  /// Number of rows at continuous
1685  int numberRowsAtContinuous_;
1686  /// Maximum number of cuts
1687  int maximumNumberCuts_;
1688  /** Current phase (so heuristics etc etc can find out).
1689      0 - initial solve
1690      1 - solve with cuts at root
1691      2 - solve with cuts
1692      3 - other e.g. strong branching
1693      4 - trying to validate a solution
1694      5 - at end of search
1695  */
1696  int phase_;
1697
1698  /// Number of entries in #addedCuts_
1699  int currentNumberCuts_;
1700
1701  /** Current limit on search tree depth
1702
1703    The allocated size of #walkback_. Increased as needed.
1704  */
1705  int maximumDepth_;
1706  /** Array used to assemble the path between a node and the search tree root
1707
1708    The array is resized when necessary. #maximumDepth_  is the current
1709    allocated size.
1710  */
1711  CbcNodeInfo ** walkback_;
1712
1713  /** The list of cuts initially collected for this subproblem
1714
1715    When the subproblem at this node is rebuilt, a set of cuts is collected
1716    for inclusion in the constraint system. If any of these cuts are
1717    subsequently removed because they have become loose, the corresponding
1718    entry is set to NULL.
1719  */
1720  CbcCountRowCut ** addedCuts_;
1721
1722  /** A pointer to a row cut which will be added instead of normal branching.
1723      After use it should be set to NULL.
1724  */
1725  OsiRowCut * nextRowCut_;
1726
1727  /// Current node so can be used elsewhere
1728  CbcNode * currentNode_;
1729
1730  /// Indices of integer variables
1731  int * integerVariable_;
1732  /// Whether of not integer
1733  char * integerInfo_;
1734  /// Holds solution at continuous (after cuts)
1735  double * continuousSolution_;
1736  /// Array marked whenever a solution is found if non-zero
1737  int * usedInSolution_;
1738  /**
1739      0 bit (1) - check if cuts valid (if on debugger list)
1740      1 bit (2) - use current basis to check integer solution (rather than all slack)
1741      2 bit (4) - don't check integer solution
1742      3 bit (8) - Strong is doing well - keep on
1743  */
1744  int specialOptions_;
1745  /// User node comparison function
1746  CbcCompareBase * nodeCompare_;
1747  /// User feasibility function (see CbcFeasibleBase.hpp)
1748  CbcFeasibilityBase * problemFeasibility_;
1749  /// Tree
1750  CbcTree * tree_;
1751  /// A pointer to model to be used for subtrees
1752  CbcModel * subTreeModel_;
1753  /// Number of times any subtree stopped on nodes, time etc
1754  int numberStoppedSubTrees_;
1755  /// Variable selection function
1756  CbcBranchDecision * branchingMethod_;
1757  /// Cut modifier function
1758  CbcCutModifier * cutModifier_;
1759  /// Strategy
1760  CbcStrategy * strategy_;
1761  /// Parent model
1762  CbcModel * parentModel_;
1763  /** Whether to automatically do presolve before branch and bound.
1764      0 - no
1765      1 - ordinary presolve
1766      2 - integer presolve (dodgy)
1767  */
1768  /// Pointer to array[getNumCols()] (for speed) of column lower bounds
1769  const double * cbcColLower_;
1770  /// Pointer to array[getNumCols()] (for speed) of column upper bounds
1771  const double * cbcColUpper_;
1772  /// Pointer to array[getNumRows()] (for speed) of row lower bounds
1773  const double * cbcRowLower_;
1774  /// Pointer to array[getNumRows()] (for speed) of row upper bounds
1775  const double * cbcRowUpper_;
1776  /// Pointer to array[getNumCols()] (for speed) of primal solution vector
1777  const double * cbcColSolution_;
1778  /// Pointer to array[getNumRows()] (for speed) of dual prices
1779  const double * cbcRowPrice_;
1780  /// Get a pointer to array[getNumCols()] (for speed) of reduced costs
1781  const double * cbcReducedCost_;
1782  /// Pointer to array[getNumRows()] (for speed) of row activity levels.
1783  const double * cbcRowActivity_;
1784  /// Pointer to user-defined data structure
1785  void * appData_;
1786  /// Pointer to
1787  int presolve_;
1788  /** Maximum number of candidates to consider for strong branching.
1789    To disable strong branching, set this to 0.
1790  */
1791  int numberStrong_;
1792  /** The number of branches before pseudo costs believed
1793      in dynamic strong branching. (0 off) */
1794  int numberBeforeTrust_;
1795  /** The number of variable sfor which to compute penalties
1796      in dynamic strong branching. (0 off) */
1797  int numberPenalties_;
1798  /** Scale factor to make penalties match strong.
1799      Should/will be computed */
1800  double penaltyScaleFactor_;
1801  /// Number of analyze iterations to do
1802  int numberAnalyzeIterations_;
1803  /// Arrays with analysis results
1804  double * analyzeResults_;
1805  /// Number of nodes infeasible by normal branching (before cuts)
1806  int numberInfeasibleNodes_;
1807  /** Problem type as set by user or found by analysis.  This will be extended
1808      0 - not known
1809      1 - Set partitioning <=
1810      2 - Set partitioning ==
1811      3 - Set covering
1812  */
1813  int problemType_;
1814  /// Print frequency
1815  int printFrequency_;
1816  /// Number of cut generators
1817  int numberCutGenerators_;
1818  // Cut generators
1819  CbcCutGenerator ** generator_;
1820  // Cut generators before any changes
1821  CbcCutGenerator ** virginGenerator_;
1822  /// Number of heuristics
1823  int numberHeuristics_;
1824  /// Heuristic solvers
1825  CbcHeuristic ** heuristic_;
1826  /// Pointer to heuristic solver which found last solution (or NULL)
1827  CbcHeuristic * lastHeuristic_;
1828  /*! Pointer to the event handler */
1829# ifdef CBC_ONLY_CLP
1830  ClpEventHandler *eventHandler_ ;
1831# else
1832  CbcEventHandler *eventHandler_ ;
1833# endif
1834
1835  /// Total number of objects
1836  int numberObjects_;
1837
1838  /** \brief Integer and Clique and ... information
1839
1840    \note The code assumes that the first objects on the list will be
1841          SimpleInteger objects for each integer variable, followed by
1842          Clique objects. Portions of the code that understand Clique objects
1843          will fail if they do not immediately follow the SimpleIntegers.
1844          Large chunks of the code will fail if the first objects are not
1845          SimpleInteger. As of 2003.08, SimpleIntegers and Cliques are the only
1846          objects.
1847  */
1848  OsiObject ** object_;
1849  /// Now we may not own objects - just point to solver's objects
1850  bool ownObjects_;
1851 
1852  /// Original columns as created by integerPresolve
1853  int * originalColumns_;
1854  /// How often to scan global cuts
1855  int howOftenGlobalScan_;
1856  /** Number of times global cuts violated.  When global cut pool then this
1857      should be kept for each cut and type of cut */
1858  int numberGlobalViolations_;
1859  /** Value of objective at continuous
1860      (Well actually after initial round of cuts)
1861  */
1862  double continuousObjective_;
1863  /** Value of objective before root node cuts added
1864  */
1865  double originalContinuousObjective_;
1866  /// Number of infeasibilities at continuous
1867  int continuousInfeasibilities_;
1868  /// Maximum number of cut passes at root
1869  int maximumCutPassesAtRoot_;
1870  /// Maximum number of cut passes
1871  int maximumCutPasses_;
1872  /// Preferred way of branching
1873  int preferredWay_;
1874  /// Current cut pass number
1875  int currentPassNumber_;
1876  /// Maximum number of cuts (for whichGenerator_)
1877  int maximumWhich_;
1878  /// Which cut generator generated this cut
1879  int * whichGenerator_;
1880  /// Maximum number of statistics
1881  int maximumStatistics_;
1882  /// statistics
1883  CbcStatistics ** statistics_;
1884  /// Maximum depth reached
1885  int maximumDepthActual_;
1886  /// Number of reduced cost fixings
1887  double numberDJFixed_;
1888  /// Probing info
1889  CglTreeProbingInfo * probingInfo_;
1890  /// Number of fixed by analyze at root
1891  int numberFixedAtRoot_;
1892  /// Number fixed by analyze so far
1893  int numberFixedNow_;
1894  /// Whether stopping on gap
1895  bool stoppedOnGap_;
1896  /// Whether event happened
1897  bool eventHappened_;
1898  /// Number of long strong goes
1899  int numberLongStrong_;
1900  /// Number of old active cuts
1901  int numberOldActiveCuts_;
1902  /// Number of new cuts
1903  int numberNewCuts_;
1904  /// Size of mini - tree
1905  int sizeMiniTree_;
1906  /// Strategy worked out - mainly at root node
1907  int searchStrategy_;
1908  /// Number of iterations in strong branching
1909  int numberStrongIterations_;
1910  /** 0 - number times strong branching done, 1 - number fixed, 2 - number infeasible */
1911  int strongInfo_[3];
1912  /**
1913      For advanced applications you may wish to modify the behavior of Cbc
1914      e.g. if the solver is a NLP solver then you may not have an exact
1915      optimum solution at each step.  This gives characteristics - just for one BAB.
1916      For actually saving/restoring a solution you need the actual solver one.
1917  */
1918  OsiBabSolver * solverCharacteristics_;
1919  /// Whether to force a resolve after takeOffCuts
1920  bool resolveAfterTakeOffCuts_;
1921 //@}
1922};
1923/// So we can use osiObject or CbcObject during transition
1924void getIntegerInformation(const OsiObject * object, double & originalLower,
1925                           double & originalUpper) ;
1926#endif
Note: See TracBrowser for help on using the repository browser.