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

Last change on this file since 1879 was 1825, checked in by forrest, 8 years ago

stuff to allow more event handling

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1/* $Id: ClpEventHandler.hpp 1825 2011-11-20 16:02:57Z forrest $ */
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
12This is just here to allow for event handling.  By event I mean a Clp event
13e.g. end of values pass.
14
15One use would be to let a user handle a system event e.g. Control-C.  This could be done
16by deriving a class MyEventHandler which knows about such events.  If one occurs
17MyEventHandler::event() could clear event status and return 3 (stopped).
18
19Clp would then return to user code.
20
21As it is called every iteration this should be fine grained enough.
22
23User can derive and construct from CbcModel  - not pretty
24
25*/
26
27class ClpEventHandler  {
28
29public:
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, // after gutsOfSolution etc
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          goodFactorization, // before gutsOfSolution
51          complicatedPivotIn, // in modifyCoefficients
52          noCandidateInPrimal, // tentative end
53          looksEndInPrimal, // About to declare victory (or defeat)
54          endInPrimal, // Victory (or defeat)
55          beforeStatusOfProblemInPrimal,
56          startOfStatusOfProblemInPrimal,
57          complicatedPivotOut, // in modifyCoefficients
58          noCandidateInDual, // tentative end
59          looksEndInDual, // About to declare victory (or defeat)
60          endInDual, // Victory (or defeat)
61          beforeStatusOfProblemInDual,
62          startOfStatusOfProblemInDual,
63          startOfIterationInDual,
64          updateDualsInDual,
65          endOfCreateRim,
66          slightlyInfeasible,
67          modifyMatrixInMiniPresolve,
68          moreMiniPresolve,
69          modifyMatrixInMiniPostsolve,
70          noTheta // At end (because no pivot)
71     };
72     /**@name Virtual method that the derived classes should provide.
73      The base class instance does nothing and as event() is only useful method
74      it would not be very useful NOT providing one!
75     */
76     //@{
77     /** This can do whatever it likes.  If return code -1 then carries on
78         if 0 sets ClpModel::status() to 5 (stopped by event) and will return to user.
79         At present if <-1 carries on and if >0 acts as if 0 - this may change.
80         For ClpSolve 2 -> too big return status of -2 and -> too small 3
81     */
82     virtual int event(Event whichEvent);
83     /** This can do whatever it likes.  Return code -1 means no action.
84         This passes in something
85     */
86     virtual int eventWithInfo(Event whichEvent, void * info) ;
87     //@}
88
89
90     /**@name Constructors, destructor */
91
92     //@{
93     /** Default constructor. */
94     ClpEventHandler(ClpSimplex * model = NULL);
95     /** Destructor */
96     virtual ~ClpEventHandler();
97     // Copy
98     ClpEventHandler(const ClpEventHandler&);
99     // Assignment
100     ClpEventHandler& operator=(const ClpEventHandler&);
101     /// Clone
102     virtual ClpEventHandler * clone() const;
103
104     //@}
105
106     /**@name Sets/gets */
107
108     //@{
109     /** set model. */
110     void setSimplex(ClpSimplex * model);
111     /// Get model
112     inline ClpSimplex * simplex() const {
113          return model_;
114     }
115     //@}
116
117
118protected:
119     /**@name Data members
120        The data members are protected to allow access for derived classes. */
121     //@{
122     /// Pointer to simplex
123     ClpSimplex * model_;
124     //@}
125};
126/** Base class for Clp disaster handling
127
128This is here to allow for disaster handling.  By disaster I mean that Clp
129would otherwise give up
130
131*/
132
133class ClpDisasterHandler  {
134
135public:
136     /**@name Virtual methods that the derived classe should provide.
137     */
138     //@{
139     /// Into simplex
140     virtual void intoSimplex() = 0;
141     /// Checks if disaster
142     virtual bool check() const = 0;
143     /// saves information for next attempt
144     virtual void saveInfo() = 0;
145     /// Type of disaster 0 can fix, 1 abort
146     virtual int typeOfDisaster();
147     //@}
148
149
150     /**@name Constructors, destructor */
151
152     //@{
153     /** Default constructor. */
154     ClpDisasterHandler(ClpSimplex * model = NULL);
155     /** Destructor */
156     virtual ~ClpDisasterHandler();
157     // Copy
158     ClpDisasterHandler(const ClpDisasterHandler&);
159     // Assignment
160     ClpDisasterHandler& operator=(const ClpDisasterHandler&);
161     /// Clone
162     virtual ClpDisasterHandler * clone() const = 0;
163
164     //@}
165
166     /**@name Sets/gets */
167
168     //@{
169     /** set model. */
170     void setSimplex(ClpSimplex * model);
171     /// Get model
172     inline ClpSimplex * simplex() const {
173          return model_;
174     }
175     //@}
176
177
178protected:
179     /**@name Data members
180        The data members are protected to allow access for derived classes. */
181     //@{
182     /// Pointer to simplex
183     ClpSimplex * model_;
184     //@}
185};
186#endif
Note: See TracBrowser for help on using the repository browser.