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

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

unbounded changes from devel

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