source: trunk/Cbc/src/CbcModel.hpp @ 310

Last change on this file since 310 was 295, checked in by forrest, 14 years ago

for ampl

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