source: trunk/include/CbcModel.hpp @ 287

Last change on this file since 287 was 287, checked in by lou, 15 years ago

Remove CBC_ONLY_CLP build option, ClpEventHandler?.

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