-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhypergraph.hpp
More file actions
1734 lines (1438 loc) · 61.9 KB
/
hypergraph.hpp
File metadata and controls
1734 lines (1438 loc) · 61.9 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2024-2026 Jakub Musiał
// This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl).
// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
#pragma once
#include "gl/attributes/force_inline.hpp"
#include "gl/traits.hpp"
#include "gl/types/core.hpp"
#include "hgl/constants.hpp"
#include "hgl/directional_tags.hpp"
#include "hgl/hypergraph_traits.hpp"
#include "hgl/impl/impl_tags.hpp"
#include "hgl/io/core.hpp"
#include "hgl/io/hypergraph_fmt_traits.hpp"
#include "hgl/util.hpp"
#include <algorithm>
#include <initializer_list>
#include <set>
#include <type_traits>
#include <vector>
namespace hgl {
template <traits::c_instantiation_of<hypergraph_traits> HypergraphTraits = hypergraph_traits<>>
class hypergraph;
// --- general hypergraph utility ---
namespace traits {
template <typename H>
concept c_hypergraph = c_instantiation_of<H, hypergraph>;
template <typename H>
concept c_undirected_hypergraph =
c_hypergraph<H> and std::same_as<typename H::directional_tag, undirected_t>;
template <typename H>
concept c_bf_directed_hypergraph =
c_hypergraph<H> and std::same_as<typename H::directional_tag, bf_directed_t>;
template <typename H>
concept c_list_hypergraph =
c_hypergraph<H> and c_hypergraph_list_impl<typename H::implementation_tag>;
template <typename H>
concept c_flat_list_hypergraph =
c_hypergraph<H> and c_hypergraph_flat_list_impl<typename H::implementation_tag>;
template <typename H>
concept c_incidence_list_hypergraph =
c_hypergraph<H> and c_hypergraph_incidence_list_impl<typename H::implementation_tag>;
template <typename H>
concept c_matrix_hypergraph =
c_hypergraph<H> and c_hypergraph_matrix_impl<typename H::implementation_tag>;
template <typename H>
concept c_incidence_matrix_hypergraph =
c_hypergraph<H> and c_hypergraph_incidence_matrix_impl<typename H::implementation_tag>;
} // namespace traits
template <traits::c_hypergraph Hypergraph>
[[nodiscard]] Hypergraph clone(const Hypergraph& source);
template <traits::c_hypergraph_impl_tag TargetImplTag, traits::c_hypergraph Hypergraph>
[[nodiscard]] auto to(Hypergraph&& source);
namespace detail {
template <traits::c_hypergraph_impl_tag TargetImplTag, traits::c_hypergraph_impl_tag SourceImplTag>
struct to_impl;
} // namespace detail
template <traits::c_instantiation_of<hypergraph_traits> HypergraphTraits>
class hypergraph final {
public:
using traits_type = HypergraphTraits;
using directional_tag = typename traits_type::directional_tag;
using implementation_tag = typename traits_type::implementation_tag;
using implementation_type =
typename implementation_tag::template implementation_type<directional_tag>;
using id_type = typename traits_type::id_type;
using vertex_type = typename traits_type::vertex_type;
using vertex_properties_type = typename traits_type::vertex_properties_type;
using vertex_properties_map_type = std::conditional_t<
traits::c_empty_properties<vertex_properties_type>,
empty_properties_map,
std::vector<vertex_properties_type>>;
using hyperedge_type = typename traits_type::hyperedge_type;
using hyperedge_properties_type = typename traits_type::hyperedge_properties_type;
using hyperedge_properties_map_type = std::conditional_t<
traits::c_empty_properties<hyperedge_properties_type>,
empty_properties_map,
std::vector<hyperedge_properties_type>>;
hypergraph& operator=(const hypergraph&) = delete;
explicit hypergraph(const size_type n_vertices = 0uz, const size_type n_hyperedges = 0uz)
: _n_vertices(n_vertices), _n_hyperedges(n_hyperedges), _impl(n_vertices, n_hyperedges) {
if constexpr (traits::c_non_empty_properties<vertex_properties_type>)
this->_vertex_properties.resize(n_vertices);
if constexpr (traits::c_non_empty_properties<hyperedge_properties_type>)
this->_hyperedge_properties.resize(n_hyperedges);
}
hypergraph(hypergraph&&) noexcept = default;
hypergraph& operator=(hypergraph&&) noexcept = default;
~hypergraph() = default;
// --- size methods ---
[[nodiscard]] gl_attr_force_inline size_type n_vertices() const noexcept {
return this->_n_vertices;
}
[[nodiscard]] gl_attr_force_inline size_type n_hyperedges() const noexcept {
return this->_n_hyperedges;
}
// --- vertex modifiers ---
vertex_type add_vertex() {
this->_impl.add_vertices(1uz);
const auto new_vertex_id = static_cast<id_type>(this->_n_vertices++);
if constexpr (traits::c_non_empty_properties<vertex_properties_type>)
return vertex_type{new_vertex_id, this->_vertex_properties.emplace_back()};
else
return vertex_type{new_vertex_id};
}
vertex_type add_vertex_with(vertex_properties_type properties)
requires(traits::c_non_empty_properties<vertex_properties_type>)
{
this->_impl.add_vertices(1uz);
return vertex_type{
static_cast<id_type>(this->_n_vertices++),
this->_vertex_properties.emplace_back(std::move(properties))
};
}
void add_vertices(const size_type n) {
this->_impl.add_vertices(n);
this->_n_vertices += n;
if constexpr (traits::c_non_empty_properties<vertex_properties_type>)
this->_vertex_properties.resize(this->_n_vertices);
}
void add_vertices_with(
const traits::c_sized_range_of<vertex_properties_type> auto& properties_rng
)
requires(traits::c_non_empty_properties<vertex_properties_type>)
{
const auto n = std::ranges::size(properties_rng);
this->_impl.add_vertices(n);
this->_n_vertices += n;
if constexpr (traits::c_non_empty_properties<vertex_properties_type>)
this->_vertex_properties.insert(
this->_vertex_properties.end(),
std::ranges::begin(properties_rng),
std::ranges::end(properties_rng)
);
}
gl_attr_force_inline void remove_vertex(const id_type vertex_id) {
this->_remove_vertex_impl(vertex_id);
}
gl_attr_force_inline void remove_vertex(const vertex_type& vertex) {
this->remove_vertex(vertex.id());
}
void remove_vertices_from(const traits::c_forward_range_of<id_type> auto& vertex_id_rng) {
// sorts ids in a descending n_vertices and removes duplicate ids
std::set<id_type, std::greater<id_type>> vertex_id_set(
std::ranges::begin(vertex_id_rng), std::ranges::end(vertex_id_rng)
);
// TODO: optimize
for (const auto vertex_id : vertex_id_set)
this->_remove_vertex_impl(vertex_id);
}
void remove_vertices_from(const traits::c_sized_range_of<vertex_type> auto& vertex_rng) {
// sort vertices in a descending n_vertices (by id) and removes duplicate ids
std::set<vertex_type, std::greater<vertex_type>> vertex_set(
std::ranges::begin(vertex_rng), std::ranges::end(vertex_rng)
);
// TODO: optimize
for (const auto& vertex : vertex_set)
this->_remove_vertex_impl(vertex.id());
}
// --- vertex getters ---
[[nodiscard]] gl_attr_force_inline bool has_vertex(const id_type vertex_id) const {
return vertex_id < this->_n_vertices;
}
[[nodiscard]] gl_attr_force_inline bool has_vertex(const vertex_type& vertex) const {
return this->has_vertex(vertex.id());
}
[[nodiscard]] vertex_type vertex(const id_type vertex_id) const {
this->_verify_vertex_id(vertex_id);
return this->vertex_unchecked(vertex_id);
}
[[nodiscard]] gl_attr_force_inline vertex_type at(vertex_t, const id_type vertex_id) const {
return this->vertex(vertex_id);
}
[[nodiscard]] gl_attr_force_inline vertex_type vertex_unchecked(const id_type vertex_id) const {
if constexpr (traits::c_non_empty_properties<vertex_properties_type>)
return vertex_type{vertex_id, this->_vertex_properties[vertex_id]};
else
return vertex_type{vertex_id};
}
[[nodiscard]] gl_attr_force_inline vertex_type
operator[](vertex_t, const id_type vertex_id) const {
return this->vertex_unchecked(vertex_id);
}
[[nodiscard]] gl_attr_force_inline auto vertices() const noexcept {
return this->vertex_ids() | std::views::transform(this->_create_vertex_descriptor());
}
[[nodiscard]] gl_attr_force_inline auto vertex_ids() const noexcept {
return std::views::iota(initial_id_v<id_type>, this->_n_vertices);
}
[[nodiscard]] gl_attr_force_inline vertex_properties_type& vertex_properties(
const id_type vertex_id
) const
requires(traits::c_non_empty_properties<vertex_properties_type>)
{
this->_verify_vertex_id(vertex_id);
return this->_vertex_properties[vertex_id];
}
[[nodiscard]] gl_attr_force_inline auto vertex_properties_map() const noexcept
requires(traits::c_non_empty_properties<vertex_properties_type>)
{
return std::views::all(this->_vertex_properties);
}
// --- hyperedge modifiers ---
hyperedge_type add_hyperedge() {
this->_impl.add_hyperedges(1uz);
const auto new_hyperedge_id = static_cast<id_type>(this->_n_hyperedges++);
if constexpr (traits::c_non_empty_properties<hyperedge_properties_type>)
return hyperedge_type{new_hyperedge_id, this->_hyperedge_properties.emplace_back()};
else
return hyperedge_type{new_hyperedge_id};
}
hyperedge_type add_hyperedge_with(hyperedge_properties_type properties)
requires(traits::c_non_empty_properties<hyperedge_properties_type>)
{
this->_impl.add_hyperedges(1uz);
return hyperedge_type{
static_cast<id_type>(this->_n_hyperedges++),
this->_hyperedge_properties.emplace_back(std::move(properties))
};
}
hyperedge_type add_hyperedge(const traits::c_forward_range_of<id_type> auto& vertex_id_rng)
requires std::same_as<directional_tag, undirected_t>
{
auto he = this->add_hyperedge();
this->bind(vertex_id_rng, he.id());
return he;
}
gl_attr_force_inline hyperedge_type add_hyperedge(std::initializer_list<id_type> vertex_ids)
requires std::same_as<directional_tag, undirected_t>
{
return this->add_hyperedge(std::views::all(vertex_ids));
}
gl_attr_force_inline hyperedge_type
add_hyperedge(const traits::c_forward_range_of<vertex_type> auto& vertex_rng)
requires std::same_as<directional_tag, undirected_t>
{
return this->add_hyperedge(vertex_rng | std::views::transform(&vertex_type::id));
}
gl_attr_force_inline hyperedge_type add_hyperedge(std::initializer_list<vertex_type> vertices)
requires std::same_as<directional_tag, undirected_t>
{
return this->add_hyperedge(std::views::all(vertices));
}
hyperedge_type add_hyperedge_with(
const traits::c_forward_range_of<id_type> auto& vertex_id_rng,
hyperedge_properties_type properties
)
requires(std::same_as<directional_tag, undirected_t> and traits::c_non_empty_properties<hyperedge_properties_type>)
{
auto he = this->add_hyperedge_with(std::move(properties));
this->bind(vertex_id_rng, he.id());
return he;
}
hyperedge_type add_hyperedge_with(
std::initializer_list<id_type> vertex_ids, hyperedge_properties_type properties
)
requires(std::same_as<directional_tag, undirected_t> and traits::c_non_empty_properties<hyperedge_properties_type>)
{
return this->add_hyperedge_with(std::views::all(vertex_ids), std::move(properties));
}
gl_attr_force_inline hyperedge_type add_hyperedge_with(
const traits::c_forward_range_of<vertex_type> auto& vertex_rng,
hyperedge_properties_type properties
)
requires(std::same_as<directional_tag, undirected_t> and traits::c_non_empty_properties<hyperedge_properties_type>)
{
return this->add_hyperedge_with(
vertex_rng | std::views::transform(&vertex_type::id), std::move(properties)
);
}
hyperedge_type add_hyperedge_with(
std::initializer_list<vertex_type> vertices, hyperedge_properties_type properties
)
requires(std::same_as<directional_tag, undirected_t> and traits::c_non_empty_properties<hyperedge_properties_type>)
{
return this->add_hyperedge_with(std::views::all(vertices), std::move(properties));
}
hyperedge_type add_hyperedge(
const traits::c_forward_range_of<id_type> auto& tail_id_rng,
const traits::c_forward_range_of<id_type> auto& head_id_rng
)
requires std::same_as<directional_tag, bf_directed_t>
{
auto he = this->add_hyperedge();
this->bind_tail(tail_id_rng, he.id());
this->bind_head(head_id_rng, he.id());
return he;
}
gl_attr_force_inline hyperedge_type
add_hyperedge(std::initializer_list<id_type> tail_ids, std::initializer_list<id_type> head_ids)
requires std::same_as<directional_tag, bf_directed_t>
{
return this->add_hyperedge(std::views::all(tail_ids), std::views::all(head_ids));
}
gl_attr_force_inline hyperedge_type add_hyperedge(
const traits::c_forward_range_of<vertex_type> auto& tail_rng,
const traits::c_forward_range_of<vertex_type> auto& head_rng
)
requires std::same_as<directional_tag, bf_directed_t>
{
return this->add_hyperedge(
tail_rng | std::views::transform(&vertex_type::id),
head_rng | std::views::transform(&vertex_type::id)
);
}
gl_attr_force_inline hyperedge_type
add_hyperedge(std::initializer_list<vertex_type> tail, std::initializer_list<vertex_type> head)
requires std::same_as<directional_tag, bf_directed_t>
{
return this->add_hyperedge(std::views::all(tail), std::views::all(head));
}
hyperedge_type add_hyperedge_with(
const traits::c_forward_range_of<id_type> auto& tail_id_rng,
const traits::c_forward_range_of<id_type> auto& head_id_rng,
hyperedge_properties_type properties
)
requires(std::same_as<directional_tag, bf_directed_t> and traits::c_non_empty_properties<hyperedge_properties_type>)
{
auto he = this->add_hyperedge_with(std::move(properties));
this->bind_tail(tail_id_rng, he.id());
this->bind_head(head_id_rng, he.id());
return he;
}
gl_attr_force_inline hyperedge_type add_hyperedge_with(
std::initializer_list<id_type> tail_ids,
std::initializer_list<id_type> head_ids,
hyperedge_properties_type properties
)
requires(std::same_as<directional_tag, bf_directed_t> and traits::c_non_empty_properties<hyperedge_properties_type>)
{
return this->add_hyperedge_with(
std::views::all(tail_ids), std::views::all(head_ids), std::move(properties)
);
}
gl_attr_force_inline hyperedge_type add_hyperedge_with(
const traits::c_forward_range_of<vertex_type> auto& tail_rng,
const traits::c_forward_range_of<vertex_type> auto& head_rng,
hyperedge_properties_type properties
)
requires(std::same_as<directional_tag, bf_directed_t> and traits::c_non_empty_properties<hyperedge_properties_type>)
{
return this->add_hyperedge_with(
tail_rng | std::views::transform(&vertex_type::id),
head_rng | std::views::transform(&vertex_type::id),
std::move(properties)
);
}
gl_attr_force_inline hyperedge_type add_hyperedge_with(
std::initializer_list<vertex_type> tail,
std::initializer_list<vertex_type> head,
hyperedge_properties_type properties
)
requires(std::same_as<directional_tag, bf_directed_t> and traits::c_non_empty_properties<hyperedge_properties_type>)
{
return this->add_hyperedge_with(
std::views::all(tail), std::views::all(head), std::move(properties)
);
}
void add_hyperedges(const size_type n) {
this->_impl.add_hyperedges(n);
this->_n_hyperedges += n;
if constexpr (traits::c_non_empty_properties<hyperedge_properties_type>)
this->_hyperedge_properties.resize(this->_n_hyperedges);
}
void add_hyperedges_with(
const traits::c_sized_range_of<hyperedge_properties_type> auto& properties_rng
)
requires(traits::c_non_empty_properties<hyperedge_properties_type>)
{
const auto n = std::ranges::size(properties_rng);
this->_impl.add_hyperedges(n);
this->_n_hyperedges += n;
if constexpr (traits::c_non_empty_properties<hyperedge_properties_type>)
this->_hyperedge_properties.insert(
this->_hyperedge_properties.end(),
std::ranges::begin(properties_rng),
std::ranges::end(properties_rng)
);
}
gl_attr_force_inline void remove_hyperedge(const id_type hyperedge_id) {
this->_remove_hyperedge_impl(hyperedge_id);
}
gl_attr_force_inline void remove_hyperedge(const hyperedge_type& hyperedge) {
this->remove_hyperedge(hyperedge.id());
}
void remove_hyperedges_from(const traits::c_forward_range_of<id_type> auto& hyperedge_id_rng) {
// sorts ids in a descending n_vertices and removes duplicate ids
std::set<id_type, std::greater<id_type>> hyperedge_id_set(
std::ranges::begin(hyperedge_id_rng), std::ranges::end(hyperedge_id_rng)
);
// TODO: optimize
for (const auto hyperedge_id : hyperedge_id_set)
this->_remove_hyperedge_impl(hyperedge_id);
}
void remove_hyperedges_from(const traits::c_sized_range_of<hyperedge_type> auto& hyperedge_rng
) {
// sort hyperedges in a descending n_vertices (by id) and removes duplicate ids
std::set<hyperedge_type, std::greater<hyperedge_type>> hyperedge_set(
std::ranges::begin(hyperedge_rng), std::ranges::end(hyperedge_rng)
);
// TODO: optimize
for (const auto& hyperedge : hyperedge_set)
this->_remove_hyperedge_impl(hyperedge.id());
}
// --- hyperedge getters ---
[[nodiscard]] gl_attr_force_inline bool has_hyperedge(const id_type hyperedge_id) const {
return hyperedge_id < this->_n_hyperedges;
}
[[nodiscard]] gl_attr_force_inline bool has_hyperedge(const hyperedge_type& hyperedge) const {
return this->has_hyperedge(hyperedge.id());
}
[[nodiscard]] hyperedge_type hyperedge(const id_type hyperedge_id) const {
this->_verify_hyperedge_id(hyperedge_id);
return this->hyperedge_unchecked(hyperedge_id);
}
[[nodiscard]] gl_attr_force_inline hyperedge_type
at(hyperedge_t, const id_type hyperedge_id) const {
return this->hyperedge(hyperedge_id);
}
[[nodiscard]] gl_attr_force_inline hyperedge_type hyperedge_unchecked(const id_type hyperedge_id
) const {
if constexpr (traits::c_non_empty_properties<hyperedge_properties_type>)
return hyperedge_type{hyperedge_id, this->_hyperedge_properties[hyperedge_id]};
else
return hyperedge_type{hyperedge_id};
}
[[nodiscard]] gl_attr_force_inline hyperedge_type
operator[](hyperedge_t, const id_type hyperedge_id) const {
return this->hyperedge_unchecked(hyperedge_id);
}
[[nodiscard]] gl_attr_force_inline auto hyperedges() const noexcept {
return this->hyperedge_ids() | std::views::transform(this->_create_hyperedge_descriptor());
}
[[nodiscard]] gl_attr_force_inline auto hyperedge_ids() const noexcept {
return std::views::iota(initial_id_v<id_type>, this->_n_hyperedges);
}
[[nodiscard]] gl_attr_force_inline hyperedge_properties_type& hyperedge_properties(
const id_type id
) const
requires(traits::c_non_empty_properties<hyperedge_properties_type>)
{
this->_verify_hyperedge_id(id);
return this->_hyperedge_properties[id];
}
[[nodiscard]] gl_attr_force_inline auto hyperedge_properties_map() const noexcept
requires(traits::c_non_empty_properties<hyperedge_properties_type>)
{
return std::views::all(this->_hyperedge_properties);
}
// --- incidence modifiers ---
void bind(const id_type vertex_id, const id_type hyperedge_id)
requires std::same_as<directional_tag, undirected_t>
{
this->_verify_vertex_id(vertex_id);
this->_verify_hyperedge_id(hyperedge_id);
this->_impl.bind(vertex_id, hyperedge_id);
}
gl_attr_force_inline void bind(const vertex_type& vertex, const hyperedge_type& hyperedge)
requires std::same_as<directional_tag, undirected_t>
{
this->bind(vertex.id(), hyperedge.id());
}
void bind(
const traits::c_forward_range_of<id_type> auto& vertex_id_rng, const id_type hyperedge_id
)
requires std::same_as<directional_tag, undirected_t>
{
this->_verify_hyperedge_id(hyperedge_id);
for (const auto vertex_id : vertex_id_rng) {
this->_verify_vertex_id(vertex_id);
this->_impl.bind(vertex_id, hyperedge_id);
}
}
gl_attr_force_inline void bind(
std::initializer_list<id_type> vertex_ids, const id_type hyperedge_id
)
requires std::same_as<directional_tag, undirected_t>
{
this->bind(std::views::all(vertex_ids), hyperedge_id);
}
gl_attr_force_inline void bind(
const traits::c_forward_range_of<vertex_type> auto& vertex_rng,
const hyperedge_type& hyperedge
)
requires std::same_as<directional_tag, undirected_t>
{
this->bind(vertex_rng | std::views::transform(&vertex_type::id), hyperedge.id());
}
gl_attr_force_inline void bind(
std::initializer_list<vertex_type> vertices, const hyperedge_type& hyperedge
)
requires std::same_as<directional_tag, undirected_t>
{
this->bind(std::views::all(vertices), hyperedge);
}
void bind(
const id_type vertex_id, const traits::c_forward_range_of<id_type> auto& hyperedge_id_rng
)
requires std::same_as<directional_tag, undirected_t>
{
this->_verify_vertex_id(vertex_id);
for (const auto hyperedge_id : hyperedge_id_rng) {
this->_verify_hyperedge_id(hyperedge_id);
this->_impl.bind(vertex_id, hyperedge_id);
}
}
gl_attr_force_inline void bind(
const id_type vertex_id, std::initializer_list<id_type> hyperedge_ids
)
requires std::same_as<directional_tag, undirected_t>
{
this->bind(vertex_id, std::views::all(hyperedge_ids));
}
gl_attr_force_inline void bind(
const vertex_type& vertex,
const traits::c_forward_range_of<hyperedge_type> auto& hyperedge_rng
)
requires std::same_as<directional_tag, undirected_t>
{
this->bind(vertex.id(), hyperedge_rng | std::views::transform(&hyperedge_type::id));
}
gl_attr_force_inline void bind(
const vertex_type& vertex, std::initializer_list<hyperedge_type> hyperedges
)
requires std::same_as<directional_tag, undirected_t>
{
this->bind(vertex, std::views::all(hyperedges));
}
void bind_tail(const id_type vertex_id, const id_type hyperedge_id)
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_vertex_id(vertex_id);
this->_verify_hyperedge_id(hyperedge_id);
this->_impl.bind_tail(vertex_id, hyperedge_id);
}
gl_attr_force_inline void bind_tail(const vertex_type& vertex, const hyperedge_type& hyperedge)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_tail(vertex.id(), hyperedge.id());
}
void bind_tail(
const traits::c_forward_range_of<id_type> auto& vertex_id_rng, const id_type hyperedge_id
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_hyperedge_id(hyperedge_id);
for (const auto vertex_id : vertex_id_rng) {
this->_verify_vertex_id(vertex_id);
this->_impl.bind_tail(vertex_id, hyperedge_id);
}
}
gl_attr_force_inline void bind_tail(
std::initializer_list<id_type> vertex_ids, const id_type hyperedge_id
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_tail(std::views::all(vertex_ids), hyperedge_id);
}
gl_attr_force_inline void bind_tail(
const traits::c_forward_range_of<vertex_type> auto& vertex_rng,
const hyperedge_type& hyperedge
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_tail(vertex_rng | std::views::transform(&vertex_type::id), hyperedge.id());
}
gl_attr_force_inline void bind_tail(
std::initializer_list<vertex_type> vertices, const hyperedge_type& hyperedge
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_tail(std::views::all(vertices), hyperedge);
}
void bind_tail(
const id_type vertex_id, const traits::c_forward_range_of<id_type> auto& hyperedge_id_rng
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_vertex_id(vertex_id);
for (const auto hyperedge_id : hyperedge_id_rng) {
this->_verify_hyperedge_id(hyperedge_id);
this->_impl.bind_tail(vertex_id, hyperedge_id);
}
}
gl_attr_force_inline void bind_tail(
const id_type vertex_id, std::initializer_list<id_type> hyperedge_ids
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_tail(vertex_id, std::views::all(hyperedge_ids));
}
gl_attr_force_inline void bind_tail(
const vertex_type& vertex,
const traits::c_forward_range_of<hyperedge_type> auto& hyperedge_rng
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_tail(vertex.id(), hyperedge_rng | std::views::transform(&hyperedge_type::id));
}
gl_attr_force_inline void bind_tail(
const vertex_type& vertex, std::initializer_list<hyperedge_type> hyperedges
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_tail(vertex, std::views::all(hyperedges));
}
void bind_head(const id_type vertex_id, const id_type hyperedge_id)
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_vertex_id(vertex_id);
this->_verify_hyperedge_id(hyperedge_id);
this->_impl.bind_head(vertex_id, hyperedge_id);
}
gl_attr_force_inline void bind_head(const vertex_type& vertex, const hyperedge_type& hyperedge)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_head(vertex.id(), hyperedge.id());
}
void bind_head(
const traits::c_forward_range_of<id_type> auto& vertex_id_rng, const id_type hyperedge_id
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_hyperedge_id(hyperedge_id);
for (const auto vertex_id : vertex_id_rng) {
this->_verify_vertex_id(vertex_id);
this->_impl.bind_head(vertex_id, hyperedge_id);
}
}
gl_attr_force_inline void bind_head(
std::initializer_list<id_type> vertex_ids, const id_type hyperedge_id
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_head(std::views::all(vertex_ids), hyperedge_id);
}
gl_attr_force_inline void bind_head(
const traits::c_forward_range_of<vertex_type> auto& vertex_rng,
const hyperedge_type& hyperedge
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_head(vertex_rng | std::views::transform(&vertex_type::id), hyperedge.id());
}
gl_attr_force_inline void bind_head(
std::initializer_list<vertex_type> vertices, const hyperedge_type& hyperedge
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_head(std::views::all(vertices), hyperedge);
}
void bind_head(
const id_type vertex_id, const traits::c_forward_range_of<id_type> auto& hyperedge_id_rng
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_vertex_id(vertex_id);
for (const auto hyperedge_id : hyperedge_id_rng) {
this->_verify_hyperedge_id(hyperedge_id);
this->_impl.bind_head(vertex_id, hyperedge_id);
}
}
gl_attr_force_inline void bind_head(
const id_type vertex_id, std::initializer_list<id_type> hyperedge_ids
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_head(vertex_id, std::views::all(hyperedge_ids));
}
gl_attr_force_inline void bind_head(
const vertex_type& vertex,
const traits::c_forward_range_of<hyperedge_type> auto& hyperedge_rng
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_head(vertex.id(), hyperedge_rng | std::views::transform(&hyperedge_type::id));
}
gl_attr_force_inline void bind_head(
const vertex_type& vertex, std::initializer_list<hyperedge_type> hyperedges
)
requires std::same_as<directional_tag, bf_directed_t>
{
this->bind_head(vertex, std::views::all(hyperedges));
}
void unbind(const id_type vertex_id, const id_type hyperedge_id) {
this->_verify_vertex_id(vertex_id);
this->_verify_hyperedge_id(hyperedge_id);
this->_impl.unbind(vertex_id, hyperedge_id);
}
gl_attr_force_inline void unbind(const vertex_type& vertex, const hyperedge_type& hyperedge) {
this->unbind(vertex.id(), hyperedge.id());
}
// --- incidence validators ---
[[nodiscard]] bool are_incident(const id_type vertex_id, const id_type hyperedge_id) const {
this->_verify_vertex_id(vertex_id);
this->_verify_hyperedge_id(hyperedge_id);
return this->_impl.are_bound(vertex_id, hyperedge_id);
}
[[nodiscard]] gl_attr_force_inline bool are_incident(
const vertex_type& vertex, const hyperedge_type& hyperedge
) const {
return this->are_incident(vertex.id(), hyperedge.id());
}
[[nodiscard]] bool is_tail(const id_type vertex_id, const id_type hyperedge_id) const
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_vertex_id(vertex_id);
this->_verify_hyperedge_id(hyperedge_id);
return this->_impl.is_tail(vertex_id, hyperedge_id);
}
[[nodiscard]] gl_attr_force_inline bool is_tail(
const vertex_type& vertex, const hyperedge_type& hyperedge
) const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->is_tail(vertex.id(), hyperedge.id());
}
[[nodiscard]] bool is_head(const id_type vertex_id, const id_type hyperedge_id) const
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_vertex_id(vertex_id);
this->_verify_hyperedge_id(hyperedge_id);
return this->_impl.is_head(vertex_id, hyperedge_id);
}
[[nodiscard]] gl_attr_force_inline bool is_head(
const vertex_type& vertex, const hyperedge_type& hyperedge
) const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->is_head(vertex.id(), hyperedge.id());
}
// --- incidence getters ---
[[nodiscard]] gl_attr_force_inline auto incident_hyperedges(const id_type vertex_id) {
return this->incident_hyperedge_ids(vertex_id)
| std::views::transform(this->_create_hyperedge_descriptor());
}
[[nodiscard]] gl_attr_force_inline auto incident_hyperedges(const vertex_type& vertex) {
return this->incident_hyperedges(vertex.id());
}
[[nodiscard]] auto incident_hyperedge_ids(const id_type vertex_id) const {
this->_verify_vertex_id(vertex_id);
return this->_impl.incident_hyperedges(vertex_id);
}
[[nodiscard]] gl_attr_force_inline auto incident_hyperedge_ids(const vertex_type& vertex
) const {
return this->incident_hyperedge_ids(vertex.id());
}
[[nodiscard]] size_type degree(const id_type vertex_id) const {
this->_verify_vertex_id(vertex_id);
return this->_impl.degree(vertex_id);
}
[[nodiscard]] gl_attr_force_inline size_type degree(const vertex_type& vertex) const {
return this->degree(vertex.id());
}
[[nodiscard]] std::vector<size_type> degree_map() const {
return this->_impl.degree_map(this->_n_vertices);
}
[[nodiscard]] gl_attr_force_inline auto out_hyperedges(const id_type vertex_id) const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->out_hyperedge_ids(vertex_id)
| std::views::transform(this->_create_hyperedge_descriptor());
}
[[nodiscard]] gl_attr_force_inline auto out_hyperedges(const vertex_type& vertex) const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->out_hyperedges(vertex.id());
}
[[nodiscard]] auto out_hyperedge_ids(const id_type vertex_id) const
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_vertex_id(vertex_id);
return this->_impl.out_hyperedges(vertex_id);
}
[[nodiscard]] gl_attr_force_inline auto out_hyperedge_ids(const vertex_type& vertex) const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->out_hyperedge_ids(vertex.id());
}
[[nodiscard]] size_type out_degree(const id_type vertex_id) const
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_vertex_id(vertex_id);
return this->_impl.out_degree(vertex_id);
}
[[nodiscard]] gl_attr_force_inline size_type out_degree(const vertex_type& vertex) const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->out_degree(vertex.id());
}
[[nodiscard]] std::vector<size_type> out_degree_map() const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->_impl.out_degree_map(this->_n_vertices);
}
[[nodiscard]] gl_attr_force_inline auto in_hyperedges(const id_type vertex_id) const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->in_hyperedge_ids(vertex_id)
| std::views::transform(this->_create_hyperedge_descriptor());
}
[[nodiscard]] gl_attr_force_inline auto in_hyperedges(const vertex_type& vertex) const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->in_hyperedges(vertex.id());
}
[[nodiscard]] auto in_hyperedge_ids(const id_type vertex_id) const
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_vertex_id(vertex_id);
return this->_impl.in_hyperedges(vertex_id);
}
[[nodiscard]] gl_attr_force_inline auto in_hyperedge_ids(const vertex_type& vertex) const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->in_hyperedge_ids(vertex.id());
}
[[nodiscard]] size_type in_degree(const id_type vertex_id) const
requires std::same_as<directional_tag, bf_directed_t>
{
this->_verify_vertex_id(vertex_id);
return this->_impl.in_degree(vertex_id);
}
[[nodiscard]] gl_attr_force_inline size_type in_degree(const vertex_type& vertex) const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->in_degree(vertex.id());
}
[[nodiscard]] std::vector<size_type> in_degree_map() const
requires std::same_as<directional_tag, bf_directed_t>
{
return this->_impl.in_degree_map(this->_n_vertices);
}
[[nodiscard]] auto incident_vertices(const id_type hyperedge_id) const {
return this->incident_vertex_ids(hyperedge_id)
| std::views::transform(this->_create_vertex_descriptor());
}
[[nodiscard]] gl_attr_force_inline auto incident_vertices(const hyperedge_type& hyperedge