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

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

for cut generators

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