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

Last change on this file since 1525 was 1525, checked in by mjs, 10 years ago

Formatted .cpp, .hpp, .c, .h files with "astyle -A4 -p". This matches the formatting used in the grand CBC reorganization.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1/* $Id: ClpEventHandler.hpp 1525 2010-02-26 17:27:59Z mjs $ */
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     };
41     /**@name Virtual method that the derived classe should provide.
42      The base class instance does nothing and as event() is only useful method
43      it would not be very useful NOT providing one!
44     */
45     //@{
46     /** This can do whatever it likes.  If return code -1 then carries on
47         if 0 sets ClpModel::status() to 5 (stopped by event) and will return to user.
48         At present if <-1 carries on and if >0 acts as if 0 - this may change
49     */
50     virtual int event(Event whichEvent);
51     //@}
52
53
54     /**@name Constructors, destructor */
55
56     //@{
57     /** Default constructor. */
58     ClpEventHandler(ClpSimplex * model = NULL);
59     /** Destructor */
60     virtual ~ClpEventHandler();
61     // Copy
62     ClpEventHandler(const ClpEventHandler&);
63     // Assignment
64     ClpEventHandler& operator=(const ClpEventHandler&);
65     /// Clone
66     virtual ClpEventHandler * clone() const;
67
68     //@}
69
70     /**@name Sets/gets */
71
72     //@{
73     /** set model. */
74     void setSimplex(ClpSimplex * model);
75     /// Get model
76     inline ClpSimplex * simplex() const {
77          return model_;
78     }
79     //@}
80
81
82protected:
83     /**@name Data members
84        The data members are protected to allow access for derived classes. */
85     //@{
86     /// Pointer to simplex
87     ClpSimplex * model_;
88     //@}
89};
90/** Base class for Clp disaster handling
91
92This is here to allow for disaster handling.  By disaster I mean that Clp
93would otherwise give up
94
95*/
96
97class ClpDisasterHandler  {
98
99public:
100     /**@name Virtual methods that the derived classe should provide.
101     */
102     //@{
103     /// Into simplex
104     virtual void intoSimplex() = 0;
105     /// Checks if disaster
106     virtual bool check() const = 0;
107     /// saves information for next attempt
108     virtual void saveInfo() = 0;
109     /// Type of disaster 0 can fix, 1 abort
110     virtual int typeOfDisaster();
111     //@}
112
113
114     /**@name Constructors, destructor */
115
116     //@{
117     /** Default constructor. */
118     ClpDisasterHandler(ClpSimplex * model = NULL);
119     /** Destructor */
120     virtual ~ClpDisasterHandler();
121     // Copy
122     ClpDisasterHandler(const ClpDisasterHandler&);
123     // Assignment
124     ClpDisasterHandler& operator=(const ClpDisasterHandler&);
125     /// Clone
126     virtual ClpDisasterHandler * clone() const = 0;
127
128     //@}
129
130     /**@name Sets/gets */
131
132     //@{
133     /** set model. */
134     void setSimplex(ClpSimplex * model);
135     /// Get model
136     inline ClpSimplex * simplex() const {
137          return model_;
138     }
139     //@}
140
141
142protected:
143     /**@name Data members
144        The data members are protected to allow access for derived classes. */
145     //@{
146     /// Pointer to simplex
147     ClpSimplex * model_;
148     //@}
149};
150#endif
Note: See TracBrowser for help on using the repository browser.