@@ -24,7 +24,7 @@ A JuMP interface to the algorithms implemented by JuMPIn
24
24
25
25
import JuMP
26
26
27
- import JuMPIn: get_bipartite_incidence_graph, maximum_matching
27
+ import JuMPIn: get_bipartite_incidence_graph, maximum_matching, GraphDataTuple
28
28
29
29
import Graphs as gjl
30
30
import BipartiteMatching as bpm
101
101
102
102
103
103
IncidenceGraphInterface (
104
- args:: Tuple{Tuple, Dict, Dict}
104
+ args:: GraphDataTuple
105
105
) = IncidenceGraphInterface (
106
106
_tuple_to_graphs_jl (args[1 ]),
107
107
args[2 ],
@@ -119,7 +119,7 @@ IncidenceGraphInterface(
119
119
120
120
121
121
IncidenceGraphInterface (
122
- constraints:: Vector{JuMP.ConstraintRef} ,
122
+ constraints:: Vector{<: JuMP.ConstraintRef} ,
123
123
variables:: Vector{JuMP.VariableRef} ,
124
124
) = IncidenceGraphInterface (
125
125
get_bipartite_incidence_graph (constraints, variables)
@@ -138,7 +138,7 @@ Return the variables adjacent to a constraint in an incidence graph.
138
138
function get_adjacent (
139
139
igraph:: IncidenceGraphInterface ,
140
140
constraint:: JuMP.ConstraintRef ,
141
- )
141
+ ):: Vector{JuMP.VariableRef}
142
142
con_node = igraph. _con_node_map[constraint]
143
143
var_nodes = gjl. neighbors (igraph. _graph, con_node)
144
144
variables = [igraph. _nodes[n] for n in var_nodes]
@@ -165,7 +165,7 @@ julia> @NLconstraint(m, eq_2, v[1]*v[2]^3 == 2);
165
165
julia> igraph = ji.IncidenceGraphInterface(m);
166
166
julia> adj_cons = ji.get_adjacent(igraph, v[1]);
167
167
julia> display(adj_cons)
168
- 2-element Vector{ConstraintRef{Model, C, ScalarShape} where C }:
168
+ 2-element Vector{ConstraintRef}:
169
169
eq_1 : v[1] + v[3] = 1.0
170
170
v[1] * v[2] ^ 3.0 - 2.0 = 0
171
171
```
@@ -174,7 +174,7 @@ julia> display(adj_cons)
174
174
function get_adjacent (
175
175
igraph:: IncidenceGraphInterface ,
176
176
variable:: JuMP.VariableRef ,
177
- )
177
+ ):: Vector{JuMP.ConstraintRef}
178
178
var_node = igraph. _var_node_map[variable]
179
179
con_nodes = gjl. neighbors (igraph. _graph, var_node)
180
180
constraints = [igraph. _nodes[n] for n in con_nodes]
@@ -200,7 +200,7 @@ julia> @NLconstraint(m, eq_2, v[1]*v[2]^3 == 2);
200
200
julia> igraph = ji.IncidenceGraphInterface(m);
201
201
julia> matching = ji.maximum_matching(igraph);
202
202
julia> display(matching)
203
- Dict{ConstraintRef{Model, C, ScalarShape} where C , VariableRef} with 2 entries:
203
+ Dict{ConstraintRef, VariableRef} with 2 entries:
204
204
v[1] * v[2] ^ 3.0 - 2.0 = 0 => v[2]
205
205
eq_1 : v[1] + v[3] = 1.0 => v[1]
206
206
```
@@ -220,13 +220,32 @@ end
220
220
221
221
222
222
function maximum_matching (
223
- constraints:: Vector{JuMP.ConstraintRef} ,
223
+ constraints:: Vector{<: JuMP.ConstraintRef} ,
224
224
variables:: Vector{JuMP.VariableRef} ,
225
225
):: Dict{JuMP.ConstraintRef, JuMP.VariableRef}
226
226
igraph = IncidenceGraphInterface (constraints, variables)
227
227
return maximum_matching (igraph)
228
228
end
229
229
230
+ const DMConPartition = NamedTuple{
231
+ (:underconstrained , :square , :overconstrained , :unmatched ),
232
+ Tuple{
233
+ Vector{JuMP. ConstraintRef},
234
+ Vector{JuMP. ConstraintRef},
235
+ Vector{JuMP. ConstraintRef},
236
+ Vector{JuMP. ConstraintRef},
237
+ },
238
+ }
239
+
240
+ const DMVarPartition = NamedTuple{
241
+ (:unmatched , :underconstrained , :square , :overconstrained ),
242
+ Tuple{
243
+ Vector{JuMP. VariableRef},
244
+ Vector{JuMP. VariableRef},
245
+ Vector{JuMP. VariableRef},
246
+ Vector{JuMP. VariableRef},
247
+ },
248
+ }
230
249
231
250
"""
232
251
dulmage_mendelsohn(igraph::IncidenceGraphInterface)
@@ -294,21 +313,23 @@ julia> display(var_dmp.underconstrained)
294
313
v[1]
295
314
v[2]
296
315
julia> display(con_dmp.underconstrained)
297
- 2-element Vector{ConstraintRef{Model, C, ScalarShape} where C }:
316
+ 2-element Vector{ConstraintRef}:
298
317
eq_1 : v[1] + v[3] = 1.0
299
318
v[1] * v[2] ^ 3.0 - 2.0 = 0
300
319
julia> display(var_dmp.square)
301
320
1-element Vector{VariableRef}:
302
321
v[4]
303
322
julia> display(con_dmp.square)
304
- 1-element Vector{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.ScalarQuadraticFunction{Float64}, MathOptInterface.EqualTo{Float64}}, ScalarShape} }:
323
+ 1-element Vector{ConstraintRef}:
305
324
eq_3 : v[4]² = 3.0
306
325
julia> # As there are no unmatched constraints, the overconstrained subsystem
307
326
julia> # is empty.
308
327
```
309
328
310
329
"""
311
- function dulmage_mendelsohn (igraph:: IncidenceGraphInterface )
330
+ function dulmage_mendelsohn (
331
+ igraph:: IncidenceGraphInterface
332
+ ):: Tuple{DMConPartition, DMVarPartition}
312
333
ncon = length (igraph. _con_node_map)
313
334
con_node_set = Set (1 : ncon)
314
335
con_dmp, var_dmp = dulmage_mendelsohn (igraph. _graph, con_node_set)
332
353
333
354
334
355
function dulmage_mendelsohn (
335
- constraints:: Vector{JuMP.ConstraintRef} ,
356
+ constraints:: Vector{<: JuMP.ConstraintRef} ,
336
357
variables:: Vector{JuMP.VariableRef} ,
337
- )
358
+ ):: Tuple{DMConPartition, DMVarPartition}
338
359
igraph = IncidenceGraphInterface (constraints, variables)
339
360
return dulmage_mendelsohn (igraph)
340
361
end
0 commit comments