1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
appellation: hypergraph <module>
authors: @FL03
*/
//! This module is heavily inspired by the `rshyper` crate.
//!
/// the [`hypergraph`] macro works to aide the in the creation of hypergraphs by allowing
/// users to define nodes and edges in a hypergraph in a more declarative way.
///
/// ## Example
///
/// ### Basic Usage
///
/// The `hypergraph` macro allows you to define nodes and edges in a hypergraph
///
/// ```rust
/// use hypergraphx::prelude::*;
/// // initialize a new undirected hypergraph
/// let mut graph = UndirectedHypergraph::<usize, usize>::new();
/// // use the macro to insert nodes and edges into the graph
/// hypergraph! {
/// graph {
/// nodes: {
/// let v0 = 0;
/// let v1 = 1;
/// let v2 = 10;
/// };
/// edges: {
/// let e0: [v0, v1];
/// [v0, v1, v2] = 10;
/// };
/// }
/// }
/// ```
///
/// or
///
/// ```rust
/// use hypergraph::prelude::*;
///
/// // use the macro to initialize a new hypergraph, then insert nodes and edges
/// hypergraph! {
/// let mut graph: UndirectedHypergraph<usize, usize> {
/// nodes: {
/// let v0 = 0;
/// let v1 = 1;
/// let v2 = 2;
/// };
/// edges: {
/// let e0: [v0, v1] = 5;
/// let e1: [v0, v2] = 7;
/// [v0, v1, v2] = 10;
/// };
/// }
/// }
/// The `hyperedge` macro streamlines the definition of hyperedges in a hypergraph.
///
/// ## Usage
///
/// The macro requires that you to pass a mutable reference to some hypergraph by first
/// defining the ident of the associated graph. Once declared, hyperedges are defined as `let`
/// statement within a block, where each statement defines a hyperedge by its name and the
/// vertices it connects. Instead of specifying the type of hyperedge, a slice of node indices
/// is used to define the edge consituents.
///
/// Edges may be declared without a binding as well.
///
/// ```ignore
/// hyperedge! {
/// ${graph} {
/// let ${edge_name}: [${vertex1}, ${vertex2}, ...] = ${weight};
/// },
/// ${graph} {
/// [${vertex1}, ${vertex2}, ...] = ${weight};
/// }
/// }
/// ```
///
) => ;
=> ;
=> ;
=> ;
=> ;
=> ;
}
/// the [`hypernode`] macro streamlines the process of inserting nodes into a hypergraph.
///
/// ## Usage
///
/// The macro requires that you to pass a mutable reference to some hypergraph by first
/// defining the ident of the associated graph. Once declared, hypernodes are defined as `let`
/// statement within a block, where each statement defines the identifier of a node.
/// Optionally, a weight may be specified for the hypernode by appending `= <weight>`.
///
/// ```ignore
/// hypernode! {
/// $graph: {
/// let $var:ident $(= $w:expr)?;
/// }
/// }
/// ```
///
/// ### Example
///
/// ```rust
/// use rshyper::HyperMap;
/// // initialize a new, undirected hypergraph
/// let mut graph = HyperMap::<usize, usize>::undirected();
/// // use the macro to insert nodes into the graph
/// rshyper::hypernode! {
/// graph {
/// let v0;
/// let v1;
/// let v2;
/// let v3 = 1;
/// let v4 = 2;
/// let v5 = 3;
/// }
/// }
/// ```