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

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

devel stuff

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