source: trunk/Clp/src/ClpEventHandler.hpp @ 1610

Last change on this file since 1610 was 1610, checked in by forrest, 11 years ago

changes for more flexibility in ClpSolve?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1/* $Id: ClpEventHandler.hpp 1610 2010-09-23 15:11:23Z forrest $ */
2// Copyright (C) 2004, International Business Machines
3// Corporation and others.  All Rights Reserved.
4#ifndef ClpEventHandler_H
5#define ClpEventHandler_H
6
7#include "ClpSimplex.hpp"
8/** Base class for Clp event handling
9
10This is just here to allow for event handling.  By event I mean a Clp event
11e.g. end of values pass.
12
13One use would be to let a user handle a system event e.g. Control-C.  This could be done
14by deriving a class MyEventHandler which knows about such events.  If one occurs
15MyEventHandler::event() could clear event status and return 3 (stopped).
16
17Clp would then return to user code.
18
19As it is called every iteration this should be fine grained enough.
20
21User can derive and construct from CbcModel  - not pretty
22
23*/
24
25class ClpEventHandler  {
26
27public:
28     /** enums for what sort of event.
29
30         These will also be returned in ClpModel::secondaryStatus() as int
31     */
32     enum Event {
33          endOfIteration = 100, // used to set secondary status
34          endOfFactorization,
35          endOfValuesPass,
36          node, // for Cbc
37          treeStatus, // for Cbc
38          solution, // for Cbc
39          theta, // hit in parametrics
40          pivotRow, // used to choose pivot row
41          presolveStart, // ClpSolve presolve start
42          presolveSize, // sees if ClpSolve presolve too big or too small
43          presolveInfeasible, // ClpSolve presolve infeasible
44          presolveBeforeSolve, // ClpSolve presolve before solve
45          presolveAfterFirstSolve, // ClpSolve presolve after solve
46          presolveAfterSolve, // ClpSolve presolve after solve
47          presolveEnd // ClpSolve presolve end
48     };
49     /**@name Virtual method that the derived classes should provide.
50      The base class instance does nothing and as event() is only useful method
51      it would not be very useful NOT providing one!
52     */
53     //@{
54     /** This can do whatever it likes.  If return code -1 then carries on
55         if 0 sets ClpModel::status() to 5 (stopped by event) and will return to user.
56         At present if <-1 carries on and if >0 acts as if 0 - this may change.
57         For ClpSolve 2 -> too big return status of -2 and -> too small 3
58     */
59     virtual int event(Event whichEvent);
60     //@}
61
62
63     /**@name Constructors, destructor */
64
65     //@{
66     /** Default constructor. */
67     ClpEventHandler(ClpSimplex * model = NULL);
68     /** Destructor */
69     virtual ~ClpEventHandler();
70     // Copy
71     ClpEventHandler(const ClpEventHandler&);
72     // Assignment
73     ClpEventHandler& operator=(const ClpEventHandler&);
74     /// Clone
75     virtual ClpEventHandler * clone() const;
76
77     //@}
78
79     /**@name Sets/gets */
80
81     //@{
82     /** set model. */
83     void setSimplex(ClpSimplex * model);
84     /// Get model
85     inline ClpSimplex * simplex() const {
86          return model_;
87     }
88     //@}
89
90
91protected:
92     /**@name Data members
93        The data members are protected to allow access for derived classes. */
94     //@{
95     /// Pointer to simplex
96     ClpSimplex * model_;
97     //@}
98};
99/** Base class for Clp disaster handling
100
101This is here to allow for disaster handling.  By disaster I mean that Clp
102would otherwise give up
103
104*/
105
106class ClpDisasterHandler  {
107
108public:
109     /**@name Virtual methods that the derived classe should provide.
110     */
111     //@{
112     /// Into simplex
113     virtual void intoSimplex() = 0;
114     /// Checks if disaster
115     virtual bool check() const = 0;
116     /// saves information for next attempt
117     virtual void saveInfo() = 0;
118     /// Type of disaster 0 can fix, 1 abort
119     virtual int typeOfDisaster();
120     //@}
121
122
123     /**@name Constructors, destructor */
124
125     //@{
126     /** Default constructor. */
127     ClpDisasterHandler(ClpSimplex * model = NULL);
128     /** Destructor */
129     virtual ~ClpDisasterHandler();
130     // Copy
131     ClpDisasterHandler(const ClpDisasterHandler&);
132     // Assignment
133     ClpDisasterHandler& operator=(const ClpDisasterHandler&);
134     /// Clone
135     virtual ClpDisasterHandler * clone() const = 0;
136
137     //@}
138
139     /**@name Sets/gets */
140
141     //@{
142     /** set model. */
143     void setSimplex(ClpSimplex * model);
144     /// Get model
145     inline ClpSimplex * simplex() const {
146          return model_;
147     }
148     //@}
149
150
151protected:
152     /**@name Data members
153        The data members are protected to allow access for derived classes. */
154     //@{
155     /// Pointer to simplex
156     ClpSimplex * model_;
157     //@}
158};
159#endif
Note: See TracBrowser for help on using the repository browser.