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

Last change on this file since 491 was 481, checked in by forrest, 14 years ago

for nonlinear

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