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

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

many changes

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