@@ -22,10 +22,32 @@ limitations under the License.
2222
2323#include " computational_dag_concept.hpp"
2424
25+ /* *
26+ * @file constructable_computational_dag_concept.hpp
27+ * @brief Concepts for Constructable and Modifiable Computational DAGs.
28+ *
29+ * This file defines concepts that validate whether a graph type supports dynamic construction
30+ * and modification of its structure and properties. This includes adding vertices and edges,
31+ * as well as setting weights and types for existing elements.
32+ *
33+ * These concepts are useful for algorithms that need to build or transform graphs,
34+ * such as graph generators or coarsening algorithms.
35+ */
2536
2637namespace osp {
2738
28- // modify vertices
39+ /* *
40+ * @brief Concept to check if vertex weights are modifiable.
41+ *
42+ * Requires:
43+ * - `set_vertex_work_weight(v, w)`
44+ * - `set_vertex_comm_weight(v, w)`
45+ * - `set_vertex_mem_weight(v, w)`
46+ *
47+ * Also requires the graph to be default constructible, copy/move constructible, and assignable.
48+ *
49+ * @tparam T The graph type.
50+ */
2951template <typename T, typename = void >
3052struct is_modifiable_cdag_vertex : std::false_type {};
3153
@@ -36,54 +58,83 @@ struct is_modifiable_cdag_vertex<
3658 decltype(std::declval<T>().set_vertex_mem_weight(std::declval<vertex_idx_t <T>>(), std::declval<v_memw_t<T>>()))>>
3759 : std::conjunction<is_computational_dag<T>,
3860 std::is_default_constructible<T>,
39- std::is_copy_constructible<T>,
40- std::is_move_constructible<T>,
61+ std::is_copy_constructible<T>,
62+ std::is_move_constructible<T>,
4163 std::is_copy_assignable<T>,
4264 std::is_move_assignable<T>> {};
4365
4466template <typename T>
4567inline constexpr bool is_modifiable_cdag_vertex_v = is_modifiable_cdag_vertex<T>::value;
4668
47- // add vertices
69+ /* *
70+ * @brief Concept to check if vertices can be added to the graph.
71+ *
72+ * Requires:
73+ * - `add_vertex(work_weight, comm_weight, mem_weight)`
74+ * - Constructibility from `vertex_idx_t` (for reserving size).
75+ *
76+ * @tparam T The graph type.
77+ */
4878template <typename T, typename = void >
4979struct is_constructable_cdag_vertex : std::false_type {};
5080
5181template <typename T>
5282struct is_constructable_cdag_vertex <
5383 T, std::void_t <decltype (std::declval<T>().add_vertex(std::declval<v_workw_t <T>>(), std::declval<v_commw_t <T>>(), std::declval<v_memw_t <T>>()))>>
54- : std::conjunction<is_modifiable_cdag_vertex<T>,
84+ : std::conjunction<is_modifiable_cdag_vertex<T>,
5585 std::is_constructible<T, vertex_idx_t <T>>> {};
5686
5787template <typename T>
5888inline constexpr bool is_constructable_cdag_vertex_v = is_constructable_cdag_vertex<T>::value;
5989
60- // modify vertices types
90+ /* *
91+ * @brief Concept to check if vertex types are modifiable.
92+ *
93+ * Requires:
94+ * - `set_vertex_type(v, type)`
95+ *
96+ * @tparam T The graph type.
97+ */
6198template <typename T, typename = void >
6299struct is_modifiable_cdag_typed_vertex : std::false_type {};
63100
64101template <typename T>
65102struct is_modifiable_cdag_typed_vertex <
66103 T, std::void_t <decltype (std::declval<T>().set_vertex_type(std::declval<vertex_idx_t <T>>(), std::declval<v_type_t <T>>()))>>
67- : std::conjunction<is_modifiable_cdag_vertex<T>,
104+ : std::conjunction<is_modifiable_cdag_vertex<T>,
68105 is_computational_dag_typed_vertices<T>> {}; // for default node type
69106
70107template <typename T>
71108inline constexpr bool is_modifiable_cdag_typed_vertex_v = is_modifiable_cdag_typed_vertex<T>::value;
72109
73- // add vertices with types
110+ /* *
111+ * @brief Concept to check if typed vertices can be added.
112+ *
113+ * Requires:
114+ * - `add_vertex(work, comm, mem, type)`
115+ *
116+ * @tparam T The graph type.
117+ */
74118template <typename T, typename = void >
75119struct is_constructable_cdag_typed_vertex : std::false_type {};
76120
77121template <typename T>
78122struct is_constructable_cdag_typed_vertex <
79123 T, std::void_t <decltype (std::declval<T>().add_vertex(std::declval<v_workw_t <T>>(), std::declval<v_commw_t <T>>(), std::declval<v_memw_t <T>>(), std::declval<v_type_t <T>>()))>>
80- : std::conjunction<is_constructable_cdag_vertex<T>,
124+ : std::conjunction<is_constructable_cdag_vertex<T>,
81125 is_modifiable_cdag_typed_vertex<T>> {}; // for default node type
82126
83127template <typename T>
84128inline constexpr bool is_constructable_cdag_typed_vertex_v = is_constructable_cdag_typed_vertex<T>::value;
85129
86- // add edges
130+ /* *
131+ * @brief Concept to check if edges can be added (unweighted).
132+ *
133+ * Requires:
134+ * - `add_edge(source, target)`
135+ *
136+ * @tparam T The graph type.
137+ */
87138template <typename T, typename = void >
88139struct is_constructable_cdag_edge : std::false_type {};
89140
@@ -95,7 +146,14 @@ struct is_constructable_cdag_edge<T, std::void_t<decltype(std::declval<T>().add_
95146template <typename T>
96147inline constexpr bool is_constructable_cdag_edge_v = is_constructable_cdag_edge<T>::value;
97148
98- // modify edges with comm costs
149+ /* *
150+ * @brief Concept to check if edge communication weights are modifiable.
151+ *
152+ * Requires:
153+ * - `set_edge_comm_weight(edge, weight)`
154+ *
155+ * @tparam T The graph type.
156+ */
99157template <typename T, typename = void >
100158struct is_modifiable_cdag_comm_edge : std::false_type {};
101159
@@ -107,20 +165,34 @@ struct is_modifiable_cdag_comm_edge<
107165template <typename T>
108166inline constexpr bool is_modifiable_cdag_comm_edge_v = is_modifiable_cdag_comm_edge<T>::value;
109167
110- // add edges with comm costs
168+ /* *
169+ * @brief Concept to check if weighted edges can be added.
170+ *
171+ * Requires:
172+ * - `add_edge(source, target, weight)`
173+ *
174+ * @tparam T The graph type.
175+ */
111176template <typename T, typename = void >
112177struct is_constructable_cdag_comm_edge : std::false_type {};
113178
114179template <typename T>
115180struct is_constructable_cdag_comm_edge <
116181 T, std::void_t <decltype (std::declval<T>().add_edge(std::declval<vertex_idx_t <T>>(), std::declval<vertex_idx_t <T>>(), std::declval<e_commw_t <T>>()))>>
117- : std::conjunction<is_constructable_cdag_edge<T>,
182+ : std::conjunction<is_constructable_cdag_edge<T>,
118183 is_computational_dag_edge_desc<T>,
119184 is_modifiable_cdag_comm_edge<T>> {}; // for default edge weight
120185
121186template <typename T>
122187inline constexpr bool is_constructable_cdag_comm_edge_v = is_constructable_cdag_comm_edge<T>::value;
123188
189+ /* *
190+ * @brief Concept for a fully constructable computational DAG.
191+ *
192+ * Combines `is_constructable_cdag_vertex` and `is_constructable_cdag_edge`.
193+ *
194+ * @tparam T The graph type.
195+ */
124196template <typename T, typename = void >
125197struct is_constructable_cdag : std::false_type {};
126198
@@ -131,6 +203,9 @@ struct is_constructable_cdag<T, std::void_t<>>
131203template <typename T>
132204inline constexpr bool is_constructable_cdag_v = is_constructable_cdag<T>::value;
133205
206+ /* *
207+ * @brief Helper trait to check if a graph can be directly constructed from a vertex count and a set of edges.
208+ */
134209template <typename T>
135210inline constexpr bool is_direct_constructable_cdag_v = std::is_constructible<T, vertex_idx_t <T>, std::set<std::pair<vertex_idx_t <T>, vertex_idx_t <T>>>>::value;
136211
0 commit comments