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