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
27
struct
GScipEventHandlerDescription
{
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.
54
class
GScipEventHandlerContext
{
55
public
:
56
GScipEventHandlerContext
(
GScip
*
gscip
, SCIP_EVENTTYPE
event_type
)
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.
74
class
GScipEventHandler
{
75
public
:
76
explicit
GScipEventHandler
(
const
GScipEventHandlerDescription
&
description
)
77
: description_(
description
) {}
78
virtual
~GScipEventHandler
() {}
79
const
GScipEventHandlerDescription
&
description
()
const
{
80
return
description_;
81
}
82
83
virtual
void
Execute
(
GScipEventHandlerContext
context
) = 0;
84
85
private
:
86
GScipEventHandlerDescription
description_;
87
};
88
89
// Handler is not owned but held.
90
void
RegisterGScipEventHandler
(
GScip
* scip,
GScipEventHandler
* handler);
91
92
}
// namespace operations_research
93
94
#endif
// OR_TOOLS_GSCIP_GSCIP_EVENT_HANDLER_H_
operations_research::GScipEventHandlerContext
Definition:
gscip_event_handler.h:54
operations_research::GScipEventHandlerContext::event_type
SCIP_EVENTTYPE event_type() const
Definition:
gscip_event_handler.h:63
operations_research::GScipEventHandlerContext::gscip
GScip * gscip() const
Definition:
gscip_event_handler.h:59
operations_research::GScipEventHandlerContext::GScipEventHandlerContext
GScipEventHandlerContext(GScip *gscip, SCIP_EVENTTYPE event_type)
Definition:
gscip_event_handler.h:56
operations_research::GScipEventHandler
Definition:
gscip_event_handler.h:74
operations_research::GScipEventHandler::~GScipEventHandler
virtual ~GScipEventHandler()
Definition:
gscip_event_handler.h:78
operations_research::GScipEventHandler::description
const GScipEventHandlerDescription & description() const
Definition:
gscip_event_handler.h:79
operations_research::GScipEventHandler::Execute
virtual void Execute(GScipEventHandlerContext context)=0
operations_research::GScipEventHandler::GScipEventHandler
GScipEventHandler(const GScipEventHandlerDescription &description)
Definition:
gscip_event_handler.h:76
operations_research::GScip
Definition:
gscip.h:127
gscip.h
context
GurobiMPCallbackContext * context
Definition:
gurobi_interface.cc:513
operations_research
Collection of objects used to extend the Constraint Solver library.
Definition:
dense_doubly_linked_list.h:21
operations_research::RegisterGScipEventHandler
void RegisterGScipEventHandler(GScip *scip, GScipEventHandler *handler)
Definition:
gscip_event_handler.cc:78
operations_research::GScipEventHandlerDescription
Definition:
gscip_event_handler.h:27
operations_research::GScipEventHandlerDescription::description
std::string description
Definition:
gscip_event_handler.h:37
operations_research::GScipEventHandlerDescription::events_to_catch_from_start
std::vector< SCIP_EVENTTYPE > events_to_catch_from_start
Definition:
gscip_event_handler.h:42
operations_research::GScipEventHandlerDescription::name
std::string name
Definition:
gscip_event_handler.h:34
ortools
gscip
gscip_event_handler.h
Generated by
1.9.1