@@ -25,16 +25,73 @@ abstract type AbstractConstraintHandler end
25
25
# (also: CONSDATA)
26
26
abstract type AbstractConstraint{Handler} end
27
27
28
- # Example implementation
29
- mutable struct ExampleConstraintHandler <: AbstractConstraintHandler
30
- end
28
+ # Parameters:
29
+
30
+ abstract type AbstractConstraintHandlerParameter end
31
+ struct Name <: AbstractConstraintHandlerParameter end
32
+ struct Description <: AbstractConstraintHandlerParameter end
33
+ struct EnforcePriority <: AbstractConstraintHandlerParameter end
34
+ struct CheckPriority <: AbstractConstraintHandlerParameter end
35
+
36
+ # Interface methods
37
+
38
+ # Parameters have default values
39
+ get (ch:: AbstractConstraintHandler , :: Name ) = " "
40
+ get (ch:: AbstractConstraintHandler , :: Description ) = " "
41
+ # enfoprio: integral has 0, nonlinear: -30 or less
42
+ get (ch:: AbstractConstraintHandler , :: EnforcePriority ) = - 15
43
+ # checkprio: integral has 0, SCIP's plugins have -6000000 or more
44
+ get (ch:: AbstractConstraintHandler , :: CheckPriority ) = - 7000000
45
+
46
+ # For semantics of callback methods, see SCIP documentation at:
47
+ # https://scip.zib.de/doc-6.0.1/html/CONS.php#CONS_FUNDAMENTALCALLBACKS
48
+
49
+ function check end
50
+
51
+ # possible return values:
52
+ # SCIP_CUTOFF: stating that the current subproblem is infeasible
53
+ # SCIP_CONSADDED: adding constraint that resolves the infeasibility
54
+ # SCIP_REDUCEDDOM: reducing the domain of a variable
55
+ # SCIP_SEPARATED: adding a cutting plane
56
+ # SCIP_BRANCHED: performing a branching
57
+ function enforce_lp_sol end
58
+
59
+ # possible return values:
60
+ # SCIP_CUTOFF: stating that the current subproblem is infeasible
61
+ # SCIP_CONSADDED: adding constraint that resolves the infeasibility
62
+ # SCIP_REDUCEDDOM: reducing the domain of a variable
63
+ # SCIP_BRANCHED: performing a branching
64
+ # SCIP_SOLVELP: force solving of LP
65
+ function enforce_pseudo_sol end
66
+
67
+ function lock end
31
68
32
- # ## ^ above: what it will look like to Julia users
33
- # ## = here: sketches for the translation
69
+ # Methods
34
70
35
- # ## v below: what it will look like to SCIP
71
+ # CONSCHECK
72
+ # (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss,
73
+ # SCIP_SOL* sol, SCIP_Bool checkintegrality, SCIP_Bool checklprows,
74
+ # SCIP_Bool printreason, SCIP_Bool completely, SCIP_RESULT* result
75
+ function _conscheck (scip:: Ptr{SCIP_} , conshdlr: :{SCIP_CONSHDLR},
76
+ conss:: Ptr{Ptr{SCIP_CONS}} , nconss:: Cint ,
77
+ sol:: Ptr{SCIP_SOL} , checkintegrality:: SCIP_Bool ,
78
+ checklprows:: SCIP_Bool , printreason:: SCIP_Bool ,
79
+ completely:: SCIP_Bool , result:: Ptr{SCIP_RESULT} )
80
+ # get Julia object out of constraint handler data
81
+ conshdlrdata = SCIPconshdlrGetData (conshdlr)
82
+ constraint_handler = unsafe_objref_from_pointer (conshdlrdata)
36
83
37
- # Methods
84
+ # get Julia array from C pointer
85
+ constraint_pointers = unsafe_wrap (Array{Ptr{SCIP_CONS}}, conss, nconss)
86
+
87
+ # TODO : fetch solution values
88
+ # TODO : document meaning of all parameters
89
+
90
+ # call user method via dispatch
91
+ result[] = check (constraint_handler, constraints)
92
+
93
+ return SCIP_OKAY
94
+ end
38
95
39
96
# CONSENFOLP
40
97
# (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss,
@@ -44,6 +101,19 @@ function _consenfolp(scip::Ptr{SCIP_}, conshdlr::Ptr{SCIP_CONSHDLR},
44
101
conss:: Ptr{Ptr{SCIP_CONS}} , nconss:: Cint ,
45
102
nusefulconss:: Cint , solinfeasible:: SCIP_Bool ,
46
103
result:: Ptr{SCIP_RESULT} )
104
+ # get Julia object out of constraint handler data
105
+ conshdlrdata = SCIPconshdlrGetData (conshdlr)
106
+ constraint_handler = unsafe_objref_from_pointer (conshdlrdata)
107
+
108
+ # get Julia array from C pointer
109
+ constraint_pointers = unsafe_wrap (Array{Ptr{SCIP_CONS}}, conss, nconss)
110
+
111
+ # TODO : fetch solution values?
112
+ # TODO : document meaning of all parameters
113
+
114
+ # call user method via dispatch
115
+ result[] = enforce_lp_sol (constraint_handler, constraints, solinfeasible)
116
+
47
117
return SCIP_OKAY
48
118
end
49
119
@@ -55,18 +125,20 @@ function _consenfops(scip::Ptr{SCIP_}, conshdlr::Ptr{SCIP_CONSHDLR},
55
125
conss:: Ptr{Ptr{SCIP_CONS}} , nconss:: Cint ,
56
126
nusefulconss:: Cint , solinfeasible:: SCIP_Bool ,
57
127
objinfeasible:: SCIP_Bool , result:: Ptr{SCIP_RESULT} )
58
- return SCIP_OKAY
59
- end
128
+ # get Julia object out of constraint handler data
129
+ conshdlrdata = SCIPconshdlrGetData (conshdlr)
130
+ constraint_handler = unsafe_objref_from_pointer (conshdlrdata)
131
+
132
+ # get Julia array from C pointer
133
+ constraint_pointers = unsafe_wrap (Array{Ptr{SCIP_CONS}}, conss, nconss)
134
+
135
+ # TODO : fetch solution values?
136
+ # TODO : document meaning of all parameters
137
+
138
+ # call user method via dispatch
139
+ result[] = enforce_pseudo_sol (constraint_handler, constraints,
140
+ solinfeasible, objinfeasible)
60
141
61
- # CONSCHECK
62
- # (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss,
63
- # SCIP_SOL* sol, SCIP_Bool checkintegrality, SCIP_Bool checklprows,
64
- # SCIP_Bool printreason, SCIP_Bool completely, SCIP_RESULT* result
65
- function _conscheck (scip:: Ptr{SCIP_} , conshdlr: :{SCIP_CONSHDLR},
66
- conss:: Ptr{Ptr{SCIP_CONS}} , nconss:: Cint ,
67
- sol:: Ptr{SCIP_SOL} , checkintegrality:: SCIP_Bool ,
68
- checklprows:: SCIP_Bool , printreason:: SCIP_Bool ,
69
- completely:: SCIP_Bool , result:: Ptr{SCIP_RESULT} )
70
142
return SCIP_OKAY
71
143
end
72
144
76
148
function _conslock (scip:: Ptr{SCIP_} , conshdlr:: Ptr{SCIP_CONSHDLR} ,
77
149
cons:: Ptr{SCIP_CONS} , locktype:: Ptr{SCIP_LOCKTYPE} ,
78
150
nlockspos:: Cint , nlocksneg:: Cint )
151
+ # get Julia object out of constraint handler data
152
+ conshdlrdata = SCIPconshdlrGetData (conshdlr)
153
+ constraint_handler = unsafe_objref_from_pointer (conshdlrdata)
154
+
155
+ # TODO : document meaning of all parameters
156
+
157
+ # call user method via dispatch
158
+ result[] = lock (constraint_handler, cons, locktype, nlockspos, nlocksneg)
159
+
79
160
return SCIP_OKAY
80
161
end
81
162
85
166
# - set properties (NAME, DESC, ENFOPRIORITY, CHECKPRIORITY).
86
167
# - initialize conshdlrdata (== Julia object)
87
168
# - could be called from the constructor to constraint handler?
88
- function include_conshdlr (mscip:: ManagedSCIP , constraint_handler :: CH ) where CH <: AbstractConstraintHandler
169
+ function include_conshdlr (mscip:: ManagedSCIP , ch :: CH ) where CH <: AbstractConstraintHandler
89
170
# get C function pointers from Julia functions
90
- # TODO : need specific methods? ask users to specify as function arguments?
91
171
_enfolp = @cfunction (_consenfolp, SCIP_RETCODE, (Ptr{SCIP_}, Ptr{SCIP_CONSHDLR}, Ptr{Ptr{SCIP_CONS}}, Cint, Cint, SCIP_Bool, SCIP_Bool, Ptr{SCIP_RESULT}))
92
172
_enfops = @cfunction (_consenfops, SCIP_RETCODE, (Ptr{SCIP_}, Ptr{SCIP_CONSHDLR}, Ptr{Ptr{SCIP_CONS}}, Cint, Cint, SCIP_Bool, SCIP_Bool, SCIP_Bool, Ptr{SCIP_RESULT}))
93
173
_check = @cfunction (_conscheck, SCIP_RETCODE, (Ptr{SCIP_}, Ptr{SCIP_CONSHDLR}, Ptr{Ptr{SCIP_CONS}}, Cint, Ptr{SCIP_SOL}, SCIP_Bool, SCIP_Bool, SCIP_Bool, SCIP_Bool, Ptr{SCIP_RESULT}))
@@ -102,16 +182,16 @@ function include_conshdlr(mscip::ManagedSCIP, constraint_handler::CH) where CH <
102
182
NEEDSCONS = TRUE
103
183
104
184
# Get other values from methods:
105
- name = get (constraint_handler , Name ())
106
- desc = get (constraint_handler , Description ())
107
- enfoprio = get (constraint_handler , EnforcePriority ())
108
- checkprio = get (constraint_handler , CheckPriority ())
185
+ name = get (ch , Name ())
186
+ desc = get (ch , Description ())
187
+ enfoprio = get (ch , EnforcePriority ())
188
+ checkprio = get (ch , CheckPriority ())
109
189
110
190
# Register constraint handler with SCIP instance.
111
191
@SC SCIPincludeConshdlrBasic (mscip, conshdlr__, name, desc, enfopriority,
112
192
chckpriority, EAGERFREQ, NEEDSCONS,
113
193
_enfolp, _enfops, _check, _lock,
114
- constraint_handler )
194
+ ch )
115
195
116
196
# Sanity checks
117
197
@assert conshdlr__[] != C_NULL
0 commit comments