source: branches/sandbox/Cbc/src/CbcModel.hpp @ 1332

Last change on this file since 1332 was 1332, checked in by EdwinStraver, 10 years ago

Further breakouts from branchAndBound()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 93.8 KB
Line 
1/* $Id: CbcModel.hpp 1332 2009-12-02 23:39:53Z EdwinStraver $ */
2// Copyright (C) 2002, International Business Machines
3// Corporation and others.  All Rights Reserved.
4#ifndef CbcModel_H
5#define CbcModel_H
6#include <string>
7#include <vector>
8#include "CoinFinite.hpp"
9#include "CoinMessageHandler.hpp"
10#include "OsiSolverInterface.hpp"
11#include "OsiBranchingObject.hpp"
12#include "OsiCuts.hpp"
13#include "CoinWarmStartBasis.hpp"
14#include "CbcCompareBase.hpp"
15#include "CbcMessage.hpp"
16#include "CbcEventHandler.hpp"
17#include "ClpDualRowPivot.hpp"
18
19//class OsiSolverInterface;
20
21class CbcCutGenerator;
22class OsiRowCut;
23class OsiBabSolver;
24class OsiRowCutDebugger;
25class CglCutGenerator;
26class CglStored;
27class CbcCutModifier;
28class CglTreeProbingInfo;
29class CbcHeuristic;
30class OsiObject;
31class CbcTree;
32class CbcStrategy;
33class CbcFeasibilityBase;
34class CbcStatistics;
35class CbcEventHandler ;
36class CglPreProcess;
37# ifdef COIN_HAS_CLP
38class ClpNodeStuff;
39#endif
40// #define CBC_CHECK_BASIS 1
41
42//#############################################################################
43
44/** Simple Branch and bound class
45
46  The initialSolve() method solves the initial LP relaxation of the MIP
47  problem. The branchAndBound() method can then be called to finish using
48  a branch and cut algorithm.
49
50  <h3>Search Tree Traversal</h3>
51
52  Subproblems (aka nodes) requiring additional evaluation are stored using
53  the CbcNode and CbcNodeInfo objects. Ancestry linkage is maintained in the
54  CbcNodeInfo object. Evaluation of a subproblem within branchAndBound()
55  proceeds as follows:
56  <ul>
57    <li> The node representing the most promising parent subproblem is popped
58         from the heap which holds the set of subproblems requiring further
59         evaluation.
60    <li> Using branching instructions stored in the node, and information in
61         its ancestors, the model and solver are adjusted to create the
62         active subproblem.
63    <li> If the parent subproblem will require further evaluation
64         (<i>i.e.</i>, there are branches remaining) its node is pushed back
65         on the heap. Otherwise, the node is deleted.  This may trigger
66         recursive deletion of ancestors.
67    <li> The newly created subproblem is evaluated.
68    <li> If the subproblem requires further evaluation, a node is created.
69         All information needed to recreate the subproblem (branching
70         information, row and column cuts) is placed in the node and the node
71         is added to the set of subproblems awaiting further evaluation.
72  </ul>
73  Note that there is never a node representing the active subproblem; the model
74  and solver represent the active subproblem.
75
76  <h3>Row (Constraint) Cut Handling</h3>
77
78  For a typical subproblem, the sequence of events is as follows:
79  <ul>
80    <li> The subproblem is rebuilt for further evaluation: One result of a
81         call to addCuts() is a traversal of ancestors, leaving a list of all
82         cuts used in the ancestors in #addedCuts_. This list is then scanned
83         to construct a basis that includes only tight cuts. Entries for
84         loose cuts are set to NULL.
85    <li> The subproblem is evaluated: One result of a call to solveWithCuts()
86         is the return of a set of newly generated cuts for the subproblem.
87         #addedCuts_ is also kept up-to-date as old cuts become loose.
88    <li> The subproblem is stored for further processing: A call to
89         CbcNodeInfo::addCuts() adds the newly generated cuts to the
90         CbcNodeInfo object associated with this node.
91  </ul>
92  See CbcCountRowCut for details of the bookkeeping associated with cut
93  management.
94*/
95
96class CbcModel  {
97
98public:
99
100    enum CbcIntParam {
101        /** The maximum number of nodes before terminating */
102        CbcMaxNumNode = 0,
103        /** The maximum number of solutions before terminating */
104        CbcMaxNumSol,
105        /** Fathoming discipline
106
107          Controls objective function comparisons for purposes of fathoming by bound
108          or determining monotonic variables.
109
110          If 1, action is taken only when the current objective is strictly worse
111          than the target. Implementation is handled by adding a small tolerance to
112          the target.
113        */
114        CbcFathomDiscipline,
115        /** Adjusts printout
116            1 does different node message with number unsatisfied on last branch
117        */
118        CbcPrinting,
119        /** Number of branches (may be more than number of nodes as may
120            include strong branching) */
121        CbcNumberBranches,
122        /** Just a marker, so that a static sized array can store parameters. */
123        CbcLastIntParam
124    };
125
126    enum CbcDblParam {
127        /** The maximum amount the value of an integer variable can vary from
128            integer and still be considered feasible. */
129        CbcIntegerTolerance = 0,
130        /** The objective is assumed to worsen by this amount for each
131            integer infeasibility. */
132        CbcInfeasibilityWeight,
133        /** The amount by which to tighten the objective function cutoff when
134            a new solution is discovered. */
135        CbcCutoffIncrement,
136        /** Stop when the gap between the objective value of the best known solution
137          and the best bound on the objective of any solution is less than this.
138
139          This is an absolute value. Conversion from a percentage is left to the
140          client.
141        */
142        CbcAllowableGap,
143        /** Stop when the gap between the objective value of the best known solution
144          and the best bound on the objective of any solution is less than this
145          fraction of of the absolute value of best known solution.
146
147          Code stops if either this test or CbcAllowableGap test succeeds
148        */
149        CbcAllowableFractionGap,
150        /** \brief The maximum number of seconds before terminating.
151               A double should be adequate! */
152        CbcMaximumSeconds,
153        /// Cutoff - stored for speed
154        CbcCurrentCutoff,
155        /// Optimization direction - stored for speed
156        CbcOptimizationDirection,
157        /// Current objective value
158        CbcCurrentObjectiveValue,
159        /// Current minimization objective value
160        CbcCurrentMinimizationObjectiveValue,
161        /** \brief The time at start of model.
162               So that other pieces of code can access */
163        CbcStartSeconds,
164        /** Stop doing heuristics when the gap between the objective value of the
165            best known solution and the best bound on the objective of any solution
166            is less than this.
167
168          This is an absolute value. Conversion from a percentage is left to the
169          client.
170        */
171        CbcHeuristicGap,
172        /** Stop doing heuristics when the gap between the objective value of the
173            best known solution and the best bound on the objective of any solution
174            is less than this fraction of of the absolute value of best known
175            solution.
176
177          Code stops if either this test or CbcAllowableGap test succeeds
178        */
179        CbcHeuristicFractionGap,
180        /// Smallest non-zero change on a branch
181        CbcSmallestChange,
182        /// Sum of non-zero changes on a branch
183        CbcSumChange,
184        /// Largest non-zero change on a branch
185        CbcLargestChange,
186        /// Small non-zero change on a branch to be used as guess
187        CbcSmallChange,
188        /** Just a marker, so that a static sized array can store parameters. */
189        CbcLastDblParam
190    };
191
192    //---------------------------------------------------------------------------
193
194public:
195    ///@name Solve methods
196    //@{
197    /** \brief Solve the initial LP relaxation
198
199      Invoke the solver's %initialSolve() method.
200    */
201    void initialSolve();
202
203    /** \brief Invoke the branch \& cut algorithm
204
205      The method assumes that initialSolve() has been called to solve the
206      LP relaxation. It processes the root node, then proceeds to explore the
207      branch & cut search tree. The search ends when the tree is exhausted or
208      one of several execution limits is reached.
209      If doStatistics is 1 summary statistics are printed
210      if 2 then also the path to best solution (if found by branching)
211      if 3 then also one line per node
212    */
213    void branchAndBound(int doStatistics = 0);
214private:
215
216    /** \brief Evaluate a subproblem using cutting planes and heuristics
217
218      The method invokes a main loop which generates cuts, applies heuristics,
219      and reoptimises using the solver's native %resolve() method.
220      It returns true if the subproblem remains feasible at the end of the
221      evaluation.
222    */
223    bool solveWithCuts(OsiCuts & cuts, int numberTries, CbcNode * node);
224    /** Input one node output N nodes to put on tree and optional solution update
225        This should be able to operate in parallel so is given a solver and is const(ish)
226        However we will need to keep an array of solver_ and bases and more
227        status is 0 for normal, 1 if solution
228        Calling code should always push nodes back on tree
229    */
230    CbcNode ** solveOneNode(int whichSolver, CbcNode * node,
231                            int & numberNodesOutput, int & status) ;
232    /// Update size of whichGenerator
233    void resizeWhichGenerator(int numberNow, int numberAfter);
234public:
235#ifdef CBC_KEEP_DEPRECATED
236    // See if anyone is using these any more!!
237    /** \brief create a clean model from partially fixed problem
238
239      The method creates a new model with given bounds and with no tree.
240    */
241    CbcModel *  cleanModel(const double * lower, const double * upper);
242    /** \brief Invoke the branch \& cut algorithm on partially fixed problem
243
244      The method presolves the given model and does branch and cut. The search
245      ends when the tree is exhausted or maximum nodes is reached.
246
247      If better solution found then it is saved.
248
249      Returns 0 if search completed and solution, 1 if not completed and solution,
250      2 if completed and no solution, 3 if not completed and no solution.
251
252      Normally okay to do cleanModel immediately followed by subBranchandBound
253      (== other form of subBranchAndBound)
254      but may need to get at model for advanced features.
255
256      Deletes model2
257    */
258    int subBranchAndBound(CbcModel * model2,
259                          CbcModel * presolvedModel,
260                          int maximumNodes);
261    /** \brief Invoke the branch \& cut algorithm on partially fixed problem
262
263      The method creates a new model with given bounds, presolves it
264      then proceeds to explore the branch & cut search tree. The search
265      ends when the tree is exhausted or maximum nodes is reached.
266
267      If better solution found then it is saved.
268
269      Returns 0 if search completed and solution, 1 if not completed and solution,
270      2 if completed and no solution, 3 if not completed and no solution.
271
272      This is just subModel immediately followed by other version of
273      subBranchandBound.
274
275    */
276    int subBranchAndBound(const double * lower, const double * upper,
277                          int maximumNodes);
278
279    /** \brief Process root node and return a strengthened model
280
281      The method assumes that initialSolve() has been called to solve the
282      LP relaxation. It processes the root node and then returns a pointer
283      to the strengthened model (or NULL if infeasible)
284    */
285    OsiSolverInterface *  strengthenedModel();
286    /** preProcess problem - replacing solver
287        If makeEquality true then <= cliques converted to ==.
288        Presolve will be done numberPasses times.
289
290        Returns NULL if infeasible
291
292        If makeEquality is 1 add slacks to get cliques,
293        if 2 add slacks to get sos (but only if looks plausible) and keep sos info
294    */
295    CglPreProcess * preProcess( int makeEquality = 0, int numberPasses = 5,
296                                int tuning = 5);
297    /** Does postprocessing - original solver back.
298        User has to delete process */
299    void postProcess(CglPreProcess * process);
300#endif
301    /// Adds an update information object
302    void addUpdateInformation(const CbcObjectUpdateData & data);
303    /** Do one node - broken out for clarity?
304        also for parallel (when baseModel!=this)
305        Returns 1 if solution found
306        node NULL on return if no branches left
307        newNode NULL if no new node created
308    */
309    int doOneNode(CbcModel * baseModel, CbcNode * & node, CbcNode * & newNode);
310
311    /// Returns true if locked
312    bool isLocked() const;
313#ifdef CBC_THREAD
314    /**
315       Locks a thread if parallel so that stuff like cut pool
316       can be updated and/or used.
317    */
318    void lockThread();
319    /**
320       Unlocks a thread if parallel to say cut pool stuff not needed
321    */
322    void unlockThread();
323#else
324    inline void lockThread() {}
325    inline void unlockThread() {}
326#endif
327private:
328    /** Move/copy information from one model to another
329        -1 - initialization
330        0 - from base model
331        1 - to base model (and reset)
332        2 - add in final statistics etc (and reset so can do clean destruction)
333    */
334    void moveToModel(CbcModel * baseModel, int mode);
335public:
336    /** \brief Reoptimise an LP relaxation
337
338      Invoke the solver's %resolve() method.
339      whereFrom -
340      0 - initial continuous
341      1 - resolve on branch (before new cuts)
342      2 - after new cuts
343      3  - obsolete code or something modified problem in unexpected way
344      10 - after strong branching has fixed variables at root
345      11 - after strong branching has fixed variables in tree
346
347      returns 1 feasible, 0 infeasible, -1 feasible but skip cuts
348    */
349    int resolve(CbcNodeInfo * parent, int whereFrom,
350                double * saveSolution = NULL,
351                double * saveLower = NULL,
352                double * saveUpper = NULL);
353    /// Make given rows (L or G) into global cuts and remove from lp
354    void makeGlobalCuts(int numberRows, const int * which);
355    /// Make given cut into a global cut
356    void makeGlobalCut(const OsiRowCut * cut);
357    /// Make given cut into a global cut
358    void makeGlobalCut(const OsiRowCut & cut);
359    /// Make given column cut into a global cut
360    void makeGlobalCut(const OsiColCut * cut);
361    /// Make given column cut into a global cut
362    void makeGlobalCut(const OsiColCut & cut);
363    //@}
364
365    /** \name Presolve methods */
366    //@{
367
368    /** Identify cliques and construct corresponding objects.
369
370        Find cliques with size in the range
371        [\p atLeastThisMany, \p lessThanThis] and construct corresponding
372        CbcClique objects.
373        If \p makeEquality is true then a new model may be returned if
374        modifications had to be made, otherwise \c this is returned.
375        If the problem is infeasible #numberObjects_ is set to -1.
376        A client must use deleteObjects() before a second call to findCliques().
377        If priorities exist, clique priority is set to the default.
378    */
379    CbcModel * findCliques(bool makeEquality, int atLeastThisMany,
380                           int lessThanThis, int defaultValue = 1000);
381
382    /** Do integer presolve, creating a new (presolved) model.
383
384      Returns the new model, or NULL if feasibility is lost.
385      If weak is true then just does a normal presolve
386
387      \todo It remains to work out the cleanest way of getting a solution to
388            the original problem at the end. So this is very preliminary.
389     */
390    CbcModel * integerPresolve(bool weak = false);
391
392    /** Do integer presolve, modifying the current model.
393
394        Returns true if the model remains feasible after presolve.
395    */
396    bool integerPresolveThisModel(OsiSolverInterface * originalSolver, bool weak = false);
397
398
399    /// Put back information into the original model after integer presolve.
400    void originalModel(CbcModel * presolvedModel, bool weak);
401
402    /** \brief For variables involved in VUB constraints, see if we can tighten
403           bounds by solving lp's
404
405        Returns false if feasibility is lost.
406        If CglProbing is available, it will be tried as well to see if it can
407        tighten bounds.
408        This routine is just a front end for tightenVubs(int,const int*,double).
409
410        If <tt>type = -1</tt> all variables are processed (could be very slow).
411        If <tt>type = 0</tt> only variables involved in VUBs are processed.
412        If <tt>type = n > 0</tt>, only the n most expensive VUB variables
413        are processed, where it is assumed that x is at its maximum so delta
414        would have to go to 1 (if x not at bound).
415
416        If \p allowMultipleBinary is true, then a VUB constraint is a row with
417        one continuous variable and any number of binary variables.
418
419        If <tt>useCutoff < 1.0e30</tt>, the original objective is installed as a
420        constraint with \p useCutoff as a bound.
421    */
422    bool tightenVubs(int type, bool allowMultipleBinary = false,
423                     double useCutoff = 1.0e50);
424
425    /** \brief For variables involved in VUB constraints, see if we can tighten
426           bounds by solving lp's
427
428      This version is just handed a list of variables to be processed.
429    */
430    bool tightenVubs(int numberVubs, const int * which,
431                     double useCutoff = 1.0e50);
432    /**
433      Analyze problem to find a minimum change in the objective function.
434    */
435    void analyzeObjective();
436
437    /**
438      Add additional integers.
439    */
440    void AddIntegers();
441   
442    /**
443      Save copy of the model.
444    */
445    void saveModel(OsiSolverInterface * saveSolver, double * checkCutoffForRestart, bool * feasible);
446
447#ifdef COIN_HAS_CLP
448        void possiblePivotMethodChange( ClpDualRowPivot ** savePivotMethod, int lower, int upper);
449#endif
450    //@}
451
452    /** \name Object manipulation routines
453
454      See OsiObject for an explanation of `object' in the context of CbcModel.
455    */
456    //@{
457
458    /// Get the number of objects
459    inline int numberObjects() const {
460        return numberObjects_;
461    }
462    /// Set the number of objects
463    inline void setNumberObjects(int number) {
464        numberObjects_ = number;
465    }
466
467    /// Get the array of objects
468    inline OsiObject ** objects() const {
469        return object_;
470    }
471
472    /// Get the specified object
473    const inline OsiObject * object(int which) const {
474        return object_[which];
475    }
476    /// Get the specified object
477    inline OsiObject * modifiableObject(int which) const {
478        return object_[which];
479    }
480
481    void setOptionalInteger(int index);
482
483    /// Delete all object information (and just back to integers if true)
484    void deleteObjects(bool findIntegers = true);
485
486    /** Add in object information.
487
488      Objects are cloned; the owner can delete the originals.
489    */
490    void addObjects(int numberObjects, OsiObject ** objects);
491
492    /** Add in object information.
493
494      Objects are cloned; the owner can delete the originals.
495    */
496    void addObjects(int numberObjects, CbcObject ** objects);
497
498    /// Ensure attached objects point to this model.
499    void synchronizeModel() ;
500
501    /** \brief Identify integer variables and create corresponding objects.
502
503      Record integer variables and create an CbcSimpleInteger object for each
504      one.
505      If \p startAgain is true, a new scan is forced, overwriting any existing
506      integer variable information.
507      If type > 0 then 1==PseudoCost, 2 new ones low priority
508    */
509
510    void findIntegers(bool startAgain, int type = 0);
511
512    //@}
513
514    //---------------------------------------------------------------------------
515
516    /**@name Parameter set/get methods
517
518       The set methods return true if the parameter was set to the given value,
519       false if the value of the parameter is out of range.
520
521       The get methods return the value of the parameter.
522
523    */
524    //@{
525    /// Set an integer parameter
526    inline bool setIntParam(CbcIntParam key, int value) {
527        intParam_[key] = value;
528        return true;
529    }
530    /// Set a double parameter
531    inline bool setDblParam(CbcDblParam key, double value) {
532        dblParam_[key] = value;
533        return true;
534    }
535    /// Get an integer parameter
536    inline int getIntParam(CbcIntParam key) const {
537        return intParam_[key];
538    }
539    /// Get a double parameter
540    inline double getDblParam(CbcDblParam key) const {
541        return dblParam_[key];
542    }
543    /*! \brief Set cutoff bound on the objective function.
544
545      When using strict comparison, the bound is adjusted by a tolerance to
546      avoid accidentally cutting off the optimal solution.
547    */
548    void setCutoff(double value) ;
549
550    /// Get the cutoff bound on the objective function - always as minimize
551    inline double getCutoff() const { //double value ;
552        //solver_->getDblParam(OsiDualObjectiveLimit,value) ;
553        //assert( dblParam_[CbcCurrentCutoff]== value * solver_->getObjSense());
554        return dblParam_[CbcCurrentCutoff];
555    }
556
557    /// Set the \link CbcModel::CbcMaxNumNode maximum node limit \endlink
558    inline bool setMaximumNodes( int value) {
559        return setIntParam(CbcMaxNumNode, value);
560    }
561
562    /// Get the \link CbcModel::CbcMaxNumNode maximum node limit \endlink
563    inline int getMaximumNodes() const {
564        return getIntParam(CbcMaxNumNode);
565    }
566
567    /** Set the
568        \link CbcModel::CbcMaxNumSol maximum number of solutions \endlink
569        desired.
570    */
571    inline bool setMaximumSolutions( int value) {
572        return setIntParam(CbcMaxNumSol, value);
573    }
574    /** Get the
575        \link CbcModel::CbcMaxNumSol maximum number of solutions \endlink
576        desired.
577    */
578    inline int getMaximumSolutions() const {
579        return getIntParam(CbcMaxNumSol);
580    }
581    /// Set the printing mode
582    inline bool setPrintingMode( int value) {
583        return setIntParam(CbcPrinting, value);
584    }
585
586    /// Get the printing mode
587    inline int getPrintingMode() const {
588        return getIntParam(CbcPrinting);
589    }
590
591    /** Set the
592        \link CbcModel::CbcMaximumSeconds maximum number of seconds \endlink
593        desired.
594    */
595    inline bool setMaximumSeconds( double value) {
596        return setDblParam(CbcMaximumSeconds, value);
597    }
598    /** Get the
599        \link CbcModel::CbcMaximumSeconds maximum number of seconds \endlink
600        desired.
601    */
602    inline double getMaximumSeconds() const {
603        return getDblParam(CbcMaximumSeconds);
604    }
605    /// Current time since start of branchAndbound
606    double getCurrentSeconds() const ;
607
608    /// Return true if maximum time reached
609    bool maximumSecondsReached() const ;
610
611    /** Set the
612      \link CbcModel::CbcIntegerTolerance integrality tolerance \endlink
613    */
614    inline bool setIntegerTolerance( double value) {
615        return setDblParam(CbcIntegerTolerance, value);
616    }
617    /** Get the
618      \link CbcModel::CbcIntegerTolerance integrality tolerance \endlink
619    */
620    inline double getIntegerTolerance() const {
621        return getDblParam(CbcIntegerTolerance);
622    }
623
624    /** Set the
625        \link CbcModel::CbcInfeasibilityWeight
626          weight per integer infeasibility \endlink
627    */
628    inline bool setInfeasibilityWeight( double value) {
629        return setDblParam(CbcInfeasibilityWeight, value);
630    }
631    /** Get the
632        \link CbcModel::CbcInfeasibilityWeight
633          weight per integer infeasibility \endlink
634    */
635    inline double getInfeasibilityWeight() const {
636        return getDblParam(CbcInfeasibilityWeight);
637    }
638
639    /** Set the \link CbcModel::CbcAllowableGap allowable gap \endlink
640        between the best known solution and the best possible solution.
641    */
642    inline bool setAllowableGap( double value) {
643        return setDblParam(CbcAllowableGap, value);
644    }
645    /** Get the \link CbcModel::CbcAllowableGap allowable gap \endlink
646        between the best known solution and the best possible solution.
647    */
648    inline double getAllowableGap() const {
649        return getDblParam(CbcAllowableGap);
650    }
651
652    /** Set the \link CbcModel::CbcAllowableFractionGap fraction allowable gap \endlink
653        between the best known solution and the best possible solution.
654    */
655    inline bool setAllowableFractionGap( double value) {
656        return setDblParam(CbcAllowableFractionGap, value);
657    }
658    /** Get the \link CbcModel::CbcAllowableFractionGap fraction allowable gap \endlink
659        between the best known solution and the best possible solution.
660    */
661    inline double getAllowableFractionGap() const {
662        return getDblParam(CbcAllowableFractionGap);
663    }
664    /** Set the \link CbcModel::CbcAllowableFractionGap percentage allowable gap \endlink
665        between the best known solution and the best possible solution.
666    */
667    inline bool setAllowablePercentageGap( double value) {
668        return setDblParam(CbcAllowableFractionGap, value*0.01);
669    }
670    /** Get the \link CbcModel::CbcAllowableFractionGap percentage allowable gap \endlink
671        between the best known solution and the best possible solution.
672    */
673    inline double getAllowablePercentageGap() const {
674        return 100.0*getDblParam(CbcAllowableFractionGap);
675    }
676    /** Set the \link CbcModel::CbcHeuristicGap heuristic gap \endlink
677        between the best known solution and the best possible solution.
678    */
679    inline bool setHeuristicGap( double value) {
680        return setDblParam(CbcHeuristicGap, value);
681    }
682    /** Get the \link CbcModel::CbcHeuristicGap heuristic gap \endlink
683        between the best known solution and the best possible solution.
684    */
685    inline double getHeuristicGap() const {
686        return getDblParam(CbcHeuristicGap);
687    }
688
689    /** Set the \link CbcModel::CbcHeuristicFractionGap fraction heuristic gap \endlink
690        between the best known solution and the best possible solution.
691    */
692    inline bool setHeuristicFractionGap( double value) {
693        return setDblParam(CbcHeuristicFractionGap, value);
694    }
695    /** Get the \link CbcModel::CbcHeuristicFractionGap fraction heuristic gap \endlink
696        between the best known solution and the best possible solution.
697    */
698    inline double getHeuristicFractionGap() const {
699        return getDblParam(CbcHeuristicFractionGap);
700    }
701    /** Set the
702        \link CbcModel::CbcCutoffIncrement  \endlink
703        desired.
704    */
705    inline bool setCutoffIncrement( double value) {
706        return setDblParam(CbcCutoffIncrement, value);
707    }
708    /** Get the
709        \link CbcModel::CbcCutoffIncrement  \endlink
710        desired.
711    */
712    inline double getCutoffIncrement() const {
713        return getDblParam(CbcCutoffIncrement);
714    }
715
716    /** Pass in target solution and optional priorities.
717        If priorities then >0 means only branch if incorrect
718        while <0 means branch even if correct. +1 or -1 are
719        highest priority */
720    void setHotstartSolution(const double * solution, const int * priorities = NULL) ;
721
722    /// Set the minimum drop to continue cuts
723    inline void setMinimumDrop(double value) {
724        minimumDrop_ = value;
725    }
726    /// Get the minimum drop to continue cuts
727    inline double getMinimumDrop() const {
728        return minimumDrop_;
729    }
730
731    /** Set the maximum number of cut passes at root node (default 20)
732        Minimum drop can also be used for fine tuning */
733    inline void setMaximumCutPassesAtRoot(int value) {
734        maximumCutPassesAtRoot_ = value;
735    }
736    /** Get the maximum number of cut passes at root node */
737    inline int getMaximumCutPassesAtRoot() const {
738        return maximumCutPassesAtRoot_;
739    }
740
741    /** Set the maximum number of cut passes at other nodes (default 10)
742        Minimum drop can also be used for fine tuning */
743    inline void setMaximumCutPasses(int value) {
744        maximumCutPasses_ = value;
745    }
746    /** Get the maximum number of cut passes at other nodes (default 10) */
747    inline int getMaximumCutPasses() const {
748        return maximumCutPasses_;
749    }
750    /** Get current cut pass number in this round of cuts.
751        (1 is first pass) */
752    inline int getCurrentPassNumber() const {
753        return currentPassNumber_;
754    }
755
756    /** Set the maximum number of candidates to be evaluated for strong
757      branching.
758
759      A value of 0 disables strong branching.
760    */
761    void setNumberStrong(int number);
762    /** Get the maximum number of candidates to be evaluated for strong
763      branching.
764    */
765    inline int numberStrong() const {
766        return numberStrong_;
767    }
768    /** Set global preferred way to branch
769        -1 down, +1 up, 0 no preference */
770    inline void setPreferredWay(int value) {
771        preferredWay_ = value;
772    }
773    /** Get the preferred way to branch (default 0) */
774    inline int getPreferredWay() const {
775        return preferredWay_;
776    }
777    /// Get at which depths to do cuts
778    inline int whenCuts() const {
779        return whenCuts_;
780    }
781    /// Set at which depths to do cuts
782    inline void setWhenCuts(int value) {
783        whenCuts_ = value;
784    }
785    /** Return true if we want to do cuts
786        If allowForTopOfTree zero then just does on multiples of depth
787        if 1 then allows for doing at top of tree
788        if 2 then says if cuts allowed anywhere apart from root
789    */
790    bool doCutsNow(int allowForTopOfTree) const;
791
792    /** Set the number of branches before pseudo costs believed
793        in dynamic strong branching.
794
795      A value of 0 disables dynamic strong branching.
796    */
797    void setNumberBeforeTrust(int number);
798    /** get the number of branches before pseudo costs believed
799        in dynamic strong branching. */
800    inline int numberBeforeTrust() const {
801        return numberBeforeTrust_;
802    }
803    /** Set the number of variables for which to compute penalties
804        in dynamic strong branching.
805
806      A value of 0 disables penalties.
807    */
808    void setNumberPenalties(int number);
809    /** get the number of variables for which to compute penalties
810        in dynamic strong branching. */
811    inline int numberPenalties() const {
812        return numberPenalties_;
813    }
814    /// Number of analyze iterations to do
815    inline void setNumberAnalyzeIterations(int number) {
816        numberAnalyzeIterations_ = number;
817    }
818    inline int numberAnalyzeIterations() const {
819        return numberAnalyzeIterations_;
820    }
821    /** Get scale factor to make penalties match strong.
822        Should/will be computed */
823    inline double penaltyScaleFactor() const {
824        return penaltyScaleFactor_;
825    }
826    /** Set scale factor to make penalties match strong.
827        Should/will be computed */
828    void setPenaltyScaleFactor(double value);
829    /** Problem type as set by user or found by analysis.  This will be extended
830        0 - not known
831        1 - Set partitioning <=
832        2 - Set partitioning ==
833        3 - Set covering
834        4 - all +- 1 or all +1 and odd
835    */
836    void inline setProblemType(int number) {
837        problemType_ = number;
838    }
839    inline int problemType() const {
840        return problemType_;
841    }
842    /// Current depth
843    inline int currentDepth() const {
844        return currentDepth_;
845    }
846
847    /// Set how often to scan global cuts
848    void setHowOftenGlobalScan(int number);
849    /// Get how often to scan global cuts
850    inline int howOftenGlobalScan() const {
851        return howOftenGlobalScan_;
852    }
853    /// Original columns as created by integerPresolve or preprocessing
854    inline int * originalColumns() const {
855        return originalColumns_;
856    }
857    /// Set original columns as created by preprocessing
858    void setOriginalColumns(const int * originalColumns) ;
859
860    /** Set the print frequency.
861
862      Controls the number of nodes evaluated between status prints.
863      If <tt>number <=0</tt> the print frequency is set to 100 nodes for large
864      problems, 1000 for small problems.
865      Print frequency has very slight overhead if small.
866    */
867    inline void setPrintFrequency(int number) {
868        printFrequency_ = number;
869    }
870    /// Get the print frequency
871    inline int printFrequency() const {
872        return printFrequency_;
873    }
874    //@}
875
876    //---------------------------------------------------------------------------
877    ///@name Methods returning info on how the solution process terminated
878    //@{
879    /// Are there a numerical difficulties?
880    bool isAbandoned() const;
881    /// Is optimality proven?
882    bool isProvenOptimal() const;
883    /// Is  infeasiblity proven (or none better than cutoff)?
884    bool isProvenInfeasible() const;
885    /// Was continuous solution unbounded
886    bool isContinuousUnbounded() const;
887    /// Was continuous solution unbounded
888    bool isProvenDualInfeasible() const;
889    /// Node limit reached?
890    bool isNodeLimitReached() const;
891    /// Time limit reached?
892    bool isSecondsLimitReached() const;
893    /// Solution limit reached?
894    bool isSolutionLimitReached() const;
895    /// Get how many iterations it took to solve the problem.
896    inline int getIterationCount() const {
897        return numberIterations_;
898    }
899    /// Increment how many iterations it took to solve the problem.
900    inline void incrementIterationCount(int value) {
901        numberIterations_ += value;
902    }
903    /// Get how many Nodes it took to solve the problem.
904    inline int getNodeCount() const {
905        return numberNodes_;
906    }
907    /// Increment how many nodes it took to solve the problem.
908    inline void incrementNodeCount(int value) {
909        numberNodes_ += value;
910    }
911    /** Final status of problem
912        Some of these can be found out by is...... functions
913        -1 before branchAndBound
914        0 finished - check isProvenOptimal or isProvenInfeasible to see if solution found
915        (or check value of best solution)
916        1 stopped - on maxnodes, maxsols, maxtime
917        2 difficulties so run was abandoned
918        (5 event user programmed event occurred)
919    */
920    inline int status() const {
921        return status_;
922    }
923    inline void setProblemStatus(int value) {
924        status_ = value;
925    }
926    /** Secondary status of problem
927        -1 unset (status_ will also be -1)
928        0 search completed with solution
929        1 linear relaxation not feasible (or worse than cutoff)
930        2 stopped on gap
931        3 stopped on nodes
932        4 stopped on time
933        5 stopped on user event
934        6 stopped on solutions
935        7 linear relaxation unbounded
936    */
937    inline int secondaryStatus() const {
938        return secondaryStatus_;
939    }
940    inline void setSecondaryStatus(int value) {
941        secondaryStatus_ = value;
942    }
943    /// Are there numerical difficulties (for initialSolve) ?
944    bool isInitialSolveAbandoned() const ;
945    /// Is optimality proven (for initialSolve) ?
946    bool isInitialSolveProvenOptimal() const ;
947    /// Is primal infeasiblity proven (for initialSolve) ?
948    bool isInitialSolveProvenPrimalInfeasible() const ;
949    /// Is dual infeasiblity proven (for initialSolve) ?
950    bool isInitialSolveProvenDualInfeasible() const ;
951
952    //@}
953
954    //---------------------------------------------------------------------------
955    /**@name Problem information methods
956
957       These methods call the solver's query routines to return
958       information about the problem referred to by the current object.
959       Querying a problem that has no data associated with it result in
960       zeros for the number of rows and columns, and NULL pointers from
961       the methods that return vectors.
962
963       Const pointers returned from any data-query method are valid as
964       long as the data is unchanged and the solver is not called.
965    */
966    //@{
967    /// Number of rows in continuous (root) problem.
968    inline int numberRowsAtContinuous() const {
969        return numberRowsAtContinuous_;
970    }
971
972    /// Get number of columns
973    inline int getNumCols() const {
974        return solver_->getNumCols();
975    }
976
977    /// Get number of rows
978    inline int getNumRows() const {
979        return solver_->getNumRows();
980    }
981
982    /// Get number of nonzero elements
983    inline CoinBigIndex getNumElements() const {
984        return solver_->getNumElements();
985    }
986
987    /// Number of integers in problem
988    inline int numberIntegers() const {
989        return numberIntegers_;
990    }
991    // Integer variables
992    inline const int * integerVariable() const {
993        return integerVariable_;
994    }
995    /// Whether or not integer
996    inline char integerType(int i) const {
997        assert (integerInfo_);
998        assert (integerInfo_[i] == 0 || integerInfo_[i] == 1);
999        return integerInfo_[i];
1000    }
1001    /// Whether or not integer
1002    inline const char * integerType() const {
1003        return integerInfo_;
1004    }
1005
1006    /// Get pointer to array[getNumCols()] of column lower bounds
1007    inline const double * getColLower() const {
1008        return solver_->getColLower();
1009    }
1010
1011    /// Get pointer to array[getNumCols()] of column upper bounds
1012    inline const double * getColUpper() const {
1013        return solver_->getColUpper();
1014    }
1015
1016    /** Get pointer to array[getNumRows()] of row constraint senses.
1017        <ul>
1018        <li>'L': <= constraint
1019        <li>'E': =  constraint
1020        <li>'G': >= constraint
1021        <li>'R': ranged constraint
1022        <li>'N': free constraint
1023        </ul>
1024    */
1025    inline const char * getRowSense() const {
1026        return solver_->getRowSense();
1027    }
1028
1029    /** Get pointer to array[getNumRows()] of rows right-hand sides
1030        <ul>
1031        <li> if rowsense()[i] == 'L' then rhs()[i] == rowupper()[i]
1032        <li> if rowsense()[i] == 'G' then rhs()[i] == rowlower()[i]
1033        <li> if rowsense()[i] == 'R' then rhs()[i] == rowupper()[i]
1034        <li> if rowsense()[i] == 'N' then rhs()[i] == 0.0
1035        </ul>
1036    */
1037    inline const double * getRightHandSide() const {
1038        return solver_->getRightHandSide();
1039    }
1040
1041    /** Get pointer to array[getNumRows()] of row ranges.
1042        <ul>
1043        <li> if rowsense()[i] == 'R' then
1044        rowrange()[i] == rowupper()[i] - rowlower()[i]
1045        <li> if rowsense()[i] != 'R' then
1046        rowrange()[i] is 0.0
1047        </ul>
1048    */
1049    inline const double * getRowRange() const {
1050        return solver_->getRowRange();
1051    }
1052
1053    /// Get pointer to array[getNumRows()] of row lower bounds
1054    inline const double * getRowLower() const {
1055        return solver_->getRowLower();
1056    }
1057
1058    /// Get pointer to array[getNumRows()] of row upper bounds
1059    inline const double * getRowUpper() const {
1060        return solver_->getRowUpper();
1061    }
1062
1063    /// Get pointer to array[getNumCols()] of objective function coefficients
1064    inline const double * getObjCoefficients() const {
1065        return solver_->getObjCoefficients();
1066    }
1067
1068    /// Get objective function sense (1 for min (default), -1 for max)
1069    inline double getObjSense() const {
1070        //assert (dblParam_[CbcOptimizationDirection]== solver_->getObjSense());
1071        return dblParam_[CbcOptimizationDirection];
1072    }
1073
1074    /// Return true if variable is continuous
1075    inline bool isContinuous(int colIndex) const {
1076        return solver_->isContinuous(colIndex);
1077    }
1078
1079    /// Return true if variable is binary
1080    inline bool isBinary(int colIndex) const {
1081        return solver_->isBinary(colIndex);
1082    }
1083
1084    /** Return true if column is integer.
1085        Note: This function returns true if the the column
1086        is binary or a general integer.
1087    */
1088    inline bool isInteger(int colIndex) const {
1089        return solver_->isInteger(colIndex);
1090    }
1091
1092    /// Return true if variable is general integer
1093    inline bool isIntegerNonBinary(int colIndex) const {
1094        return solver_->isIntegerNonBinary(colIndex);
1095    }
1096
1097    /// Return true if variable is binary and not fixed at either bound
1098    inline bool isFreeBinary(int colIndex) const {
1099        return solver_->isFreeBinary(colIndex) ;
1100    }
1101
1102    /// Get pointer to row-wise copy of matrix
1103    inline const CoinPackedMatrix * getMatrixByRow() const {
1104        return solver_->getMatrixByRow();
1105    }
1106
1107    /// Get pointer to column-wise copy of matrix
1108    inline const CoinPackedMatrix * getMatrixByCol() const {
1109        return solver_->getMatrixByCol();
1110    }
1111
1112    /// Get solver's value for infinity
1113    inline double getInfinity() const {
1114        return solver_->getInfinity();
1115    }
1116    /// Get pointer to array[getNumCols()] (for speed) of column lower bounds
1117    inline const double * getCbcColLower() const {
1118        return cbcColLower_;
1119    }
1120    /// Get pointer to array[getNumCols()] (for speed) of column upper bounds
1121    inline const double * getCbcColUpper() const {
1122        return cbcColUpper_;
1123    }
1124    /// Get pointer to array[getNumRows()] (for speed) of row lower bounds
1125    inline const double * getCbcRowLower() const {
1126        return cbcRowLower_;
1127    }
1128    /// Get pointer to array[getNumRows()] (for speed) of row upper bounds
1129    inline const double * getCbcRowUpper() const {
1130        return cbcRowUpper_;
1131    }
1132    /// Get pointer to array[getNumCols()] (for speed) of primal solution vector
1133    inline const double * getCbcColSolution() const {
1134        return cbcColSolution_;
1135    }
1136    /// Get pointer to array[getNumRows()] (for speed) of dual prices
1137    inline const double * getCbcRowPrice() const {
1138        return cbcRowPrice_;
1139    }
1140    /// Get a pointer to array[getNumCols()] (for speed) of reduced costs
1141    inline const double * getCbcReducedCost() const {
1142        return cbcReducedCost_;
1143    }
1144    /// Get pointer to array[getNumRows()] (for speed) of row activity levels.
1145    inline const double * getCbcRowActivity() const {
1146        return cbcRowActivity_;
1147    }
1148    //@}
1149
1150
1151    /**@name Methods related to querying the solution */
1152    //@{
1153    /// Holds solution at continuous (after cuts if branchAndBound called)
1154    inline double * continuousSolution() const {
1155        return continuousSolution_;
1156    }
1157    /** Array marked whenever a solution is found if non-zero.
1158        Code marks if heuristic returns better so heuristic
1159        need only mark if it wants to on solutions which
1160        are worse than current */
1161    inline int * usedInSolution() const {
1162        return usedInSolution_;
1163    }
1164    /// Increases usedInSolution for nonzeros
1165    void incrementUsed(const double * solution);
1166    /// Record a new incumbent solution and update objectiveValue
1167    void setBestSolution(CBC_Message how,
1168                         double & objectiveValue, const double *solution,
1169                         int fixVariables = 0);
1170    /// Just update objectiveValue
1171    void setBestObjectiveValue( double objectiveValue);
1172    /// Deals with event handler and solution
1173    CbcEventHandler::CbcAction dealWithEventHandler(CbcEventHandler::CbcEvent event,
1174            double objValue,
1175            const double * solution);
1176
1177    /** Call this to really test if a valid solution can be feasible
1178        Solution is number columns in size.
1179        If fixVariables true then bounds of continuous solver updated.
1180        Returns objective value (worse than cutoff if not feasible)
1181        Previously computed objective value is now passed in (in case user does not do solve)
1182    */
1183    double checkSolution(double cutoff, double * solution,
1184                         int fixVariables, double originalObjValue);
1185    /** Test the current solution for feasiblility.
1186
1187      Scan all objects for indications of infeasibility. This is broken down
1188      into simple integer infeasibility (\p numberIntegerInfeasibilities)
1189      and all other reports of infeasibility (\p numberObjectInfeasibilities).
1190    */
1191    bool feasibleSolution(int & numberIntegerInfeasibilities,
1192                          int & numberObjectInfeasibilities) const;
1193
1194    /** Solution to the most recent lp relaxation.
1195
1196      The solver's solution to the most recent lp relaxation.
1197    */
1198
1199    inline double * currentSolution() const {
1200        return currentSolution_;
1201    }
1202    /** For testing infeasibilities - will point to
1203        currentSolution_ or solver-->getColSolution()
1204    */
1205    inline const double * testSolution() const {
1206        return testSolution_;
1207    }
1208    inline void setTestSolution(const double * solution) {
1209        testSolution_ = solution;
1210    }
1211    /// Make sure region there and optionally copy solution
1212    void reserveCurrentSolution(const double * solution = NULL);
1213
1214    /// Get pointer to array[getNumCols()] of primal solution vector
1215    inline const double * getColSolution() const {
1216        return solver_->getColSolution();
1217    }
1218
1219    /// Get pointer to array[getNumRows()] of dual prices
1220    inline const double * getRowPrice() const {
1221        return solver_->getRowPrice();
1222    }
1223
1224    /// Get a pointer to array[getNumCols()] of reduced costs
1225    inline const double * getReducedCost() const {
1226        return solver_->getReducedCost();
1227    }
1228
1229    /// Get pointer to array[getNumRows()] of row activity levels.
1230    inline const double * getRowActivity() const {
1231        return solver_->getRowActivity();
1232    }
1233
1234    /// Get current objective function value
1235    inline double getCurrentObjValue() const {
1236        return dblParam_[CbcCurrentObjectiveValue];
1237    }
1238    /// Get current minimization objective function value
1239    inline double getCurrentMinimizationObjValue() const {
1240        return dblParam_[CbcCurrentMinimizationObjectiveValue];
1241    }
1242
1243    /// Get best objective function value as minimization
1244    inline double getMinimizationObjValue() const {
1245        return bestObjective_;
1246    }
1247    /// Set best objective function value as minimization
1248    inline void setMinimizationObjValue(double value) {
1249        bestObjective_ = value;
1250    }
1251
1252    /// Get best objective function value
1253    inline double getObjValue() const {
1254        return bestObjective_ * solver_->getObjSense() ;
1255    }
1256    /** Get best possible objective function value.
1257        This is better of best possible left on tree
1258        and best solution found.
1259        If called from within branch and cut may be optimistic.
1260    */
1261    double getBestPossibleObjValue() const;
1262    /// Set best objective function value
1263    inline void setObjValue(double value) {
1264        bestObjective_ = value * solver_->getObjSense() ;
1265    }
1266    /// Get solver objective function value (as minimization)
1267    inline double getSolverObjValue() const {
1268        return solver_->getObjValue() * solver_->getObjSense() ;
1269    }
1270
1271    /** The best solution to the integer programming problem.
1272
1273      The best solution to the integer programming problem found during
1274      the search. If no solution is found, the method returns null.
1275    */
1276
1277    inline double * bestSolution() const {
1278        return bestSolution_;
1279    }
1280    /** User callable setBestSolution.
1281        If check false does not check valid
1282        If true then sees if feasible and warns if objective value
1283        worse than given (so just set to COIN_DBL_MAX if you don't care).
1284        If check true then does not save solution if not feasible
1285    */
1286    void setBestSolution(const double * solution, int numberColumns,
1287                         double objectiveValue, bool check = false);
1288
1289    /// Get number of solutions
1290    inline int getSolutionCount() const {
1291        return numberSolutions_;
1292    }
1293
1294    /// Set number of solutions (so heuristics will be different)
1295    inline void setSolutionCount(int value) {
1296        numberSolutions_ = value;
1297    }
1298    /// Number of saved solutions (including best)
1299    int numberSavedSolutions() const;
1300    /// Maximum number of extra saved solutions
1301    inline int maximumSavedSolutions() const {
1302        return maximumSavedSolutions_;
1303    }
1304    /// Set maximum number of extra saved solutions
1305    void setMaximumSavedSolutions(int value);
1306    /// Return a saved solution (0==best) - NULL if off end
1307    const double * savedSolution(int which) const;
1308    /// Return a saved solution objective (0==best) - COIN_DBL_MAX if off end
1309    double savedSolutionObjective(int which) const;
1310
1311    /** Current phase (so heuristics etc etc can find out).
1312        0 - initial solve
1313        1 - solve with cuts at root
1314        2 - solve with cuts
1315        3 - other e.g. strong branching
1316        4 - trying to validate a solution
1317        5 - at end of search
1318    */
1319    inline int phase() const {
1320        return phase_;
1321    }
1322
1323    /// Get number of heuristic solutions
1324    inline int getNumberHeuristicSolutions() const {
1325        return numberHeuristicSolutions_;
1326    }
1327    /// Set number of heuristic solutions
1328    inline void setNumberHeuristicSolutions(int value) {
1329        numberHeuristicSolutions_ = value;
1330    }
1331
1332    /// Set objective function sense (1 for min (default), -1 for max,)
1333    inline void setObjSense(double s) {
1334        dblParam_[CbcOptimizationDirection] = s;
1335        solver_->setObjSense(s);
1336    }
1337
1338    /// Value of objective at continuous
1339    inline double getContinuousObjective() const {
1340        return originalContinuousObjective_;
1341    }
1342    inline void setContinuousObjective(double value) {
1343        originalContinuousObjective_ = value;
1344    }
1345    /// Number of infeasibilities at continuous
1346    inline int getContinuousInfeasibilities() const {
1347        return continuousInfeasibilities_;
1348    }
1349    inline void setContinuousInfeasibilities(int value) {
1350        continuousInfeasibilities_ = value;
1351    }
1352    /// Value of objective after root node cuts added
1353    inline double rootObjectiveAfterCuts() const {
1354        return continuousObjective_;
1355    }
1356    /// Sum of Changes to objective by first solve
1357    inline double sumChangeObjective() const {
1358        return sumChangeObjective1_;
1359    }
1360    /** Number of times global cuts violated.  When global cut pool then this
1361        should be kept for each cut and type of cut */
1362    inline int numberGlobalViolations() const {
1363        return numberGlobalViolations_;
1364    }
1365    inline void clearNumberGlobalViolations() {
1366        numberGlobalViolations_ = 0;
1367    }
1368    /// Whether to force a resolve after takeOffCuts
1369    inline bool resolveAfterTakeOffCuts() const {
1370        return resolveAfterTakeOffCuts_;
1371    }
1372    inline void setResolveAfterTakeOffCuts(bool yesNo) {
1373        resolveAfterTakeOffCuts_ = yesNo;
1374    }
1375    /// Maximum number of rows
1376    inline int maximumRows() const {
1377        return maximumRows_;
1378    }
1379    /// Work basis for temporary use
1380    inline CoinWarmStartBasis & workingBasis() {
1381        return workingBasis_;
1382    }
1383    /// Get number of threads
1384    inline int getNumberThreads() const {
1385        return numberThreads_;
1386    }
1387    /// Set number of threads
1388    inline void setNumberThreads(int value) {
1389        numberThreads_ = value;
1390    }
1391    /// Get thread mode
1392    inline int getThreadMode() const {
1393        return threadMode_;
1394    }
1395    /** Set thread mode
1396        always use numberThreads for branching
1397        1 set then deterministic
1398        2 set then use numberThreads for root cuts
1399        4 set then use numberThreads in root mini branch and bound
1400        8 set and numberThreads - do heuristics numberThreads at a time
1401        8 set and numberThreads==0 do all heuristics at once
1402        default is 0
1403    */
1404    inline void setThreadMode(int value) {
1405        threadMode_ = value;
1406    }
1407    /** Return
1408        -2 if deterministic threaded and main thread
1409        -1 if deterministic threaded and serial thread
1410        0 if serial
1411        1 if opportunistic threaded
1412    */
1413    inline int parallelMode() const {
1414        if (!numberThreads_) {
1415            if ((threadMode_&1) == 0)
1416                return 0;
1417            else
1418                return -1;
1419            return 0;
1420        } else {
1421            if ((threadMode_&1) == 0)
1422                return 1;
1423            else
1424                return -2;
1425        }
1426    }
1427    /// Get number of "iterations" to stop after
1428    inline int getStopNumberIterations() const {
1429        return stopNumberIterations_;
1430    }
1431    /// Set number of "iterations" to stop after
1432    inline void setStopNumberIterations(int value) {
1433        stopNumberIterations_ = value;
1434    }
1435    //@}
1436
1437    /** \name Node selection */
1438    //@{
1439    // Comparison functions (which may be overridden by inheritance)
1440    inline CbcCompareBase * nodeComparison() const {
1441        return nodeCompare_;
1442    }
1443    void setNodeComparison(CbcCompareBase * compare);
1444    void setNodeComparison(CbcCompareBase & compare);
1445    //@}
1446
1447    /** \name Problem feasibility checking */
1448    //@{
1449    // Feasibility functions (which may be overridden by inheritance)
1450    inline CbcFeasibilityBase * problemFeasibility() const {
1451        return problemFeasibility_;
1452    }
1453    void setProblemFeasibility(CbcFeasibilityBase * feasibility);
1454    void setProblemFeasibility(CbcFeasibilityBase & feasibility);
1455    //@}
1456
1457    /** \name Tree methods and subtree methods */
1458    //@{
1459    /// Tree method e.g. heap (which may be overridden by inheritance)
1460    inline CbcTree * tree() const {
1461        return tree_;
1462    }
1463    /// For modifying tree handling (original is cloned)
1464    void passInTreeHandler(CbcTree & tree);
1465    /** For passing in an CbcModel to do a sub Tree (with derived tree handlers).
1466        Passed in model must exist for duration of branch and bound
1467    */
1468    void passInSubTreeModel(CbcModel & model);
1469    /** For retrieving a copy of subtree model with given OsiSolver.
1470        If no subtree model will use self (up to user to reset cutoff etc).
1471        If solver NULL uses current
1472    */
1473    CbcModel * subTreeModel(OsiSolverInterface * solver = NULL) const;
1474    /// Returns number of times any subtree stopped on nodes, time etc
1475    inline int numberStoppedSubTrees() const {
1476        return numberStoppedSubTrees_;
1477    }
1478    /// Says a sub tree was stopped
1479    inline void incrementSubTreeStopped() {
1480        numberStoppedSubTrees_++;
1481    }
1482    /** Whether to automatically do presolve before branch and bound (subTrees).
1483        0 - no
1484        1 - ordinary presolve
1485        2 - integer presolve (dodgy)
1486    */
1487    inline int typePresolve() const {
1488        return presolve_;
1489    }
1490    inline void setTypePresolve(int value) {
1491        presolve_ = value;
1492    }
1493
1494    //@}
1495
1496    /** \name Branching Decisions
1497
1498      See the CbcBranchDecision class for additional information.
1499    */
1500    //@{
1501
1502    /// Get the current branching decision method.
1503    inline CbcBranchDecision * branchingMethod() const {
1504        return branchingMethod_;
1505    }
1506    /// Set the branching decision method.
1507    inline void setBranchingMethod(CbcBranchDecision * method) {
1508        delete branchingMethod_;
1509        branchingMethod_ = method->clone();
1510    }
1511    /** Set the branching method
1512
1513      \overload
1514    */
1515    inline void setBranchingMethod(CbcBranchDecision & method) {
1516        delete branchingMethod_;
1517        branchingMethod_ = method.clone();
1518    }
1519    /// Get the current cut modifier method
1520    inline CbcCutModifier * cutModifier() const {
1521        return cutModifier_;
1522    }
1523    /// Set the cut modifier method
1524    void setCutModifier(CbcCutModifier * modifier);
1525    /** Set the cut modifier method
1526
1527      \overload
1528    */
1529    void setCutModifier(CbcCutModifier & modifier);
1530    //@}
1531
1532    /** \name Row (constraint) and Column (variable) cut generation */
1533    //@{
1534
1535    /** State of search
1536        0 - no solution
1537        1 - only heuristic solutions
1538        2 - branched to a solution
1539        3 - no solution but many nodes
1540    */
1541    inline int stateOfSearch() const {
1542        return stateOfSearch_;
1543    }
1544    inline void setStateOfSearch(int state) {
1545        stateOfSearch_ = state;
1546    }
1547    /// Strategy worked out - mainly at root node for use by CbcNode
1548    inline int searchStrategy() const {
1549        return searchStrategy_;
1550    }
1551    /// Set strategy worked out - mainly at root node for use by CbcNode
1552    inline void setSearchStrategy(int value) {
1553        searchStrategy_ = value;
1554    }
1555
1556    /// Get the number of cut generators
1557    inline int numberCutGenerators() const {
1558        return numberCutGenerators_;
1559    }
1560    /// Get the list of cut generators
1561    inline CbcCutGenerator ** cutGenerators() const {
1562        return generator_;
1563    }
1564    ///Get the specified cut generator
1565    inline CbcCutGenerator * cutGenerator(int i) const {
1566        return generator_[i];
1567    }
1568    ///Get the specified cut generator before any changes
1569    inline CbcCutGenerator * virginCutGenerator(int i) const {
1570        return virginGenerator_[i];
1571    }
1572    /** Add one generator - up to user to delete generators.
1573        howoften affects how generator is used. 0 or 1 means always,
1574        >1 means every that number of nodes.  Negative values have same
1575        meaning as positive but they may be switched off (-> -100) by code if
1576        not many cuts generated at continuous.  -99 is just done at root.
1577        Name is just for printout.
1578        If depth >0 overrides how often generator is called (if howOften==-1 or >0).
1579    */
1580    void addCutGenerator(CglCutGenerator * generator,
1581                         int howOften = 1, const char * name = NULL,
1582                         bool normal = true, bool atSolution = false,
1583                         bool infeasible = false, int howOftenInSub = -100,
1584                         int whatDepth = -1, int whatDepthInSub = -1);
1585//@}
1586    /** \name Strategy and sub models
1587
1588      See the CbcStrategy class for additional information.
1589    */
1590    //@{
1591
1592    /// Get the current strategy
1593    inline CbcStrategy * strategy() const {
1594        return strategy_;
1595    }
1596    /// Set the strategy. Clones
1597    void setStrategy(CbcStrategy & strategy);
1598    /// Get the current parent model
1599    inline CbcModel * parentModel() const {
1600        return parentModel_;
1601    }
1602    /// Set the parent model
1603    inline void setParentModel(CbcModel & parentModel) {
1604        parentModel_ = &parentModel;
1605    }
1606    //@}
1607
1608
1609    /** \name Heuristics and priorities */
1610    //@{
1611    /*! \brief Add one heuristic - up to user to delete
1612
1613      The name is just used for print messages.
1614    */
1615    void addHeuristic(CbcHeuristic * generator, const char *name = NULL,
1616                      int before = -1);
1617    ///Get the specified heuristic
1618    inline CbcHeuristic * heuristic(int i) const {
1619        return heuristic_[i];
1620    }
1621    /// Get the number of heuristics
1622    inline int numberHeuristics() const {
1623        return numberHeuristics_;
1624    }
1625    /// Pointer to heuristic solver which found last solution (or NULL)
1626    inline CbcHeuristic * lastHeuristic() const {
1627        return lastHeuristic_;
1628    }
1629    /// set last heuristic which found a solution
1630    inline void setLastHeuristic(CbcHeuristic * last) {
1631        lastHeuristic_ = last;
1632    }
1633
1634    /** Pass in branching priorities.
1635
1636        If ifClique then priorities are on cliques otherwise priorities are
1637        on integer variables.
1638        Other type (if exists set to default)
1639        1 is highest priority. (well actually -INT_MAX is but that's ugly)
1640        If hotstart > 0 then branches are created to force
1641        the variable to the value given by best solution.  This enables a
1642        sort of hot start.  The node choice should be greatest depth
1643        and hotstart should normally be switched off after a solution.
1644
1645        If ifNotSimpleIntegers true then appended to normal integers
1646
1647        This is now deprecated except for simple usage.  If user
1648        creates Cbcobjects then set priority in them
1649
1650        \internal Added for Kurt Spielberg.
1651    */
1652    void passInPriorities(const int * priorities, bool ifNotSimpleIntegers);
1653
1654    /// Returns priority level for an object (or 1000 if no priorities exist)
1655    inline int priority(int sequence) const {
1656        return object_[sequence]->priority();
1657    }
1658
1659    /*! \brief Set an event handler
1660
1661      A clone of the handler passed as a parameter is stored in CbcModel.
1662    */
1663    void passInEventHandler(const CbcEventHandler *eventHandler) ;
1664
1665    /*! \brief Retrieve a pointer to the event handler */
1666    inline CbcEventHandler* getEventHandler() const {
1667        return (eventHandler_) ;
1668    }
1669
1670    //@}
1671
1672    /**@name Setting/Accessing application data */
1673    //@{
1674    /** Set application data.
1675
1676    This is a pointer that the application can store into and
1677    retrieve from the solver interface.
1678    This field is available for the application to optionally
1679    define and use.
1680    */
1681    void setApplicationData (void * appData);
1682
1683    /// Get application data
1684    void * getApplicationData() const;
1685    /**
1686        For advanced applications you may wish to modify the behavior of Cbc
1687        e.g. if the solver is a NLP solver then you may not have an exact
1688        optimum solution at each step.  Information could be built into
1689        OsiSolverInterface but this is an alternative so that that interface
1690        does not have to be changed.  If something similar is useful to
1691        enough solvers then it could be migrated
1692        You can also pass in by using solver->setAuxiliaryInfo.
1693        You should do that if solver is odd - if solver is normal simplex
1694        then use this.
1695        NOTE - characteristics are not cloned
1696    */
1697    void passInSolverCharacteristics(OsiBabSolver * solverCharacteristics);
1698    /// Get solver characteristics
1699    inline const OsiBabSolver * solverCharacteristics() const {
1700        return solverCharacteristics_;
1701    }
1702    //@}
1703
1704    //---------------------------------------------------------------------------
1705
1706    /**@name Message handling */
1707    //@{
1708    /// Pass in Message handler (not deleted at end)
1709    void passInMessageHandler(CoinMessageHandler * handler);
1710    /// Set language
1711    void newLanguage(CoinMessages::Language language);
1712    inline void setLanguage(CoinMessages::Language language) {
1713        newLanguage(language);
1714    }
1715    /// Return handler
1716    inline CoinMessageHandler * messageHandler() const {
1717        return handler_;
1718    }
1719    /// Return messages
1720    inline CoinMessages & messages() {
1721        return messages_;
1722    }
1723    /// Return pointer to messages
1724    inline CoinMessages * messagesPointer() {
1725        return &messages_;
1726    }
1727    /// Set log level
1728    void setLogLevel(int value);
1729    /// Get log level
1730    inline int logLevel() const {
1731        return handler_->logLevel();
1732    }
1733    //@}
1734    //---------------------------------------------------------------------------
1735    ///@name Specialized
1736    //@{
1737
1738    /**
1739        Set special options
1740        0 bit (1) - check if cuts valid (if on debugger list)
1741        1 bit (2) - use current basis to check integer solution (rather than all slack)
1742        2 bit (4) - don't check integer solution (by solving LP)
1743        3 bit (8) - fast analyze
1744        4 bit (16) - non-linear model - so no well defined CoinPackedMatrix
1745        5 bit (32) - keep names
1746        6 bit (64) - try for dominated columns
1747        7 bit (128) - SOS type 1 but all declared integer
1748        8 bit (256) - Set to say solution just found, unset by doing cuts
1749        9 bit (512) - Try reduced model after 100 nodes
1750        10 bit (1024) - Switch on some heuristics even if seems unlikely
1751        11 bit (2048) - Mark as in small branch and bound
1752        12 bit (4096) - Funny cuts so do slow way (in some places)
1753        13 bit (8192) - Funny cuts so do slow way (in other places)
1754        14 bit (16384) - Use Cplex! for fathoming
1755        15 bit (32768) - Try reduced model after 0 nodes
1756        16 bit (65536) - Original model had integer bounds
1757        17 bit (131072) - Perturbation switched off
1758    */
1759    inline void setSpecialOptions(int value) {
1760        specialOptions_ = value;
1761    }
1762    /// Get special options
1763    inline int specialOptions() const {
1764        return specialOptions_;
1765    }
1766    /// Says if normal solver i.e. has well defined CoinPackedMatrix
1767    inline bool normalSolver() const {
1768        return (specialOptions_&16) == 0;
1769    }
1770    /** Set more special options
1771        at present bottom 6 bits used for shadow price mode
1772        1024 for experimental hotstart
1773        2048,4096 breaking out of cuts
1774        8192 slowly increase minimum drop
1775        16384 gomory
1776    */
1777    inline void setMoreSpecialOptions(int value) {
1778        moreSpecialOptions_ = value;
1779    }
1780    /// Get more special options
1781    inline int moreSpecialOptions() const {
1782        return moreSpecialOptions_;
1783    }
1784    /// Now we may not own objects - just point to solver's objects
1785    inline bool ownObjects() const {
1786        return ownObjects_;
1787    }
1788    /// Check original model before it gets messed up
1789    void checkModel();
1790    /// Pointer to a mutex
1791    inline void * mutex() {
1792        return mutex_;
1793    }
1794    /// Split up nodes
1795    int splitModel(int numberModels, CbcModel ** model,
1796                   int numberNodes);
1797    /// Start threads
1798    void startSplitModel(int numberIterations);
1799    /// Merge models
1800    void mergeModels(int numberModel, CbcModel ** model,
1801                     int numberNodes);
1802    //@}
1803    //---------------------------------------------------------------------------
1804
1805    ///@name Constructors and destructors etc
1806    //@{
1807    /// Default Constructor
1808    CbcModel();
1809
1810    /// Constructor from solver
1811    CbcModel(const OsiSolverInterface &);
1812
1813    /** Assign a solver to the model (model assumes ownership)
1814
1815      On return, \p solver will be NULL.
1816      If deleteSolver then current solver deleted (if model owned)
1817
1818      \note Parameter settings in the outgoing solver are not inherited by
1819        the incoming solver.
1820    */
1821    void assignSolver(OsiSolverInterface *&solver, bool deleteSolver = true);
1822
1823    /** \brief Set ownership of solver
1824
1825      A parameter of false tells CbcModel it does not own the solver and
1826      should not delete it. Once you claim ownership of the solver, you're
1827      responsible for eventually deleting it. Note that CbcModel clones
1828      solvers with abandon.  Unless you have a deep understanding of the
1829      workings of CbcModel, the only time you want to claim ownership is when
1830      you're about to delete the CbcModel object but want the solver to
1831      continue to exist (as, for example, when branchAndBound has finished
1832      and you want to hang on to the answer).
1833    */
1834    inline void setModelOwnsSolver (bool ourSolver) {
1835        ownership_ = ourSolver ? (ownership_ | 0x80000000) : (ownership_ & (~0x80000000)) ;
1836    }
1837
1838    /*! \brief Get ownership of solver
1839
1840      A return value of true means that CbcModel owns the solver and will
1841      take responsibility for deleting it when that becomes necessary.
1842    */
1843    inline bool modelOwnsSolver () {
1844        return ((ownership_&0x80000000) != 0) ;
1845    }
1846
1847    /** Copy constructor .
1848      If cloneHandler is true then message handler is cloned
1849    */
1850    CbcModel(const CbcModel & rhs, bool cloneHandler = false);
1851
1852    /// Assignment operator
1853    CbcModel & operator=(const CbcModel& rhs);
1854
1855    /// Destructor
1856    ~CbcModel ();
1857
1858    /// Returns solver - has current state
1859    inline OsiSolverInterface * solver() const {
1860        return solver_;
1861    }
1862
1863    /// Returns current solver - sets new one
1864    inline OsiSolverInterface * swapSolver(OsiSolverInterface * solver) {
1865        OsiSolverInterface * returnSolver = solver_;
1866        solver_ = solver;
1867        return returnSolver;
1868    }
1869
1870    /// Returns solver with continuous state
1871    inline OsiSolverInterface * continuousSolver() const {
1872        return continuousSolver_;
1873    }
1874
1875    /// Create solver with continuous state
1876    inline void createContinuousSolver() {
1877        continuousSolver_ = solver_->clone();
1878    }
1879    /// Clear solver with continuous state
1880    inline void clearContinuousSolver() {
1881        delete continuousSolver_;
1882        continuousSolver_ = NULL;
1883    }
1884
1885    /// A copy of the solver, taken at constructor or by saveReferenceSolver
1886    inline OsiSolverInterface * referenceSolver() const {
1887        return referenceSolver_;
1888    }
1889
1890    /// Save a copy of the current solver so can be reset to
1891    void saveReferenceSolver();
1892
1893    /** Uses a copy of reference solver to be current solver.
1894        Because of possible mismatches all exotic integer information is loat
1895        (apart from normal information in OsiSolverInterface)
1896        so SOS etc and priorities will have to be redone
1897    */
1898    void resetToReferenceSolver();
1899
1900    /// Clears out as much as possible (except solver)
1901    void gutsOfDestructor();
1902    /** Clears out enough to reset CbcModel as if no branch and bound done
1903     */
1904    void gutsOfDestructor2();
1905    /** Clears out enough to reset CbcModel cutoff etc
1906     */
1907    void resetModel();
1908    /** Most of copy constructor
1909        mode - 0 copy but don't delete before
1910               1 copy and delete before
1911           2 copy and delete before (but use virgin generators)
1912    */
1913    void gutsOfCopy(const CbcModel & rhs, int mode = 0);
1914    /// Move status, nodes etc etc across
1915    void moveInfo(const CbcModel & rhs);
1916    //@}
1917
1918    /// semi-private i.e. users should not use
1919    //@{
1920    /// Get how many Nodes it took to solve the problem.
1921    int getNodeCount2() const {
1922        return numberNodes2_;
1923    }
1924    /// Set pointers for speed
1925    void setPointers(const OsiSolverInterface * solver);
1926    /** Perform reduced cost fixing
1927
1928      Fixes integer variables at their current value based on reduced cost
1929      penalties.  Returns number fixed
1930    */
1931    int reducedCostFix() ;
1932    /** Makes all handlers same.  If makeDefault 1 then makes top level
1933        default and rest point to that.  If 2 then each is copy
1934    */
1935    void synchronizeHandlers(int makeDefault);
1936    /// Save a solution to saved list
1937    void saveExtraSolution(const double * solution, double objectiveValue);
1938    /// Save a solution to best and move current to saved
1939    void saveBestSolution(const double * solution, double objectiveValue);
1940    /// Delete best and saved solutions
1941    void deleteSolutions();
1942    /// Encapsulates solver resolve
1943    int resolve(OsiSolverInterface * solver);
1944
1945    /** Encapsulates choosing a variable -
1946        anyAction -2, infeasible (-1 round again), 0 done
1947    */
1948    int chooseBranch(CbcNode * & newNode, int numberPassesLeft,
1949                     CbcNode * oldNode, OsiCuts & cuts,
1950                     bool & resolved, CoinWarmStartBasis *lastws,
1951                     const double * lowerBefore, const double * upperBefore,
1952                     OsiSolverBranch * & branches);
1953    int chooseBranch(CbcNode * newNode, int numberPassesLeft, bool & resolved);
1954
1955    /** Return an empty basis object of the specified size
1956
1957      A useful utility when constructing a basis for a subproblem from scratch.
1958      The object returned will be of the requested capacity and appropriate for
1959      the solver attached to the model.
1960    */
1961    CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
1962
1963    /** Remove inactive cuts from the model
1964
1965      An OsiSolverInterface is expected to maintain a valid basis, but not a
1966      valid solution, when loose cuts are deleted. Restoring a valid solution
1967      requires calling the solver to reoptimise. If it's certain the solution
1968      will not be required, set allowResolve to false to suppress
1969      reoptimisation.
1970      If saveCuts then slack cuts will be saved
1971      On input current cuts are cuts and newCuts
1972      on exit current cuts will be correct.  Returns number dropped
1973    */
1974    int takeOffCuts(OsiCuts &cuts,
1975                    bool allowResolve, OsiCuts * saveCuts,
1976                    int numberNewCuts = 0, const OsiRowCut ** newCuts = NULL) ;
1977
1978    /** Determine and install the active cuts that need to be added for
1979      the current subproblem
1980
1981      The whole truth is a bit more complicated. The first action is a call to
1982      addCuts1(). addCuts() then sorts through the list, installs the tight
1983      cuts in the model, and does bookkeeping (adjusts reference counts).
1984      The basis returned from addCuts1() is adjusted accordingly.
1985
1986      If it turns out that the node should really be fathomed by bound,
1987      addCuts() simply treats all the cuts as loose as it does the bookkeeping.
1988
1989      canFix true if extra information being passed
1990    */
1991    int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws, bool canFix);
1992
1993    /** Traverse the tree from node to root and prep the model
1994
1995      addCuts1() begins the job of prepping the model to match the current
1996      subproblem. The model is stripped of all cuts, and the search tree is
1997      traversed from node to root to determine the changes required. Appropriate
1998      bounds changes are installed, a list of cuts is collected but not
1999      installed, and an appropriate basis (minus the cuts, but big enough to
2000      accommodate them) is constructed.
2001
2002      Returns true if new problem similar to old
2003
2004      \todo addCuts1() is called in contexts where it's known in advance that
2005        all that's desired is to determine a list of cuts and do the
2006        bookkeeping (adjust the reference counts). The work of installing
2007        bounds and building a basis goes to waste.
2008    */
2009    bool addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
2010    /** Returns bounds just before where - initially original bounds.
2011        Also sets downstream nodes (lower if force 1, upper if 2)
2012    */
2013    void previousBounds (CbcNode * node, CbcNodeInfo * where, int iColumn,
2014                         double & lower, double & upper, int force);
2015    /** Set objective value in a node.  This is separated out so that
2016       odd solvers can use.  It may look at extra information in
2017       solverCharacteriscs_ and will also use bound from parent node
2018    */
2019    void setObjectiveValue(CbcNode * thisNode, const CbcNode * parentNode) const;
2020
2021    /** If numberBeforeTrust >0 then we are going to use CbcBranchDynamic.
2022        Scan and convert CbcSimpleInteger objects
2023    */
2024    void convertToDynamic();
2025    /// Set numberBeforeTrust in all objects
2026    void synchronizeNumberBeforeTrust(int type = 0);
2027    /// Zap integer information in problem (may leave object info)
2028    void zapIntegerInformation(bool leaveObjects = true);
2029    /// Use cliques for pseudocost information - return nonzero if infeasible
2030    int cliquePseudoCosts(int doStatistics);
2031    /// Fill in useful estimates
2032    void pseudoShadow(int type);
2033    /** Return pseudo costs
2034        If not all integers or not pseudo costs - returns all zero
2035        Length of arrays are numberIntegers() and entries
2036        correspond to integerVariable()[i]
2037        User must allocate arrays before call
2038    */
2039    void fillPseudoCosts(double * downCosts, double * upCosts,
2040                         int * priority = NULL,
2041                         int * numberDown = NULL, int * numberUp = NULL,
2042                         int * numberDownInfeasible = NULL,
2043                         int * numberUpInfeasible = NULL) const;
2044    /** Do heuristics at root.
2045        0 - don't delete
2046        1 - delete
2047        2 - just delete - don't even use
2048    */
2049    void doHeuristicsAtRoot(int deleteHeuristicsAfterwards = 0);
2050    /// Adjust heuristics based on model
2051    void adjustHeuristics();
2052    /// Get the hotstart solution
2053    inline const double * hotstartSolution() const {
2054        return hotstartSolution_;
2055    }
2056    /// Get the hotstart priorities
2057    inline const int * hotstartPriorities() const {
2058        return hotstartPriorities_;
2059    }
2060
2061    /// Return the list of cuts initially collected for this subproblem
2062    inline CbcCountRowCut ** addedCuts() const {
2063        return addedCuts_;
2064    }
2065    /// Number of entries in the list returned by #addedCuts()
2066    inline int currentNumberCuts() const {
2067        return currentNumberCuts_;
2068    }
2069    /// Global cuts
2070    inline OsiCuts * globalCuts() {
2071        return &globalCuts_;
2072    }
2073    /// Copy and set a pointer to a row cut which will be added instead of normal branching.
2074    void setNextRowCut(const OsiRowCut & cut);
2075    /// Get a pointer to current node (be careful)
2076    inline CbcNode * currentNode() const {
2077        return currentNode_;
2078    }
2079    /// Get a pointer to probing info
2080    inline CglTreeProbingInfo * probingInfo() const {
2081        return probingInfo_;
2082    }
2083    /// Thread specific random number generator
2084    inline CoinThreadRandom * randomNumberGenerator() {
2085        return &randomNumberGenerator_;
2086    }
2087    /// Set the number of iterations done in strong branching.
2088    inline void setNumberStrongIterations(int number) {
2089        numberStrongIterations_ = number;
2090    }
2091    /// Get the number of iterations done in strong branching.
2092    inline int numberStrongIterations() const {
2093        return numberStrongIterations_;
2094    }
2095    /// Get maximum number of iterations (designed to be used in heuristics)
2096    inline int maximumNumberIterations() const {
2097        return maximumNumberIterations_;
2098    }
2099    /// Set maximum number of iterations (designed to be used in heuristics)
2100    inline void setMaximumNumberIterations(int value) {
2101        maximumNumberIterations_ = value;
2102    }
2103# ifdef COIN_HAS_CLP
2104    /// Set depth for fast nodes
2105    inline void setFastNodeDepth(int value) {
2106        fastNodeDepth_ = value;
2107    }
2108    /// Get depth for fast nodes
2109    inline int fastNodeDepth() const {
2110        return fastNodeDepth_;
2111    }
2112    /// Get anything with priority >= this can be treated as continuous
2113    inline int continuousPriority() const {
2114        return continuousPriority_;
2115    }
2116    /// Set anything with priority >= this can be treated as continuous
2117    inline void setContinuousPriority(int value) {
2118        continuousPriority_ = value;
2119    }
2120    inline void incrementExtra(int nodes, int iterations) {
2121        numberExtraNodes_ += nodes;
2122        numberExtraIterations_ += iterations;
2123    }
2124#endif
2125    /// Number of extra iterations
2126    inline int numberExtraIterations() const {
2127        return numberExtraIterations_;
2128    }
2129    /// Increment strong info
2130    void incrementStrongInfo(int numberTimes, int numberIterations,
2131                             int numberFixed, bool ifInfeasible);
2132    /// Return strong info
2133    inline const int * strongInfo() const {
2134        return strongInfo_;
2135    }
2136
2137    /// Return mutable strong info
2138    inline int * mutableStrongInfo() {
2139        return strongInfo_;
2140    }
2141    /// Get stored row cuts for donor/recipient CbcModel
2142    CglStored * storedRowCuts() const {
2143        return storedRowCuts_;
2144    }
2145    /// Set stored row cuts for donor/recipient CbcModel
2146    void setStoredRowCuts(CglStored * cuts) {
2147        storedRowCuts_ = cuts;
2148    }
2149    /// Says whether all dynamic integers
2150    inline bool allDynamic () const {
2151        return ((ownership_&0x40000000) != 0) ;
2152    }
2153    /// Create C++ lines to get to current state
2154    void generateCpp( FILE * fp, int options);
2155    /// Generate an OsiBranchingInformation object
2156    OsiBranchingInformation usefulInformation() const;
2157    /** Warm start object produced by heuristic or strong branching
2158
2159        If get a valid integer solution outside branch and bound then it can take
2160        a reasonable time to solve LP which produces clean solution.  If this object has
2161        any size then it will be used in solve.
2162    */
2163    inline void setBestSolutionBasis(const CoinWarmStartBasis & bestSolutionBasis) {
2164        bestSolutionBasis_ = bestSolutionBasis;
2165    }
2166    /// Redo walkback arrays
2167    void redoWalkBack();
2168    //@}
2169
2170//---------------------------------------------------------------------------
2171
2172private:
2173    ///@name Private member data
2174    //@{
2175
2176    /// The solver associated with this model.
2177    OsiSolverInterface * solver_;
2178
2179    /** Ownership of objects and other stuff
2180
2181        0x80000000 model owns solver
2182        0x40000000 all variables CbcDynamicPseudoCost
2183    */
2184    unsigned int ownership_ ;
2185
2186    /// A copy of the solver, taken at the continuous (root) node.
2187    OsiSolverInterface * continuousSolver_;
2188
2189    /// A copy of the solver, taken at constructor or by saveReferenceSolver
2190    OsiSolverInterface * referenceSolver_;
2191
2192    /// Message handler
2193    CoinMessageHandler * handler_;
2194
2195    /** Flag to say if handler_ is the default handler.
2196
2197      The default handler is deleted when the model is deleted. Other
2198      handlers (supplied by the client) will not be deleted.
2199    */
2200    bool defaultHandler_;
2201
2202    /// Cbc messages
2203    CoinMessages messages_;
2204
2205    /// Array for integer parameters
2206    int intParam_[CbcLastIntParam];
2207
2208    /// Array for double parameters
2209    double dblParam_[CbcLastDblParam];
2210
2211    /** Pointer to an empty warm start object
2212
2213      It turns out to be useful to have this available as a base from
2214      which to build custom warm start objects. This is typed as CoinWarmStart
2215      rather than CoinWarmStartBasis to allow for the possibility that a
2216      client might want to apply a solver that doesn't use a basis-based warm
2217      start. See getEmptyBasis for an example of how this field can be used.
2218    */
2219    mutable CoinWarmStart *emptyWarmStart_ ;
2220
2221    /// Best objective
2222    double bestObjective_;
2223    /// Best possible objective
2224    double bestPossibleObjective_;
2225    /// Sum of Changes to objective by first solve
2226    double sumChangeObjective1_;
2227    /// Sum of Changes to objective by subsequent solves
2228    double sumChangeObjective2_;
2229
2230    /// Array holding the incumbent (best) solution.
2231    double * bestSolution_;
2232    /// Arrays holding other solutions.
2233    double ** savedSolutions_;
2234
2235    /** Array holding the current solution.
2236
2237      This array is used more as a temporary.
2238    */
2239    double * currentSolution_;
2240    /** For testing infeasibilities - will point to
2241        currentSolution_ or solver-->getColSolution()
2242    */
2243    mutable const double * testSolution_;
2244    /** Warm start object produced by heuristic or strong branching
2245
2246        If get a valid integer solution outside branch and bound then it can take
2247        a reasonable time to solve LP which produces clean solution.  If this object has
2248        any size then it will be used in solve.
2249    */
2250    CoinWarmStartBasis bestSolutionBasis_ ;
2251    /// Global cuts
2252    OsiCuts globalCuts_;
2253
2254    /// Minimum degradation in objective value to continue cut generation
2255    double minimumDrop_;
2256    /// Number of solutions
2257    int numberSolutions_;
2258    /// Number of saved solutions
2259    int numberSavedSolutions_;
2260    /// Maximum number of saved solutions
2261    int maximumSavedSolutions_;
2262    /** State of search
2263        0 - no solution
2264        1 - only heuristic solutions
2265        2 - branched to a solution
2266        3 - no solution but many nodes
2267    */
2268    int stateOfSearch_;
2269    /// At which depths to do cuts
2270    int whenCuts_;
2271    /// Hotstart solution
2272    double * hotstartSolution_;
2273    /// Hotstart priorities
2274    int * hotstartPriorities_;
2275    /// Number of heuristic solutions
2276    int numberHeuristicSolutions_;
2277    /// Cumulative number of nodes
2278    int numberNodes_;
2279    /** Cumulative number of nodes for statistics.
2280        Must fix to match up
2281    */
2282    int numberNodes2_;
2283    /// Cumulative number of iterations
2284    int numberIterations_;
2285    /// Cumulative number of solves
2286    int numberSolves_;
2287    /// Status of problem - 0 finished, 1 stopped, 2 difficulties
2288    int status_;
2289    /** Secondary status of problem
2290        -1 unset (status_ will also be -1)
2291        0 search completed with solution
2292        1 linear relaxation not feasible (or worse than cutoff)
2293        2 stopped on gap
2294        3 stopped on nodes
2295        4 stopped on time
2296        5 stopped on user event
2297        6 stopped on solutions
2298     */
2299    int secondaryStatus_;
2300    /// Number of integers in problem
2301    int numberIntegers_;
2302    /// Number of rows at continuous
2303    int numberRowsAtContinuous_;
2304    /// Maximum number of cuts
2305    int maximumNumberCuts_;
2306    /** Current phase (so heuristics etc etc can find out).
2307        0 - initial solve
2308        1 - solve with cuts at root
2309        2 - solve with cuts
2310        3 - other e.g. strong branching
2311        4 - trying to validate a solution
2312        5 - at end of search
2313    */
2314    int phase_;
2315
2316    /// Number of entries in #addedCuts_
2317    int currentNumberCuts_;
2318
2319    /** Current limit on search tree depth
2320
2321      The allocated size of #walkback_. Increased as needed.
2322    */
2323    int maximumDepth_;
2324    /** Array used to assemble the path between a node and the search tree root
2325
2326      The array is resized when necessary. #maximumDepth_  is the current
2327      allocated size.
2328    */
2329    CbcNodeInfo ** walkback_;
2330    CbcNodeInfo ** lastNodeInfo_;
2331    const OsiRowCut ** lastCut_;
2332    int lastDepth_;
2333    int lastNumberCuts2_;
2334    int maximumCuts_;
2335    int * lastNumberCuts_;
2336
2337    /** The list of cuts initially collected for this subproblem
2338
2339      When the subproblem at this node is rebuilt, a set of cuts is collected
2340      for inclusion in the constraint system. If any of these cuts are
2341      subsequently removed because they have become loose, the corresponding
2342      entry is set to NULL.
2343    */
2344    CbcCountRowCut ** addedCuts_;
2345
2346    /** A pointer to a row cut which will be added instead of normal branching.
2347        After use it should be set to NULL.
2348    */
2349    OsiRowCut * nextRowCut_;
2350
2351    /// Current node so can be used elsewhere
2352    CbcNode * currentNode_;
2353
2354    /// Indices of integer variables
2355    int * integerVariable_;
2356    /// Whether of not integer
2357    char * integerInfo_;
2358    /// Holds solution at continuous (after cuts)
2359    double * continuousSolution_;
2360    /// Array marked whenever a solution is found if non-zero
2361    int * usedInSolution_;
2362    /**
2363        Special options
2364        0 bit (1) - check if cuts valid (if on debugger list)
2365        1 bit (2) - use current basis to check integer solution (rather than all slack)
2366        2 bit (4) - don't check integer solution (by solving LP)
2367        3 bit (8) - fast analyze
2368        4 bit (16) - non-linear model - so no well defined CoinPackedMatrix
2369        5 bit (32) - keep names
2370        6 bit (64) - try for dominated columns
2371        7 bit (128) - SOS type 1 but all declared integer
2372        8 bit (256) - Set to say solution just found, unset by doing cuts
2373        9 bit (512) - Try reduced model after 100 nodes
2374        10 bit (1024) - Switch on some heuristics even if seems unlikely
2375        11 bit (2048) - Mark as in small branch and bound
2376        12 bit (4096) - Funny cuts so do slow way (in some places)
2377        13 bit (8192) - Funny cuts so do slow way (in other places)
2378        14 bit (16384) - Use Cplex! for fathoming
2379        15 bit (32768) - Try reduced model after 0 nodes
2380        16 bit (65536) - Original model had integer bounds
2381        17 bit (131072) - Perturbation switched off
2382        18 bit (262144) - donor CbcModel
2383        19 bit (524288) - recipient CbcModel
2384    */
2385    int specialOptions_;
2386    /** More special options
2387        at present bottom 3 bits used for shadow price mode
2388    */
2389    int moreSpecialOptions_;
2390    /// User node comparison function
2391    CbcCompareBase * nodeCompare_;
2392    /// User feasibility function (see CbcFeasibleBase.hpp)
2393    CbcFeasibilityBase * problemFeasibility_;
2394    /// Tree
2395    CbcTree * tree_;
2396    /// A pointer to model to be used for subtrees
2397    CbcModel * subTreeModel_;
2398    /// Number of times any subtree stopped on nodes, time etc
2399    int numberStoppedSubTrees_;
2400    /// Variable selection function
2401    CbcBranchDecision * branchingMethod_;
2402    /// Cut modifier function
2403    CbcCutModifier * cutModifier_;
2404    /// Strategy
2405    CbcStrategy * strategy_;
2406    /// Parent model
2407    CbcModel * parentModel_;
2408    /** Whether to automatically do presolve before branch and bound.
2409        0 - no
2410        1 - ordinary presolve
2411        2 - integer presolve (dodgy)
2412    */
2413    /// Pointer to array[getNumCols()] (for speed) of column lower bounds
2414    const double * cbcColLower_;
2415    /// Pointer to array[getNumCols()] (for speed) of column upper bounds
2416    const double * cbcColUpper_;
2417    /// Pointer to array[getNumRows()] (for speed) of row lower bounds
2418    const double * cbcRowLower_;
2419    /// Pointer to array[getNumRows()] (for speed) of row upper bounds
2420    const double * cbcRowUpper_;
2421    /// Pointer to array[getNumCols()] (for speed) of primal solution vector
2422    const double * cbcColSolution_;
2423    /// Pointer to array[getNumRows()] (for speed) of dual prices
2424    const double * cbcRowPrice_;
2425    /// Get a pointer to array[getNumCols()] (for speed) of reduced costs
2426    const double * cbcReducedCost_;
2427    /// Pointer to array[getNumRows()] (for speed) of row activity levels.
2428    const double * cbcRowActivity_;
2429    /// Pointer to user-defined data structure
2430    void * appData_;
2431    /// Pointer to a mutex
2432    void * mutex_;
2433    /// Presolve for CbcTreeLocal
2434    int presolve_;
2435    /** Maximum number of candidates to consider for strong branching.
2436      To disable strong branching, set this to 0.
2437    */
2438    int numberStrong_;
2439    /** \brief The number of branches before pseudo costs believed
2440           in dynamic strong branching.
2441
2442      A value of 0 is  off.
2443    */
2444    int numberBeforeTrust_;
2445    /** \brief The number of variables for which to compute penalties
2446           in dynamic strong branching.
2447    */
2448    int numberPenalties_;
2449    /// For threads - stop after this many "iterations"
2450    int stopNumberIterations_;
2451    /** Scale factor to make penalties match strong.
2452        Should/will be computed */
2453    double penaltyScaleFactor_;
2454    /// Number of analyze iterations to do
2455    int numberAnalyzeIterations_;
2456    /// Arrays with analysis results
2457    double * analyzeResults_;
2458    /// Number of nodes infeasible by normal branching (before cuts)
2459    int numberInfeasibleNodes_;
2460    /** Problem type as set by user or found by analysis.  This will be extended
2461        0 - not known
2462        1 - Set partitioning <=
2463        2 - Set partitioning ==
2464        3 - Set covering
2465    */
2466    int problemType_;
2467    /// Print frequency
2468    int printFrequency_;
2469    /// Number of cut generators
2470    int numberCutGenerators_;
2471    // Cut generators
2472    CbcCutGenerator ** generator_;
2473    // Cut generators before any changes
2474    CbcCutGenerator ** virginGenerator_;
2475    /// Number of heuristics
2476    int numberHeuristics_;
2477    /// Heuristic solvers
2478    CbcHeuristic ** heuristic_;
2479    /// Pointer to heuristic solver which found last solution (or NULL)
2480    CbcHeuristic * lastHeuristic_;
2481# ifdef COIN_HAS_CLP
2482    /// Depth for fast nodes
2483    int fastNodeDepth_;
2484#endif
2485    /*! Pointer to the event handler */
2486# ifdef CBC_ONLY_CLP
2487    ClpEventHandler *eventHandler_ ;
2488# else
2489    CbcEventHandler *eventHandler_ ;
2490# endif
2491
2492    /// Total number of objects
2493    int numberObjects_;
2494
2495    /** \brief Integer and Clique and ... information
2496
2497      \note The code assumes that the first objects on the list will be
2498        SimpleInteger objects for each integer variable, followed by
2499        Clique objects. Portions of the code that understand Clique objects
2500        will fail if they do not immediately follow the SimpleIntegers.
2501        Large chunks of the code will fail if the first objects are not
2502        SimpleInteger. As of 2003.08, SimpleIntegers and Cliques are the only
2503        objects.
2504    */
2505    OsiObject ** object_;
2506    /// Now we may not own objects - just point to solver's objects
2507    bool ownObjects_;
2508
2509    /// Original columns as created by integerPresolve or preprocessing
2510    int * originalColumns_;
2511    /// How often to scan global cuts
2512    int howOftenGlobalScan_;
2513    /** Number of times global cuts violated.  When global cut pool then this
2514        should be kept for each cut and type of cut */
2515    int numberGlobalViolations_;
2516    /// Number of extra iterations in fast lp
2517    int numberExtraIterations_;
2518    /// Number of extra nodes in fast lp
2519    int numberExtraNodes_;
2520    /** Value of objective at continuous
2521        (Well actually after initial round of cuts)
2522    */
2523    double continuousObjective_;
2524    /** Value of objective before root node cuts added
2525    */
2526    double originalContinuousObjective_;
2527    /// Number of infeasibilities at continuous
2528    int continuousInfeasibilities_;
2529    /// Maximum number of cut passes at root
2530    int maximumCutPassesAtRoot_;
2531    /// Maximum number of cut passes
2532    int maximumCutPasses_;
2533    /// Preferred way of branching
2534    int preferredWay_;
2535    /// Current cut pass number
2536    int currentPassNumber_;
2537    /// Maximum number of cuts (for whichGenerator_)
2538    int maximumWhich_;
2539    /// Maximum number of rows
2540    int maximumRows_;
2541    /// Current depth
2542    int currentDepth_;
2543    /// Thread specific random number generator
2544    mutable CoinThreadRandom randomNumberGenerator_;
2545    /// Work basis for temporary use
2546    CoinWarmStartBasis workingBasis_;
2547    /// Which cut generator generated this cut
2548    int * whichGenerator_;
2549    /// Maximum number of statistics
2550    int maximumStatistics_;
2551    /// statistics
2552    CbcStatistics ** statistics_;
2553    /// Maximum depth reached
2554    int maximumDepthActual_;
2555    /// Number of reduced cost fixings
2556    double numberDJFixed_;
2557    /// Probing info
2558    CglTreeProbingInfo * probingInfo_;
2559    /// Number of fixed by analyze at root
2560    int numberFixedAtRoot_;
2561    /// Number fixed by analyze so far
2562    int numberFixedNow_;
2563    /// Whether stopping on gap
2564    bool stoppedOnGap_;
2565    /// Whether event happened
2566    mutable bool eventHappened_;
2567    /// Number of long strong goes
2568    int numberLongStrong_;
2569    /// Number of old active cuts
2570    int numberOldActiveCuts_;
2571    /// Number of new cuts
2572    int numberNewCuts_;
2573    /// Strategy worked out - mainly at root node
2574    int searchStrategy_;
2575    /// Number of iterations in strong branching
2576    int numberStrongIterations_;
2577    /** 0 - number times strong branching done, 1 - number fixed, 2 - number infeasible
2578        Second group of three is a snapshot at node [6] */
2579    int strongInfo_[7];
2580    /**
2581        For advanced applications you may wish to modify the behavior of Cbc
2582        e.g. if the solver is a NLP solver then you may not have an exact
2583        optimum solution at each step.  This gives characteristics - just for one BAB.
2584        For actually saving/restoring a solution you need the actual solver one.
2585    */
2586    OsiBabSolver * solverCharacteristics_;
2587    /// Whether to force a resolve after takeOffCuts
2588    bool resolveAfterTakeOffCuts_;
2589    /// Maximum number of iterations (designed to be used in heuristics)
2590    int maximumNumberIterations_;
2591    /// Anything with priority >= this can be treated as continuous
2592    int continuousPriority_;
2593    /// Number of outstanding update information items
2594    int numberUpdateItems_;
2595    /// Maximum number of outstanding update information items
2596    int maximumNumberUpdateItems_;
2597    /// Update items
2598    CbcObjectUpdateData * updateItems_;
2599    /// Stored row cuts for donor/recipient CbcModel
2600    CglStored * storedRowCuts_;
2601    /**
2602       Parallel
2603       0 - off
2604       1 - testing
2605       2-99 threads
2606       other special meanings
2607    */
2608    int numberThreads_;
2609    /** thread mode
2610        always use numberThreads for branching
2611        1 set then deterministic
2612        2 set then use numberThreads for root cuts
2613        4 set then use numberThreads in root mini branch and bound
2614        default is 0
2615    */
2616    int threadMode_;
2617//@}
2618};
2619/// So we can use osiObject or CbcObject during transition
2620void getIntegerInformation(const OsiObject * object, double & originalLower,
2621                           double & originalUpper) ;
2622// So we can call from other programs
2623// Real main program
2624class OsiClpSolverInterface;
2625int CbcMain (int argc, const char *argv[], OsiClpSolverInterface & solver, CbcModel ** babSolver);
2626int CbcMain (int argc, const char *argv[], CbcModel & babSolver);
2627// four ways of calling
2628int callCbc(const char * input2, OsiClpSolverInterface& solver1);
2629int callCbc(const char * input2);
2630int callCbc(const std::string input2, OsiClpSolverInterface& solver1);
2631int callCbc(const std::string input2) ;
2632// When we want to load up CbcModel with options first
2633void CbcMain0 (CbcModel & babSolver);
2634int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver);
2635// two ways of calling
2636int callCbc(const char * input2, CbcModel & babSolver);
2637int callCbc(const std::string input2, CbcModel & babSolver);
2638// And when CbcMain0 already called to initialize
2639int callCbc1(const char * input2, CbcModel & babSolver);
2640int callCbc1(const std::string input2, CbcModel & babSolver);
2641// And when CbcMain0 already called to initialize (with call back) (see CbcMain1 for whereFrom)
2642int callCbc1(const char * input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
2643int callCbc1(const std::string input2, CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
2644int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom));
2645// For uniform setting of cut and heuristic options
2646void setCutAndHeuristicOptions(CbcModel & model);
2647#endif
Note: See TracBrowser for help on using the repository browser.