-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
2932 lines (2682 loc) · 151 KB
/
CMakeLists.txt
File metadata and controls
2932 lines (2682 loc) · 151 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
cmake_minimum_required(VERSION 3.15)
project(chszlablib LANGUAGES C CXX)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(pybind11 CONFIG REQUIRED)
find_package(OpenMP)
# On macOS with Homebrew libomp, CMake's FindOpenMP may not populate
# OpenMP_CXX_INCLUDE_DIRS. Propagate it when available.
if(OpenMP_CXX_FOUND AND OpenMP_CXX_INCLUDE_DIRS)
include_directories(SYSTEM ${OpenMP_CXX_INCLUDE_DIRS})
endif()
# Several bundled C++ libraries use APIs removed in C++17 (std::random_shuffle,
# std::binary_function, std::unary_function). On Apple Clang with libc++ these
# are hard errors. Re-enable them globally.
add_compile_definitions(
_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
)
# GCC 10 (manylinux_2_17) has a template ordering bug: std::pair may be
# instantiated before <utility> defines __is_tuple_like_impl specialization,
# causing a hard error. -fpermissive downgrades it to a warning.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "11")
add_compile_options(-fpermissive)
endif()
# KaMIS's bundled KaHIP uses `using namespace __gnu_cxx;` which doesn't exist
# on Apple Clang. Force-include a header that provides an empty namespace.
# Also provide shims for GCC-only headers like <parallel/numeric>.
if(NOT MSVC)
add_compile_options("SHELL:-include ${CMAKE_CURRENT_SOURCE_DIR}/cmake/compat_gnu_cxx.h")
endif()
include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# MSVC compatibility: enable alternative operator tokens and suppress warnings.
if(MSVC)
add_compile_options(/FIiso646.h /W0 /permissive-)
endif()
# =============================================================================
# MQLib (for fpt-max-cut; must come BEFORE the global -include cstdint
# workaround which breaks MQLib's older C++ code)
# =============================================================================
set(FPT_MAXCUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_repositories/fpt-max-cut)
set(MQLIB_DIR ${FPT_MAXCUT_DIR}/solvers/MQLib)
file(GLOB_RECURSE MQLIB_SOURCES ${MQLIB_DIR}/src/*.cpp)
list(FILTER MQLIB_SOURCES EXCLUDE REGEX "main\\.cpp$")
add_library(mqlib_static STATIC ${MQLIB_SOURCES})
target_include_directories(mqlib_static PUBLIC ${MQLIB_DIR}/include)
if(MSVC)
target_compile_options(mqlib_static PRIVATE /FIcstdint /FIlimits)
else()
target_compile_options(mqlib_static PRIVATE -w -O2
"SHELL:-include cstdint"
"SHELL:-include limits"
)
endif()
# Fix missing <cstdint> includes in older tlx/VieCut headers on newer compilers
if(NOT MSVC)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-include;cstdint>")
else()
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/FIcstdint>")
endif()
# =============================================================================
# KaHIP (provides kahip_static target)
# =============================================================================
set(NOMPI ON CACHE BOOL "" FORCE)
set(NONATIVEOPTIMIZATIONS ON CACHE BOOL "" FORCE)
set(PARHIP OFF CACHE BOOL "" FORCE)
set(BUILDPYTHONMODULE OFF CACHE BOOL "" FORCE)
add_subdirectory(external_repositories/KaHIP EXCLUDE_FROM_ALL)
# =============================================================================
# VieClus (built manually to avoid target-name conflicts with KaHIP)
# =============================================================================
# VieClus carries its own copy of KaHIP sources under extern/KaHIP.
# We compile everything into a single static library.
set(VIECLUS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_repositories/VieClus)
set(VIECLUS_KAFFPA_SOURCES
${VIECLUS_DIR}/extern/KaHIP/lib/data_structure/graph_hierarchy.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/algorithms/strongly_connected_components.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/algorithms/topological_sort.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/algorithms/push_relabel.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/io/graph_io.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/tools/quality_metrics.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/tools/random_functions.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/tools/graph_extractor.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/tools/misc.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/tools/partition_snapshooter.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/graph_partitioner.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/w_cycles/wcycle_partitioner.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/coarsening/coarsening.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/coarsening/contraction.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/coarsening/edge_rating/edge_ratings.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/coarsening/matching/matching.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/coarsening/matching/random_matching.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/coarsening/matching/gpa/path.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/coarsening/matching/gpa/gpa_matching.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/coarsening/matching/gpa/path_set.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/coarsening/clustering/node_ordering.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/coarsening/clustering/size_constraint_label_propagation.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/initial_partitioning.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/initial_partitioner.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/initial_partition_bipartition.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/initial_refinement/initial_refinement.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/bipartition.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/initial_node_separator.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/uncoarsening.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/separator/area_bfs.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/separator/vertex_separator_algorithm.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/separator/vertex_separator_flow_solver.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/greedy_neg_cycle.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/problem_factory.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/augmented_Qgraph.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/mixed_refinement.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/label_propagation_refinement/label_propagation_refinement.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/refinement.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/2way_fm_refinement/two_way_fm.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement/two_way_flow_refinement.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement/boundary_bfs.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement/flow_solving_kernel/cut_flow_problem_solver.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement/most_balanced_minimum_cuts/most_balanced_minimum_cuts.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/quotient_graph_refinement.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/complete_boundary.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/partial_boundary.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/quotient_graph_scheduling/quotient_graph_scheduling.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/quotient_graph_scheduling/simple_quotient_graph_scheduler.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/quotient_graph_scheduling/active_block_quotient_graph_scheduler.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/kway_graph_refinement/kway_graph_refinement.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/kway_graph_refinement/kway_graph_refinement_core.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/kway_graph_refinement/kway_graph_refinement_commons.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/augmented_Qgraph_fabric.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/advanced_models.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/kway_graph_refinement/multitry_kway_fm.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/node_separators/greedy_ns_local_search.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/node_separators/fm_ns_local_search.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/node_separators/localized_fm_ns_local_search.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/algorithms/cycle_search.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/cycle_refinement.cpp
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/tabu_search/tabu_search.cpp
${VIECLUS_DIR}/extern/argtable3-3.0.3/argtable3.c
)
set(VIECLUS_CLUSTERING_SOURCES
${VIECLUS_DIR}/lib/parallel_mh_clustering/parallel_mh_async_clustering.cpp
${VIECLUS_DIR}/lib/parallel_mh_clustering/population_clustering.cpp
${VIECLUS_DIR}/lib/parallel_mh_clustering/exchange/exchanger_clustering.cpp
${VIECLUS_DIR}/lib/tools/graph_communication.cpp
${VIECLUS_DIR}/lib/clustering/louvainmethod.cpp
${VIECLUS_DIR}/lib/clustering/labelpropagation.cpp
${VIECLUS_DIR}/lib/clustering/neighborhood.cpp
${VIECLUS_DIR}/lib/clustering/coarsening/coarsening.cpp
${VIECLUS_DIR}/lib/clustering/coarsening/contractor.cpp
${VIECLUS_DIR}/lib/logging/bexception.cpp
${VIECLUS_DIR}/lib/tools/modularitymetric.cpp
${VIECLUS_DIR}/lib/tools/mpi_tools.cpp
)
add_library(vieclus_static STATIC
${VIECLUS_DIR}/interface/vieclus_interface.cpp
${VIECLUS_KAFFPA_SOURCES}
${VIECLUS_CLUSTERING_SOURCES}
)
target_include_directories(vieclus_static PUBLIC
${VIECLUS_DIR}
${VIECLUS_DIR}/extern/KaHIP/app
${VIECLUS_DIR}/extern/argtable3-3.0.3
${VIECLUS_DIR}/extern/KaHIP/lib
${VIECLUS_DIR}/extern/KaHIP/lib/io
${VIECLUS_DIR}/extern/KaHIP/lib/partition
${VIECLUS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement
${VIECLUS_DIR}/extern/KaHIP/lib/tools
${VIECLUS_DIR}/lib
${VIECLUS_DIR}/app
${VIECLUS_DIR}/interface
)
target_compile_definitions(vieclus_static PRIVATE USE_PSEUDO_MPI)
if(OpenMP_CXX_FOUND)
target_link_libraries(vieclus_static PUBLIC OpenMP::OpenMP_CXX)
else()
# VieClus provides an OpenMP stub via its KaHIP misc/ directory
target_include_directories(vieclus_static PRIVATE ${VIECLUS_DIR}/extern/KaHIP/misc)
endif()
# =============================================================================
# VieCut (header-only library; only build tlx from its extlib)
# =============================================================================
set(VIECUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_repositories/VieCut)
# tlx is the only compiled dependency VieCut needs
add_subdirectory(${VIECUT_DIR}/extlib/tlx EXCLUDE_FROM_ALL)
# =============================================================================
# CHILS (plain C library -- no existing CMake)
# =============================================================================
set(CHILS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_repositories/CHILS)
add_library(chils_static STATIC
${CHILS_DIR}/src/graph.c
${CHILS_DIR}/src/chils.c
${CHILS_DIR}/src/chils_internal.c
${CHILS_DIR}/src/local_search.c
)
target_include_directories(chils_static PUBLIC ${CHILS_DIR}/include)
set_target_properties(chils_static PROPERTIES C_STANDARD 17)
if(OpenMP_C_FOUND AND NOT MSVC)
# MSVC's OpenMP 2.0 rejects C99-style for-loop init inside #pragma omp for
# (error C3015). Skip OpenMP on MSVC; CHILS will run single-threaded.
target_link_libraries(chils_static PUBLIC OpenMP::OpenMP_C)
endif()
# =============================================================================
# red2pack (Maximum 2-Packing Set — reduce-and-transform)
# =============================================================================
set(R2P_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_repositories/red2pack)
# ---------------------------------------------------------------------------
# Patch chils_utils.h: red2pack expects the OLD CHILS C API (graph/chils/
# local_search structs with chils_init, chils_run, graph_free, etc.).
# Our CHILS provides a new opaque API (chils_initialize, chils_set_graph,
# chils_run_full, chils_release, etc.). Replace the entire file.
# ---------------------------------------------------------------------------
set(_R2P_CHILS_UTILS "${R2P_DIR}/lib/red2pack-chils/algorithms/chils_utils.h")
file(READ "${_R2P_CHILS_UTILS}" _r2p_chils_src)
string(FIND "${_r2p_chils_src}" "CHSZLABLIB_CHILS_PATCHED" _r2p_chils_patched)
if(_r2p_chils_patched EQUAL -1)
file(WRITE "${_R2P_CHILS_UTILS}" [=[
// CHSZLABLIB_CHILS_PATCHED — rewritten for new CHILS opaque API
#pragma once
#include <omp.h>
#include <red2pack/data_structure/m2s_graph_access.h>
#include <red2pack/data_structure/sized_vector.h>
#include <algorithm>
#include <limits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
namespace chils {
extern "C" {
#include <chils.h>
}
// Local graph struct replacing the old CHILS C graph type
struct graph {
int n;
int *V; // xadj (size n+1)
int *E; // adjncy
long long *W; // vertex weights
};
inline void graph_free(graph *g) {
if (!g) return;
free(g->V);
free(g->E);
free(g->W);
free(g);
}
struct chils_config {
bool verbose = true, warm_start = false;
int run_chils = 1, max_queue = 32;
double timeout = 3600, step = 5;
long long il = std::numeric_limits<long long>::max();
int path_offset = 0, path_end = 0;
unsigned seed = 0;
};
inline graph *build_graph(red2pack::m2s_graph_access &input_graph) {
using namespace red2pack;
int N = static_cast<int>(input_graph.number_of_nodes());
long long M = static_cast<long long>(input_graph.number_of_edges() + input_graph.number_of_links());
int *V = (int *)malloc(sizeof(int) * (N + 1));
int *E = (int *)malloc(sizeof(int) * M);
long long *W = (long long *)malloc(sizeof(long long) * N);
int ei = 0;
forall_nodes(input_graph, u) {
*(W + u) = static_cast<long long>(input_graph.getNodeWeight(u));
V[u] = ei;
forall_out_edges(input_graph, e, u) { E[ei++] = input_graph.getEdgeTarget(e); } endfor
forall_out_links(input_graph, e, u) { E[ei++] = input_graph.getLinkTarget(e); } endfor
std::sort(E + V[u], E + ei);
} endfor
V[N] = ei;
graph *g = (graph *)malloc(sizeof(graph));
*g = graph{N, V, E, W};
return g;
}
inline graph *build_induced_subgraph(red2pack::m2s_graph_access &input_graph,
const std::vector<bool> &mask,
const red2pack::sized_vector<red2pack::NodeID> &reverse_mapping,
const red2pack::sized_vector<red2pack::NodeID> &mapping) {
using namespace red2pack;
int N = static_cast<int>(reverse_mapping.size());
long long M = 0;
for (NodeID u : reverse_mapping) {
forall_out_edges(input_graph, e, u) { if (mask[input_graph.getEdgeTarget(e)]) M++; } endfor
forall_out_links(input_graph, e, u) { if (mask[input_graph.getLinkTarget(e)]) M++; } endfor
}
int *V = (int *)malloc(sizeof(int) * (N + 1));
int *E = (int *)malloc(sizeof(int) * M);
long long *W = (long long *)malloc(sizeof(long long) * N);
int ei = 0;
for (NodeID i = 0; i < reverse_mapping.size(); ++i) {
NodeID u = reverse_mapping[i];
*(W + i) = static_cast<long long>(input_graph.getNodeWeight(u));
V[i] = ei;
forall_out_edges(input_graph, e, u) {
if (mask[input_graph.getEdgeTarget(e)]) E[ei++] = mapping[input_graph.getEdgeTarget(e)];
} endfor
forall_out_links(input_graph, e, u) {
if (mask[input_graph.getLinkTarget(e)]) E[ei++] = mapping[input_graph.getLinkTarget(e)];
} endfor
std::sort(E + V[i], E + ei);
}
V[N] = ei;
graph *g = (graph *)malloc(sizeof(graph));
*g = graph{N, V, E, W};
return g;
}
inline long long mwis_validate(graph *g, int *independent_set) {
long long cost = 0;
for (int u = 0; u < g->n; u++) {
if (!independent_set[u]) continue;
cost += g->W[u];
for (int i = g->V[u]; i < g->V[u + 1]; i++)
if (independent_set[g->E[i] ]) return -1;
}
return cost;
}
inline void run_chils_impl(graph *g, std::vector<bool> &solution_indicator,
double &time_best, const chils_config &cfg) {
int n = g->n;
// Build long long xadj for new CHILS API
std::vector<long long> xadj_ll(n + 1);
for (int i = 0; i <= n; i++) xadj_ll[i] = g->V[i];
void *solver = chils_initialize();
chils_set_graph(solver, n, xadj_ll.data(), g->E, g->W);
if (cfg.run_chils > 1) {
chils_run_full(solver, cfg.timeout, cfg.run_chils, cfg.seed);
} else {
chils_run_local_search_only(solver, cfg.timeout, cfg.seed);
}
time_best = chils_solution_get_time(solver);
for (int i = 0; i < n; i++)
solution_indicator[i] = (chils_solution_get_vertex_configuration(solver, i) != 0);
chils_release(solver);
}
inline void run_chils(red2pack::m2s_graph_access &input_graph,
std::vector<bool> &solution, double &time_best,
const chils_config &cfg) {
graph *g = build_graph(input_graph);
run_chils_impl(g, solution, time_best, cfg);
graph_free(g);
}
} // namespace chils
]=])
endif()
# ---------------------------------------------------------------------------
# Patch m2s_log.h: suppress scoped_timer output (no-op in library mode)
# ---------------------------------------------------------------------------
set(_R2P_SCOPED_TIMER "${R2P_DIR}/lib/red2pack/tools/scoped_timer.h")
file(READ "${_R2P_SCOPED_TIMER}" _r2p_scoped_src)
string(FIND "${_r2p_scoped_src}" "CHSZLABLIB_SCOPED_PATCHED" _r2p_scoped_patched)
if(_r2p_scoped_patched EQUAL -1)
file(WRITE "${_R2P_SCOPED_TIMER}" [=[
// CHSZLABLIB_SCOPED_PATCHED — no-op scoped_timer for library use
#pragma once
#include <string>
#include "red2pack/tools/timer.h"
#include "red2pack/tools/m2s_log.h"
#define RED2PACK_SCOPED_TIMER(name)
namespace red2pack {
class scoped_timer {
public:
explicit scoped_timer(std::string) {}
~scoped_timer() {}
};
}
]=])
endif()
# ---------------------------------------------------------------------------
# red2pack_static — fat static library
# ---------------------------------------------------------------------------
# Core library sources
set(R2P_CORE_SOURCES
${R2P_DIR}/lib/red2pack/algorithms/kernel/reduce_algorithm.cpp
${R2P_DIR}/lib/red2pack/algorithms/kernel/weighted_reduce_algorithm.cpp
${R2P_DIR}/lib/red2pack/algorithms/kernel/reductions.cpp
${R2P_DIR}/lib/red2pack/algorithms/kernel/weighted_reductions.cpp
${R2P_DIR}/lib/red2pack/algorithms/kernel/heuristic_reduction.cpp
${R2P_DIR}/lib/red2pack/algorithms/kernel/reduce_and_transform.cpp
${R2P_DIR}/lib/red2pack/algorithms/solver_scheme.cpp
${R2P_DIR}/lib/red2pack/tools/m2s_log.cpp
${R2P_DIR}/lib/red2pack/tools/m2s_graph_io.cpp
)
# Solver sources (each sub-library)
set(R2P_KAMIS_WMIS_SOURCES
${R2P_DIR}/lib/red2pack-kamis-wmis/algorithms/branch_and_reduce.cpp
${R2P_DIR}/lib/red2pack-kamis-wmis/algorithms/weighted_rnt_exact.cpp
)
set(R2P_CHILS_SOURCES
${R2P_DIR}/lib/red2pack-chils/algorithms/weighted_rnt_chils.cpp
${R2P_DIR}/lib/red2pack-chils/algorithms/drp.cpp
)
set(R2P_HTWIS_HILS_SOURCES
${R2P_DIR}/lib/red2pack-htwis-hils/algorithms/weighted_rnt_htwis.cpp
${R2P_DIR}/lib/red2pack-htwis-hils/algorithms/weighted_rnt_hils.cpp
)
set(R2P_MMWIS_SOURCES
${R2P_DIR}/lib/red2pack-mmwis/algorithms/weighted_rnt_mmwis.cpp
)
set(R2P_ONLINEMIS_SOURCES
${R2P_DIR}/lib/red2pack-onlinemis/algorithms/heuristic.cpp
)
# Bundled extern libraries
set(R2P_HTWIS_SOURCES
${R2P_DIR}/extern/htwis/Graph.cpp
)
set(R2P_HILS_SOURCES
${R2P_DIR}/extern/hils/src/ArgPack.cpp
${R2P_DIR}/extern/hils/src/Graph.cpp
${R2P_DIR}/extern/hils/src/Solution.cpp
${R2P_DIR}/extern/hils/src/bossa_timer.cpp
)
set(R2P_BUNDLED_ONLINEMIS_SOURCES
${R2P_DIR}/extern/onlinemis/data_structure/candidate_list.cpp
${R2P_DIR}/extern/onlinemis/data_structure/mis_permutation_online.cpp
${R2P_DIR}/extern/onlinemis/data_structure/priority_queues/bucket_array.cpp
${R2P_DIR}/extern/onlinemis/ils/local_search_online.cpp
${R2P_DIR}/extern/onlinemis/ils/online_ils.cpp
${R2P_DIR}/extern/onlinemis/initial_mis/greedy_mis_online.cpp
${R2P_DIR}/extern/onlinemis/tools/mis_log.cpp
)
add_library(red2pack_static STATIC
${R2P_CORE_SOURCES}
${R2P_KAMIS_WMIS_SOURCES}
${R2P_CHILS_SOURCES}
${R2P_HTWIS_HILS_SOURCES}
${R2P_ONLINEMIS_SOURCES}
${R2P_HTWIS_SOURCES}
${R2P_HILS_SOURCES}
${R2P_BUNDLED_ONLINEMIS_SOURCES}
$<TARGET_OBJECTS:r2p_mmwis_obj>
)
target_include_directories(red2pack_static PUBLIC
# Core red2pack headers — only the top-level lib dir.
# Do NOT add subdirs (lib/red2pack, lib/red2pack/tools, etc.) because they
# shadow KaMIS wmis headers (timer.h, data_structure/sized_vector.h).
# Red2pack sources use "red2pack/..." prefixed includes that resolve via lib/.
${R2P_DIR}/lib
# Sub-library headers (no onlinemis/mmwis at top level — they have conflicting headers)
${R2P_DIR}/lib/red2pack-kamis-wmis
${R2P_DIR}/lib/red2pack-kamis-wmis/algorithms
${R2P_DIR}/lib/red2pack-chils
${R2P_DIR}/lib/red2pack-chils/algorithms
${R2P_DIR}/lib/red2pack-htwis-hils
${R2P_DIR}/lib/red2pack-htwis-hils/algorithms
# Bundled extern headers (no onlinemis top-level — has conflicting mis_config.h)
${R2P_DIR}/extern
${R2P_DIR}/extern/hils/src
${R2P_DIR}/extern/onlinemis/data_structure
${R2P_DIR}/extern/onlinemis/data_structure/priority_queues
${R2P_DIR}/extern/onlinemis/ils
${R2P_DIR}/extern/onlinemis/initial_mis
${R2P_DIR}/extern/onlinemis/tools
# App headers (m2s_configuration_*.h)
${R2P_DIR}/app
)
# onlinemis top-level dir has mis_config.h that conflicts with KaMIS wmis.
# Add it ONLY to the onlinemis sources via per-file compile options.
set_source_files_properties(
${R2P_ONLINEMIS_SOURCES} ${R2P_BUNDLED_ONLINEMIS_SOURCES}
PROPERTIES COMPILE_OPTIONS
"-I${R2P_DIR}/extern/onlinemis;-I${R2P_DIR}/lib/red2pack-onlinemis;-I${R2P_DIR}/lib/red2pack-onlinemis/algorithms"
)
# MMWIS solver needs mmwis-namespaced branch_and_reduce_algorithm.h (conflicts with wmis).
# Build as separate OBJECT library with mmwis include dirs taking priority.
add_library(r2p_mmwis_obj OBJECT ${R2P_MMWIS_SOURCES})
set(R2P_KAMIS_MMWIS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_repositories/KaMIS/mmwis)
target_include_directories(r2p_mmwis_obj BEFORE PRIVATE
${R2P_KAMIS_MMWIS_DIR}/lib/mis/kernel
${R2P_KAMIS_MMWIS_DIR}/lib/mis/evolutionary
${R2P_KAMIS_MMWIS_DIR}/lib/tools
${R2P_KAMIS_MMWIS_DIR}/app
${R2P_DIR}/lib/red2pack-mmwis
${R2P_DIR}/lib/red2pack-mmwis/algorithms
)
target_include_directories(r2p_mmwis_obj PRIVATE
${R2P_DIR}/lib
${R2P_DIR}/app
)
target_link_libraries(r2p_mmwis_obj PRIVATE kamis_mmwis_static kamis_wmis_static chils_static)
target_compile_options(r2p_mmwis_obj PRIVATE $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-w -fpermissive>)
target_compile_definitions(r2p_mmwis_obj PRIVATE NDEBUG)
if(OpenMP_CXX_FOUND)
target_link_libraries(r2p_mmwis_obj PRIVATE OpenMP::OpenMP_CXX)
endif()
# Link KaMIS wmis/mmwis (for branch_and_reduce_algorithm, MISConfig, graph_access, etc.)
target_link_libraries(red2pack_static PUBLIC
kamis_wmis_static
kamis_mmwis_static
chils_static
)
target_compile_options(red2pack_static PRIVATE $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-w -fpermissive>)
target_compile_definitions(red2pack_static PRIVATE NDEBUG BOSSA_CLOCK)
if(OpenMP_CXX_FOUND)
target_link_libraries(red2pack_static PUBLIC OpenMP::OpenMP_CXX)
endif()
# =============================================================================
# LearnAndReduce (GNN-guided MWIS kernelization)
# =============================================================================
set(LR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_repositories/LearnAndReduce)
set(LR_REDUCER ${LR_DIR}/solver/reducer)
add_library(learnandreduce_static STATIC
# lib/
${LR_DIR}/lib/io/graph_io.cpp
${LR_DIR}/lib/algorithms/push_relabel.cpp
${LR_DIR}/lib/algorithms/strongly_connected_components.cpp
${LR_DIR}/lib/data_structure/operation_log.cpp
${LR_DIR}/lib/data_structure/priority_queues/bucket_array.cpp
${LR_DIR}/lib/data_structure/candidate_list.cpp
${LR_DIR}/lib/data_structure/mis_permutation.cpp
${LR_DIR}/lib/tools/random_functions.cpp
${LR_DIR}/lib/tools/log.cpp
${LR_DIR}/lib/tools/graph_extractor.cpp
${LR_DIR}/lib/basics/cout_handler.cpp
# solver/tiny_solver/
${LR_DIR}/solver/tiny_solver/tiny_solver.c
# solver/reducer/lib/
${LR_REDUCER}/lib/reduce_algorithm.cpp
${LR_REDUCER}/lib/bounds.cpp
# solver/reducer/reductions/ (core + GNN)
${LR_REDUCER}/reductions/general_reduction.cpp
${LR_REDUCER}/reductions/LRConv.cpp
${LR_REDUCER}/reductions/lr_gcn.cpp
# simple reductions
${LR_REDUCER}/reductions/simple_reduction_rules/fold1_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/fold2_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/neighborhood_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/clique_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/clique_neighborhood_fast_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/twin_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/extended_twin_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/domination_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/extended_domination_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/extended_domination_reverse_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/single_edge_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/extended_single_edge_reduction.cpp
${LR_REDUCER}/reductions/simple_reduction_rules/funnel_reduction.cpp
# expensive reductions
${LR_REDUCER}/reductions/expensive_reduction_rules/clique_neighborhood_reduction.cpp
${LR_REDUCER}/reductions/expensive_reduction_rules/critical_set_reduction.cpp
${LR_REDUCER}/reductions/expensive_reduction_rules/cut_vertex_reduction.cpp
${LR_REDUCER}/reductions/expensive_reduction_rules/generalized_fold_reduction.cpp
${LR_REDUCER}/reductions/expensive_reduction_rules/heavy_set_reduction.cpp
${LR_REDUCER}/reductions/expensive_reduction_rules/heavy_set3_reduction.cpp
# struction reductions
${LR_REDUCER}/reductions/struction_reduction_rules/mwis_finder.cpp
${LR_REDUCER}/reductions/struction_reduction_rules/original_struction.cpp
${LR_REDUCER}/reductions/struction_reduction_rules/extended_struction.cpp
${LR_REDUCER}/reductions/struction_reduction_rules/key_functions.cpp
${LR_REDUCER}/reductions/struction_reduction_rules/struction_reductions.cpp
# CSR reductions
${LR_REDUCER}/reductions/csr_reductions/src/reductions.c
${LR_REDUCER}/reductions/csr_reductions/unconfined_csr_reduction.cpp
)
target_include_directories(learnandreduce_static PUBLIC
${LR_DIR}/lib
${LR_DIR}/lib/io
${LR_DIR}/lib/config
${LR_DIR}/lib/tools
${LR_DIR}/lib/algorithms
${LR_DIR}/lib/basics
${LR_DIR}/lib/data_structure
${LR_DIR}/lib/data_structure/priority_queues
${LR_DIR}/solver/tiny_solver
${LR_REDUCER}/lib
${LR_REDUCER}/lib/bounds
${LR_REDUCER}/reductions
${LR_REDUCER}/reductions/simple_reduction_rules
${LR_REDUCER}/reductions/expensive_reduction_rules
${LR_REDUCER}/reductions/heuristic_reduction_rules
${LR_REDUCER}/reductions/struction_reduction_rules
${LR_REDUCER}/reductions/csr_reductions
${LR_REDUCER}/reductions/csr_reductions/include
)
target_compile_definitions(learnandreduce_static PUBLIC
MODE64BITNODEWEIGHTS
LR_MODELS_FOLDER_OVERRIDE
)
target_compile_options(learnandreduce_static PRIVATE -w)
if(OpenMP_CXX_FOUND)
target_link_libraries(learnandreduce_static PUBLIC OpenMP::OpenMP_CXX)
endif()
# Patch general_reduction.h: override get_models_folder_path() to read global
set(_LR_GENRED_H "${LR_REDUCER}/reductions/general_reduction.h")
file(READ "${_LR_GENRED_H}" _LR_GENRED_SRC)
string(FIND "${_LR_GENRED_SRC}" "LR_MODELS_FOLDER_OVERRIDE" _LR_ALREADY_PATCHED)
if(_LR_ALREADY_PATCHED EQUAL -1)
string(REPLACE
"std::string get_models_folder_path()\n {\n std::string current_file = __FILE__;"
"std::string get_models_folder_path()\n {\n#ifdef LR_MODELS_FOLDER_OVERRIDE\n extern std::string g_lr_models_path;\n if (!g_lr_models_path.empty()) return g_lr_models_path;\n#endif\n std::string current_file = __FILE__;"
_LR_GENRED_SRC "${_LR_GENRED_SRC}")
file(WRITE "${_LR_GENRED_H}" "${_LR_GENRED_SRC}")
endif()
# Patch general_reduction.h: clang fix — extract br_alg->status.n access from
# template into a non-inline helper so the incomplete type is not dereferenced
# in the header (GCC defers this, clang does not).
file(READ "${_LR_GENRED_H}" _LR_GENRED_SRC2)
string(FIND "${_LR_GENRED_SRC2}" "_lr_get_status_n" _LR_CLANG_PATCHED)
if(_LR_CLANG_PATCHED EQUAL -1)
string(REPLACE
"template <typename F>\n inline void for_each_changed_vertex(reduce_algorithm *br_alg, F f)\n {\n for (size_t v_idx = 0; v_idx < marker.current_size(); v_idx++)\n {\n NodeID v = marker.current_vertex(v_idx);\n\n if (v < br_alg->status.n && !is_reduced(v, br_alg))"
"static size_t _lr_get_status_n(reduce_algorithm *br_alg);\n\n template <typename F>\n inline void for_each_changed_vertex(reduce_algorithm *br_alg, F f)\n {\n for (size_t v_idx = 0; v_idx < marker.current_size(); v_idx++)\n {\n NodeID v = marker.current_vertex(v_idx);\n\n if (v < _lr_get_status_n(br_alg) && !is_reduced(v, br_alg))"
_LR_GENRED_SRC2 "${_LR_GENRED_SRC2}")
file(WRITE "${_LR_GENRED_H}" "${_LR_GENRED_SRC2}")
# Add helper implementation to general_reduction.cpp
set(_LR_GENRED_CPP "${LR_REDUCER}/reductions/general_reduction.cpp")
file(READ "${_LR_GENRED_CPP}" _LR_GENRED_CPP_SRC)
string(FIND "${_LR_GENRED_CPP_SRC}" "_lr_get_status_n" _LR_CPP_PATCHED)
if(_LR_CPP_PATCHED EQUAL -1)
string(APPEND _LR_GENRED_CPP_SRC "\nsize_t general_reduction::_lr_get_status_n(reduce_algorithm *br_alg) { return br_alg->status.n; }\n")
file(WRITE "${_LR_GENRED_CPP}" "${_LR_GENRED_CPP_SRC}")
endif()
endif()
# Patch LRConv.cpp: remove #include <immintrin.h> (x86-only, unused on ARM)
set(_LR_LRCONV_CPP "${LR_REDUCER}/reductions/LRConv.cpp")
file(READ "${_LR_LRCONV_CPP}" _LR_LRCONV_SRC)
string(FIND "${_LR_LRCONV_SRC}" "#include <immintrin.h>" _LR_LRCONV_HAS_IMMINTRIN)
if(NOT _LR_LRCONV_HAS_IMMINTRIN EQUAL -1)
string(REPLACE "#include <immintrin.h>" "// #include <immintrin.h> // removed: x86-only, unused" _LR_LRCONV_SRC "${_LR_LRCONV_SRC}")
file(WRITE "${_LR_LRCONV_CPP}" "${_LR_LRCONV_SRC}")
endif()
# Patch lr_gcn.cpp: replace AVX2 intrinsics with portable scalar code
set(_LR_GCN_CPP "${LR_REDUCER}/reductions/lr_gcn.cpp")
file(READ "${_LR_GCN_CPP}" _LR_GCN_SRC)
string(FIND "${_LR_GCN_SRC}" "immintrin.h" _LR_GCN_HAS_AVX)
if(NOT _LR_GCN_HAS_AVX EQUAL -1)
# Replace the entire file with a portable scalar version. The API
# (lr_gcn_parse, compute_features, lr_gcn_predict, etc.) is kept
# identical so that all call-sites continue to compile unchanged.
file(WRITE "${_LR_GCN_CPP}" [[
#include "lr_gcn.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
const int param_offsets[4] = {0, 272, 800, 1456};
const int layer_inputs[4] = {8, 16, 40, 16};
const int layer_outputs[4] = {16, 16, 16, 1};
const int max_input = 16;
const int cat_input = 40;
const int layer_output = 16;
const int num_features = 8;
const int node_weight = 0;
const int diff_neighborhood_weight = 1;
const int min_neighborhood_weight = 2;
const int max_neighborhood_weight = 3;
const int node_degree = 4;
const int avg_neighborhood_degree = 5;
const int min_neighborhood_degree = 6;
const int max_neighborhood_degree = 7;
int lr_gcn_parse(FILE *f, float **paramv) {
int paramc;
int np = fscanf(f, "%d\n", ¶mc);
*paramv = (float *)malloc(sizeof(float) * paramc);
for (int i = 0; i < paramc; i++)
np = fscanf(f, "%f\n", (*paramv) + i);
(void)np;
return paramc;
}
void compute_features(graph_access &g, float *x) {
for (int u = 0; u < (int)g.number_of_nodes(); u++) {
float *ux = x + u * num_features;
for (int i = 0; i < num_features; i++) ux[i] = 0.0f;
ux[node_weight] = g.getNodeWeight(u);
ux[diff_neighborhood_weight] = g.getNodeWeight(u);
ux[node_degree] = g.getNodeDegree(u);
float scale = 1.0f / ux[node_degree];
for (int i = g.get_first_edge(u); i != (int)g.get_first_invalid_edge(u); i++) {
int v = g.getEdgeTarget(i);
float d = g.getNodeDegree(v);
float w = g.getNodeWeight(v);
ux[diff_neighborhood_weight] -= w;
if (w < ux[min_neighborhood_weight] || ux[min_neighborhood_weight] == 0.0f)
ux[min_neighborhood_weight] = w;
if (w > ux[max_neighborhood_weight])
ux[max_neighborhood_weight] = w;
ux[avg_neighborhood_degree] += d * scale;
if (d < ux[min_neighborhood_degree] || ux[min_neighborhood_degree] == 0.0f)
ux[min_neighborhood_degree] = d;
if (d > ux[max_neighborhood_degree])
ux[max_neighborhood_degree] = d;
}
}
}
static void matrix_multiplication_scalar(const float *A, const float *B, float *C,
const float *b, int n, int k) {
const int m = layer_output;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) C[i * m + j] = b[j];
for (int p = 0; p < k; p++) {
float a = A[i * k + p];
for (int j = 0; j < m; j++)
C[i * m + j] += a * B[p * m + j];
}
}
}
static void lr_conv_combined_scalar(graph_access &g, int dim, float *in, float *out,
const float *p, const float *b) {
int N = g.number_of_nodes();
float *in_buff = (float *)malloc(sizeof(float) * dim * 2);
for (int u = 0; u < N; u++) {
float *x = in + u * dim;
float *y = out + u * layer_output;
for (int j = 0; j < layer_output; j++) y[j] = 0.0f;
for (int j = 0; j < dim; j++) in_buff[j] = x[j];
float scale = 1.0f / (float)g.getNodeDegree(u);
for (int i = g.get_first_edge(u); i != (int)g.get_first_invalid_edge(u); i++) {
int v = g.getEdgeTarget(i);
float *xv = in + v * dim;
for (int j = 0; j < dim; j++) in_buff[dim + j] = xv[j];
for (int j = 0; j < layer_output; j++) {
float val = b[j];
for (int k = 0; k < dim * 2; k++)
val += in_buff[k] * p[k * layer_output + j];
y[j] += val * scale;
}
}
}
free(in_buff);
}
void ReLU(float *x, int n) {
for (int u = 0; u < n; u++)
for (int i = 0; i < layer_output; i++)
x[u * layer_output + i] = x[u * layer_output + i] > 0.0f ? x[u * layer_output + i] : 0.0f;
}
void Sigmoid(float *x, int n) {
for (int u = 0; u < n; u++)
for (int i = 0; i < layer_output; i++)
x[u * layer_output + i] = 1.0f / (1.0f + expf(-x[u * layer_output + i]));
}
void prep_params(const float *p, int n, int m, float *out_p, float *out_b) {
for (int i = 0; i < n; i++)
for (int j = 0; j < layer_output; j++)
out_p[i * layer_output + j] = 0.0f;
for (int j = 0; j < layer_output; j++) out_b[j] = 0.0f;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
out_p[i * layer_output + j] = p[j * n + i];
for (int j = 0; j < m; j++)
out_b[j] = p[n * m + j];
}
float *lr_gcn_predict(graph_access &g, std::string path) {
float *params = NULL;
FILE *f = fopen(path.c_str(), "r");
if (!f) return NULL;
lr_gcn_parse(f, ¶ms);
fclose(f);
int N = g.number_of_nodes();
float *x = (float *)calloc(max_input * N, sizeof(float));
float *y = (float *)calloc(max_input * N, sizeof(float));
float *cat = (float *)calloc(cat_input * N, sizeof(float));
float *p = (float *)calloc(cat_input * layer_output, sizeof(float));
float *b = (float *)calloc(layer_output, sizeof(float));
compute_features(g, x);
for (int i = 0; i < N; i++)
for (int j = 0; j < layer_inputs[0]; j++)
cat[i * cat_input + j] = x[i * layer_inputs[0] + j];
prep_params(params + param_offsets[0], layer_inputs[0] * 2, layer_outputs[0], p, b);
lr_conv_combined_scalar(g, layer_inputs[0], x, y, p, b);
ReLU(y, N);
for (int i = 0; i < N; i++)
for (int j = 0; j < layer_output; j++)
cat[i * cat_input + layer_inputs[0] + j] = y[i * layer_output + j];
prep_params(params + param_offsets[1], layer_inputs[1] * 2, layer_outputs[1], p, b);
lr_conv_combined_scalar(g, layer_inputs[1], y, x, p, b);
ReLU(x, N);
for (int i = 0; i < N; i++)
for (int j = 0; j < layer_output; j++)
cat[i * cat_input + layer_inputs[0] + layer_inputs[1] + j] = x[i * layer_output + j];
prep_params(params + param_offsets[2], layer_inputs[2], layer_outputs[2], p, b);
matrix_multiplication_scalar(cat, p, y, b, N, layer_inputs[2]);
ReLU(y, N);
prep_params(params + param_offsets[3], layer_inputs[3], layer_outputs[3], p, b);
matrix_multiplication_scalar(y, p, x, b, N, layer_inputs[3]);
Sigmoid(x, N);
float *res = (float *)malloc(sizeof(float) * N);
for (int i = 0; i < N; i++) res[i] = x[i * layer_output];
free(params); free(x); free(y); free(cat); free(p); free(b);
return res;
}
]])
endif()
# Install GNN model files as package data
file(GLOB LR_MODEL_FILES ${LR_DIR}/models/*.lr_gcn)
install(FILES ${LR_MODEL_FILES} DESTINATION chszlablib/models)
# =============================================================================
# KaMIS (Maximum Independent Set — three isolated static libraries)
# =============================================================================
# KaMIS has three sub-projects (root, wmis, mmwis) each with their own copy of
# KaHIP and conflicting symbols. We build each as a separate static lib.
set(KAMIS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_repositories/KaMIS)
# ---------------------------------------------------------------------------
# kamis_redumis_static — unweighted MIS (ReduMIS + OnlineMIS)
# ---------------------------------------------------------------------------
set(KAMIS_ROOT_KAHIP_SOURCES
${KAMIS_DIR}/extern/KaHIP/lib/data_structure/graph_hierarchy.cpp
${KAMIS_DIR}/extern/KaHIP/lib/algorithms/strongly_connected_components.cpp
${KAMIS_DIR}/extern/KaHIP/lib/algorithms/topological_sort.cpp
${KAMIS_DIR}/extern/KaHIP/lib/algorithms/push_relabel.cpp
${KAMIS_DIR}/extern/KaHIP/lib/io/graph_io.cpp
${KAMIS_DIR}/extern/KaHIP/lib/tools/quality_metrics.cpp
${KAMIS_DIR}/extern/KaHIP/lib/tools/random_functions.cpp
${KAMIS_DIR}/extern/KaHIP/lib/tools/graph_extractor.cpp
${KAMIS_DIR}/extern/KaHIP/lib/tools/misc.cpp
${KAMIS_DIR}/extern/KaHIP/lib/tools/partition_snapshooter.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/graph_partitioner.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/w_cycles/wcycle_partitioner.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/coarsening/coarsening.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/coarsening/contraction.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/coarsening/edge_rating/edge_ratings.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/coarsening/clustering/node_ordering.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/coarsening/clustering/size_constraint_label_propagation.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/coarsening/matching/matching.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/coarsening/matching/random_matching.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/coarsening/matching/gpa/path.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/coarsening/matching/gpa/gpa_matching.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/coarsening/matching/gpa/path_set.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/initial_partitioning.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/initial_partitioner.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/initial_partition_bipartition.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/initial_refinement/initial_refinement.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/initial_partitioning/bipartition.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/uncoarsening.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/separator/vertex_separator_algorithm.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/separator/vertex_separator_flow_solver.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/greedy_neg_cycle.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/problem_factory.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/augmented_Qgraph.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/refinement.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/mixed_refinement.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/2way_fm_refinement/two_way_fm.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement/two_way_flow_refinement.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement/boundary_bfs.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement/most_balanced_minimum_cuts/most_balanced_minimum_cuts.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement/flow_solving_kernel/cut_flow_problem_solver.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/quotient_graph_refinement.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/complete_boundary.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/partial_boundary.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/quotient_graph_scheduling/quotient_graph_scheduling.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/quotient_graph_scheduling/simple_quotient_graph_scheduler.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/quotient_graph_scheduling/active_block_quotient_graph_scheduler.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/kway_graph_refinement/kway_graph_refinement.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/kway_graph_refinement/kway_graph_refinement_core.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/label_propagation_refinement/label_propagation_refinement.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/kway_graph_refinement/kway_graph_refinement_commons.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/augmented_Qgraph_fabric.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/advanced_models.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/kway_graph_refinement/multitry_kway_fm.cpp
${KAMIS_DIR}/extern/KaHIP/lib/algorithms/cycle_search.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements/cycle_refinement.cpp
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/tabu_search/tabu_search.cpp
${KAMIS_DIR}/extern/KaHIP/interface/kaHIP_interface.cpp
)
set(KAMIS_ROOT_LIB_SOURCES
${KAMIS_DIR}/lib/tools/mis_log.cpp
${KAMIS_DIR}/lib/mis/ils/ils.cpp
${KAMIS_DIR}/lib/mis/ils/local_search.cpp
${KAMIS_DIR}/lib/mis/initial_mis/greedy_mis.cpp
${KAMIS_DIR}/lib/mis/initial_mis/greedy_vertex.cpp
${KAMIS_DIR}/lib/mis/initial_mis/random_mis.cpp
${KAMIS_DIR}/lib/mis/initial_mis/initial_mis.cpp
${KAMIS_DIR}/lib/data_structure/mis_permutation.cpp
${KAMIS_DIR}/lib/data_structure/candidate_list.cpp
${KAMIS_DIR}/lib/data_structure/operation_log.cpp
${KAMIS_DIR}/lib/data_structure/priority_queues/bucket_array.cpp
${KAMIS_DIR}/lib/mis/evolutionary/population_mis.cpp
${KAMIS_DIR}/lib/mis/evolutionary/reduction_evolution.cpp
${KAMIS_DIR}/lib/mis/hopcroft/bipartite_vertex_cover.cpp
${KAMIS_DIR}/lib/mis/kernel/branch_and_reduce_algorithm.cpp
${KAMIS_DIR}/lib/mis/kernel/modified.cpp
${KAMIS_DIR}/lib/mis/evolutionary/separator_pool.cpp
${KAMIS_DIR}/lib/mis/evolutionary/combine/combine.cpp
${KAMIS_DIR}/lib/mis/evolutionary/combine/cover_combine.cpp
${KAMIS_DIR}/lib/mis/evolutionary/combine/separator_combine.cpp
${KAMIS_DIR}/lib/mis/evolutionary/combine/multiway_combine.cpp
${KAMIS_DIR}/lib/mis/kernel/ParFastKer/fast_reductions/src/full_reductions.cpp
${KAMIS_DIR}/lib/mis/kernel/ParFastKer/fast_reductions/src/parallel_reductions.cpp
${KAMIS_DIR}/lib/mis/kernel/ParFastKer/fast_reductions/src/MaximumMatching.cpp
${KAMIS_DIR}/lib/mis/kernel/ParFastKer/LinearTime/MIS_sigmod_pub/Graph.cpp
${KAMIS_DIR}/lib/mis/kernel/ParFastKer/LinearTime/MIS_sigmod_pub/Utility.cpp
${KAMIS_DIR}/extern/argtable3-3.0.3/argtable3.c
)
set(KAMIS_ONLINE_SOURCES
${KAMIS_DIR}/lib/mis/ils/online_ils.cpp
${KAMIS_DIR}/lib/mis/ils/local_search_online.cpp
${KAMIS_DIR}/lib/mis/initial_mis/greedy_mis_online.cpp
${KAMIS_DIR}/lib/data_structure/mis_permutation_online.cpp
)
add_library(kamis_redumis_static STATIC
${KAMIS_ROOT_KAHIP_SOURCES}
${KAMIS_ROOT_LIB_SOURCES}
${KAMIS_ONLINE_SOURCES}
)
target_include_directories(kamis_redumis_static PUBLIC
${KAMIS_DIR}/extern/argtable3-3.0.3
${KAMIS_DIR}
${KAMIS_DIR}/app
${KAMIS_DIR}/extern/KaHIP
${KAMIS_DIR}/extern/KaHIP/interface
${KAMIS_DIR}/extern/KaHIP/lib
${KAMIS_DIR}/extern/KaHIP/lib/data_structure
${KAMIS_DIR}/extern/KaHIP/lib/io
${KAMIS_DIR}/extern/KaHIP/lib/partition
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement
${KAMIS_DIR}/extern/KaHIP/lib/partition/uncoarsening/refinement/cycle_improvements
${KAMIS_DIR}/extern/KaHIP/lib/tools
${KAMIS_DIR}/lib
${KAMIS_DIR}/lib/mis
${KAMIS_DIR}/lib/mis/evolutionary