Skip to content

Commit b3558e2

Browse files
authored
Merge pull request #14 from jalving/jalving/fix_nightly
GraphOptInterface maintenance
2 parents 3a041e5 + 1b89301 commit b3558e2

7 files changed

Lines changed: 495 additions & 7 deletions

File tree

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
matrix:
2525
version:
2626
- '1.6'
27-
- '1.8'
27+
- '1.12'
2828
- 'nightly'
2929
os:
3030
- ubuntu-latest

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1212
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1313

1414
[compat]
15-
DataStructures = "0.18"
15+
DataStructures = "0.18,0.19"
1616
Lazy="0.15"
1717
Graphs = "1.8"
1818
MathOptInterface = "1.6"

src/GraphOptInterface.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Abstract supertype for block-structure-exploiting optimizers.
1515
"""
1616
abstract type AbstractGraphOptimizer <: MOI.AbstractOptimizer end
1717

18+
"""
19+
supports_graph_interface(optimizer::MOI.AbstractOptimizer)
20+
21+
Check if the given optimizer supports the graph interface. Returns `false` for standard
22+
MOI optimizers and `true` for `AbstractGraphOptimizer` subtypes.
23+
"""
1824
function supports_graph_interface(::MOI.AbstractOptimizer)
1925
return false
2026
end

src/GraphViews/bipartite.jl

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@ mutable struct BipartiteGraph <: Graphs.AbstractGraph{Int64}
88
vertexset1::Vector{Int64}
99
vertexset2::Vector{Int64}
1010
end
11+
"""
12+
BipartiteGraph()
13+
14+
Construct an empty `BipartiteGraph` with no vertices or edges.
15+
"""
1116
function BipartiteGraph()
1217
return BipartiteGraph(Graphs.Graph(), Vector{Int64}(), Vector{Int64}())
1318
end
1419

20+
"""
21+
Graphs.add_vertex!(bgraph::BipartiteGraph; bipartite=1)
22+
23+
Add a vertex to the bipartite graph. The `bipartite` keyword argument specifies
24+
which vertex set to add the vertex to (1 or 2). Returns the success status.
25+
"""
1526
function Graphs.add_vertex!(bgraph::BipartiteGraph; bipartite=1)
1627
added = Graphs.add_vertex!(bgraph.graph)
1728
vertex = Graphs.nv(bgraph.graph)
@@ -24,34 +35,91 @@ function Graphs.add_vertex!(bgraph::BipartiteGraph; bipartite=1)
2435
return added
2536
end
2637

38+
"""
39+
Graphs.add_edge!(bgraph::BipartiteGraph, from::Int64, to::Int64)
40+
41+
Add an edge between vertices `from` and `to`. Enforces bipartite structure by
42+
requiring that the vertices be in different vertex sets.
43+
"""
2744
function Graphs.add_edge!(bgraph::BipartiteGraph, from::Int64, to::Int64)
2845
length(intersect((from, to), bgraph.vertexset1)) == 1 ||
2946
error("$from and $to must be in separate vertex sets")
3047
return Graphs.add_edge!(bgraph.graph, from, to)
3148
end
3249

50+
"""
51+
Graphs.edges(bgraph::BipartiteGraph)
52+
53+
Return an iterator over all edges in the bipartite graph.
54+
"""
3355
Graphs.edges(bgraph::BipartiteGraph) = Graphs.edges(bgraph.graph)
3456

57+
"""
58+
Graphs.edgetype(bgraph::BipartiteGraph)
59+
60+
Return the edge type for a bipartite graph (`SimpleEdge{Int64}`).
61+
"""
3562
Graphs.edgetype(bgraph::BipartiteGraph) = Graphs.SimpleGraphs.SimpleEdge{Int64}
3663

64+
"""
65+
Graphs.has_edge(bgraph::BipartiteGraph, from::Int64, to::Int64)
66+
67+
Check if the bipartite graph has an edge from `from` to `to`.
68+
"""
3769
function Graphs.has_edge(bgraph::BipartiteGraph, from::Int64, to::Int64)
3870
return Graphs.has_edge(bgraph.graph, from, to)
3971
end
4072

73+
"""
74+
Graphs.has_vertex(bgraph::BipartiteGraph, v::Integer)
75+
76+
Check if the bipartite graph contains vertex `v`.
77+
"""
4178
function Graphs.has_vertex(bgraph::BipartiteGraph, v::Integer)
4279
return Graphs.has_vertex(bgraph.graph, v)
4380
end
4481

82+
"""
83+
Graphs.is_directed(bgraph::BipartiteGraph)
84+
85+
Bipartite graphs are undirected. Always returns `false`.
86+
"""
4587
Graphs.is_directed(bgraph::BipartiteGraph) = false
4688

89+
"""
90+
Graphs.is_directed(::Type{BipartiteGraph})
91+
92+
Bipartite graphs are undirected. Always returns `false`.
93+
"""
4794
Graphs.is_directed(::Type{BipartiteGraph}) = false
4895

96+
"""
97+
Graphs.ne(bgraph::BipartiteGraph)
98+
99+
Return the number of edges in the bipartite graph.
100+
"""
49101
Graphs.ne(bgraph::BipartiteGraph) = Graphs.ne(bgraph.graph)
50102

103+
"""
104+
Graphs.nv(bgraph::BipartiteGraph)
105+
106+
Return the number of vertices in the bipartite graph.
107+
"""
51108
Graphs.nv(bgraph::BipartiteGraph) = Graphs.nv(bgraph.graph)
52109

110+
"""
111+
Graphs.vertices(bgraph::BipartiteGraph)
112+
113+
Return a vector of all vertices in the bipartite graph.
114+
"""
53115
Graphs.vertices(bgraph::BipartiteGraph) = Graphs.vertices(bgraph.graph)
54116

117+
"""
118+
Graphs.adjacency_matrix(bgraph::BipartiteGraph)
119+
120+
Return the adjacency matrix of the bipartite graph. Rows correspond to vertices
121+
in the first set, columns correspond to vertices in the second set.
122+
"""
55123
function Graphs.adjacency_matrix(bgraph::BipartiteGraph)
56124
n_v1 = length(bgraph.vertexset1)
57125
n_v2 = length(bgraph.vertexset2)
@@ -62,6 +130,18 @@ function Graphs.adjacency_matrix(bgraph::BipartiteGraph)
62130
return A
63131
end
64132

133+
"""
134+
identify_separators(bgraph::BipartiteGraph, partitions::Vector; cut_selector=Graphs.degree)
135+
136+
Identify separator elements (cut vertices or cut edges) that separate the given `partitions`.
137+
The `cut_selector` parameter determines how to assign boundary elements to cuts. It can be:
138+
- A function (e.g., `Graphs.degree`) that compares element degrees
139+
- `:vertex` to always assign vertices as separators
140+
- `:edge` to always assign edges as separators
141+
142+
Returns a tuple `(partition_elements, cross_elements)` where `partition_elements` are the
143+
elements local to each partition and `cross_elements` are the separator elements.
144+
"""
65145
function identify_separators(
66146
bgraph::BipartiteGraph, partitions::Vector; cut_selector=Graphs.degree
67147
)
@@ -123,6 +203,21 @@ function identify_separators(
123203
return partition_elements, cross_elements
124204
end
125205

206+
"""
207+
induced_elements(bgraph::BipartiteGraph, partitions::Vector; cut_selector=Graphs.degree)
208+
209+
Get the induced elements for each partition (i.e., elements local to each partition,
210+
excluding separators). This is a convenience function that returns only the first element
211+
of `identify_separators`.
212+
213+
# Arguments
214+
- `bgraph::BipartiteGraph`: The bipartite graph
215+
- `partitions::Vector`: Vector of partitions
216+
- `cut_selector=Graphs.degree`: Selector for determining cut assignment (function, `:vertex`, or `:edge`)
217+
218+
# Returns
219+
A vector of vectors, where each inner vector contains the induced elements for that partition.
220+
"""
126221
function induced_elements(
127222
bgraph::BipartiteGraph, partitions::Vector; cut_selector=Graphs.degree
128223
)

0 commit comments

Comments
 (0)