OR-Tools  9.0
gscip_event_handler.h
Go to the documentation of this file.
1 // Copyright 2010-2021 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 // Provides a safe C++ interface for SCIP event handlers, which are described at
15 // https://www.scipopt.org/doc-7.0.1/html/EVENT.php.
16 #ifndef OR_TOOLS_GSCIP_GSCIP_EVENT_HANDLER_H_
17 #define OR_TOOLS_GSCIP_GSCIP_EVENT_HANDLER_H_
18 
19 #include <string>
20 #include <vector>
21 
22 #include "ortools/gscip/gscip.h"
23 #include "scip/type_event.h"
24 
25 namespace operations_research {
26 
28  // For the first two members below, the SCIP constraint handler
29  // property name is provided. See
30  // https://www.scipopt.org/doc-7.0.1/html/EVENT.php#EVENTHDLR_PROPERTIES for
31  // details.
32 
33  // See CONSHDLR_NAME in SCIP documentation above.
34  std::string name;
35 
36  // See CONSHDLR_DESC in SCIP documentation above.
37  std::string description;
38 
39  // These are "general" events to be added via SCIPcatchEvent in the EVENTINIT
40  // callback, not "Var" or "Row" events. See scip/type_event.h for the list of
41  // possible events.
42  std::vector<SCIP_EVENTTYPE> events_to_catch_from_start;
43 
44  // TODO(user,user): Support Var and Row events.
45 
46  // TODO(user,user): Support registering events in the EVENTINITSOL
47  // callback, which would cause them to be trapped only after presolve.
48 };
49 
50 // Passed by value. This is a lightweight interface to the callback context and
51 // the underlying problem. It's preferred for callbacks to use the context
52 // object to query information rather than using the raw SCIP pointer, because
53 // the context object can be set up to do this in a safe way.
55  public:
57  : gscip_(gscip), event_type_(event_type) {}
58 
59  GScip* gscip() const { return gscip_; }
60 
61  // This is always an atomic event type, not a mask (i.e., one of the events
62  // defined as a bitwise OR).
63  SCIP_EVENTTYPE event_type() const { return event_type_; }
64 
65  // TODO(user,user): Support additional properties that might need to be
66  // queried within an event handler.
67 
68  private:
69  GScip* gscip_;
70  SCIP_EVENTTYPE event_type_;
71 };
72 
73 // Inherit from this to implement the callback.
75  public:
77  : description_(description) {}
78  virtual ~GScipEventHandler() {}
80  return description_;
81  }
82 
84 
85  private:
86  GScipEventHandlerDescription description_;
87 };
88 
89 // Handler is not owned but held.
91 
92 } // namespace operations_research
93 
94 #endif // OR_TOOLS_GSCIP_GSCIP_EVENT_HANDLER_H_
GScipEventHandlerContext(GScip *gscip, SCIP_EVENTTYPE event_type)
const GScipEventHandlerDescription & description() const
virtual void Execute(GScipEventHandlerContext context)=0
GScipEventHandler(const GScipEventHandlerDescription &description)
GurobiMPCallbackContext * context
Collection of objects used to extend the Constraint Solver library.
void RegisterGScipEventHandler(GScip *scip, GScipEventHandler *handler)
std::vector< SCIP_EVENTTYPE > events_to_catch_from_start