generalized-maxflow 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- generalized_maxflow-0.3.0/.gitattributes +3 -0
- generalized_maxflow-0.3.0/.gitignore +27 -0
- generalized_maxflow-0.3.0/CMakeLists.txt +152 -0
- generalized_maxflow-0.3.0/LICENSE +21 -0
- generalized_maxflow-0.3.0/PKG-INFO +686 -0
- generalized_maxflow-0.3.0/README.md +642 -0
- generalized_maxflow-0.3.0/bindings/c/capi.cpp +71 -0
- generalized_maxflow-0.3.0/bindings/wasm/build.sh +56 -0
- generalized_maxflow-0.3.0/bindings/wasm/index.d.ts +132 -0
- generalized_maxflow-0.3.0/bindings/wasm/index.mjs +70 -0
- generalized_maxflow-0.3.0/bindings/wasm/package.json +50 -0
- generalized_maxflow-0.3.0/bindings/wasm/test_node.mjs +89 -0
- generalized_maxflow-0.3.0/examples/currency_arbitrage.json +14 -0
- generalized_maxflow-0.3.0/examples/power_grid.json +20 -0
- generalized_maxflow-0.3.0/examples/rerouting.json +12 -0
- generalized_maxflow-0.3.0/include/gmf/gmf.hpp +194 -0
- generalized_maxflow-0.3.0/include/gmf/json.hpp +87 -0
- generalized_maxflow-0.3.0/pyproject.toml +74 -0
- generalized_maxflow-0.3.0/python/gmaxflow/__init__.py +133 -0
- generalized_maxflow-0.3.0/python/gmaxflow/__main__.py +62 -0
- generalized_maxflow-0.3.0/python/gmaxflow/_native.py +75 -0
- generalized_maxflow-0.3.0/python/gmaxflow/py.typed +0 -0
- generalized_maxflow-0.3.0/src/api.cpp +345 -0
- generalized_maxflow-0.3.0/src/cli_main.cpp +134 -0
- generalized_maxflow-0.3.0/src/json.cpp +480 -0
- generalized_maxflow-0.3.0/src/solver.cpp +1773 -0
- generalized_maxflow-0.3.0/tests/harness.hpp +75 -0
- generalized_maxflow-0.3.0/tests/reference.hpp +155 -0
- generalized_maxflow-0.3.0/tests/test_api.cpp +140 -0
- generalized_maxflow-0.3.0/tests/test_json.cpp +96 -0
- generalized_maxflow-0.3.0/tests/test_main.cpp +35 -0
- generalized_maxflow-0.3.0/tests/test_python.py +218 -0
- generalized_maxflow-0.3.0/tests/test_regression.cpp +319 -0
- generalized_maxflow-0.3.0/tests/test_solver.cpp +380 -0
- generalized_maxflow-0.3.0/tools/bench.cpp +154 -0
- generalized_maxflow-0.3.0/tools/gap_probe.py +126 -0
- generalized_maxflow-0.3.0/tools/lp_check.py +232 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
build/
|
|
2
|
+
build-*/
|
|
3
|
+
dist/
|
|
4
|
+
wheelhouse/
|
|
5
|
+
bindings/wasm/pkg/
|
|
6
|
+
*.egg-info/
|
|
7
|
+
__pycache__/
|
|
8
|
+
*.pyc
|
|
9
|
+
.pytest_cache/
|
|
10
|
+
.venv/
|
|
11
|
+
venv/
|
|
12
|
+
.vs/
|
|
13
|
+
.vscode/
|
|
14
|
+
.idea/
|
|
15
|
+
CMakeUserPresets.json
|
|
16
|
+
compile_commands.json
|
|
17
|
+
*.o
|
|
18
|
+
*.obj
|
|
19
|
+
*.a
|
|
20
|
+
*.lib
|
|
21
|
+
*.so
|
|
22
|
+
*.dylib
|
|
23
|
+
*.dll
|
|
24
|
+
*.pyd
|
|
25
|
+
*.exe
|
|
26
|
+
*.wasm
|
|
27
|
+
.DS_Store
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.18)
|
|
2
|
+
|
|
3
|
+
project(generalized-maxflow
|
|
4
|
+
VERSION 0.3.0
|
|
5
|
+
DESCRIPTION "Generalized maximum flow: maximum flow with per-edge gain multipliers"
|
|
6
|
+
LANGUAGES CXX)
|
|
7
|
+
|
|
8
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
9
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
10
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
11
|
+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
12
|
+
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
|
|
13
|
+
endif()
|
|
14
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
15
|
+
|
|
16
|
+
# Link-time optimisation for the optimised configurations, where supported. The
|
|
17
|
+
# solver is one translation unit calling into another, so cross-module inlining
|
|
18
|
+
# of the inner loops is worth having.
|
|
19
|
+
include(CheckIPOSupported)
|
|
20
|
+
check_ipo_supported(RESULT GMF_IPO_SUPPORTED OUTPUT GMF_IPO_MESSAGE)
|
|
21
|
+
if(GMF_IPO_SUPPORTED)
|
|
22
|
+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
|
|
23
|
+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
|
|
24
|
+
endif()
|
|
25
|
+
|
|
26
|
+
option(GMF_BUILD_CLI "Build the gmaxflow command line tool" ON)
|
|
27
|
+
option(GMF_BUILD_TESTS "Build the test suite" ON)
|
|
28
|
+
option(GMF_BUILD_BENCH "Build the benchmark harness" ON)
|
|
29
|
+
if(DEFINED SKBUILD)
|
|
30
|
+
set(GMF_SHARED_DEFAULT ON)
|
|
31
|
+
else()
|
|
32
|
+
set(GMF_SHARED_DEFAULT OFF)
|
|
33
|
+
endif()
|
|
34
|
+
# The shared library with a plain C ABI that the Python package loads through
|
|
35
|
+
# ctypes. It never links libpython, which is what lets one wheel per OS and CPU
|
|
36
|
+
# (tagged py3-none-<platform>) serve every Python version.
|
|
37
|
+
option(GMF_BUILD_SHARED "Build the gmaxflow_core shared library (C ABI)" ${GMF_SHARED_DEFAULT})
|
|
38
|
+
option(GMF_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)
|
|
39
|
+
|
|
40
|
+
if(GMF_BUILD_SHARED)
|
|
41
|
+
# Everything ends up inside one shared library, so keep the core's C++
|
|
42
|
+
# symbols out of its export table: only the gmf_* C functions are public.
|
|
43
|
+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
|
44
|
+
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
|
|
45
|
+
if(MSVC)
|
|
46
|
+
# Static CRT: the DLL then depends only on system DLLs, so it loads on a
|
|
47
|
+
# machine without the Visual C++ redistributable installed.
|
|
48
|
+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
49
|
+
endif()
|
|
50
|
+
endif()
|
|
51
|
+
|
|
52
|
+
# Emscripten compiles with exceptions disabled by default, which turns a throw
|
|
53
|
+
# into a module-level abort. The JSON front door reports a malformed graph by
|
|
54
|
+
# catching the exception validation raises, so without this the solver aborts
|
|
55
|
+
# instead of returning {"status": "invalid_input"} -- which is what the Node
|
|
56
|
+
# smoke test caught. These must be set before the targets they apply to.
|
|
57
|
+
if(EMSCRIPTEN)
|
|
58
|
+
add_compile_options(-fexceptions)
|
|
59
|
+
add_link_options(-fexceptions)
|
|
60
|
+
endif()
|
|
61
|
+
|
|
62
|
+
add_library(gmf_core STATIC
|
|
63
|
+
src/json.cpp
|
|
64
|
+
src/solver.cpp
|
|
65
|
+
src/api.cpp)
|
|
66
|
+
target_include_directories(gmf_core PUBLIC
|
|
67
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
68
|
+
$<INSTALL_INTERFACE:include>)
|
|
69
|
+
|
|
70
|
+
if(MSVC)
|
|
71
|
+
target_compile_options(gmf_core PRIVATE /W4 /permissive-)
|
|
72
|
+
if(GMF_WARNINGS_AS_ERRORS)
|
|
73
|
+
target_compile_options(gmf_core PRIVATE /WX)
|
|
74
|
+
endif()
|
|
75
|
+
else()
|
|
76
|
+
target_compile_options(gmf_core PRIVATE -Wall -Wextra -Wpedantic)
|
|
77
|
+
if(GMF_WARNINGS_AS_ERRORS)
|
|
78
|
+
target_compile_options(gmf_core PRIVATE -Werror)
|
|
79
|
+
endif()
|
|
80
|
+
endif()
|
|
81
|
+
|
|
82
|
+
if(GMF_BUILD_CLI AND NOT EMSCRIPTEN)
|
|
83
|
+
add_executable(gmaxflow src/cli_main.cpp)
|
|
84
|
+
target_link_libraries(gmaxflow PRIVATE gmf_core)
|
|
85
|
+
endif()
|
|
86
|
+
|
|
87
|
+
if(GMF_BUILD_TESTS)
|
|
88
|
+
enable_testing()
|
|
89
|
+
add_executable(gmf_tests
|
|
90
|
+
tests/test_main.cpp
|
|
91
|
+
tests/test_json.cpp
|
|
92
|
+
tests/test_solver.cpp
|
|
93
|
+
tests/test_api.cpp
|
|
94
|
+
tests/test_regression.cpp)
|
|
95
|
+
target_link_libraries(gmf_tests PRIVATE gmf_core)
|
|
96
|
+
target_include_directories(gmf_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
|
97
|
+
add_test(NAME gmf_tests COMMAND gmf_tests)
|
|
98
|
+
endif()
|
|
99
|
+
|
|
100
|
+
if(GMF_BUILD_BENCH AND NOT EMSCRIPTEN)
|
|
101
|
+
add_executable(gmf_bench tools/bench.cpp)
|
|
102
|
+
target_link_libraries(gmf_bench PRIVATE gmf_core)
|
|
103
|
+
endif()
|
|
104
|
+
|
|
105
|
+
if(GMF_BUILD_SHARED AND NOT EMSCRIPTEN)
|
|
106
|
+
add_library(gmaxflow_core SHARED bindings/c/capi.cpp)
|
|
107
|
+
target_link_libraries(gmaxflow_core PRIVATE gmf_core)
|
|
108
|
+
# One fixed name on every platform, with no "lib" prefix, so ctypes looks
|
|
109
|
+
# for gmaxflow_core.{dll,so,dylib}.
|
|
110
|
+
set_target_properties(gmaxflow_core PROPERTIES PREFIX "")
|
|
111
|
+
if(APPLE)
|
|
112
|
+
set_target_properties(gmaxflow_core PROPERTIES SUFFIX ".dylib")
|
|
113
|
+
endif()
|
|
114
|
+
if(MINGW)
|
|
115
|
+
# MinGW's C++ runtime and winpthread are not on a user's PATH.
|
|
116
|
+
target_link_options(gmaxflow_core PRIVATE -static)
|
|
117
|
+
endif()
|
|
118
|
+
# Linux links libstdc++ dynamically; the manylinux and musllinux images keep
|
|
119
|
+
# the wheel within the libstdc++ every supported distribution ships.
|
|
120
|
+
#
|
|
121
|
+
# scikit-build-core installs relative to the wheel's platlib root. Only the
|
|
122
|
+
# library itself: on Windows the import .lib is not wanted in a wheel.
|
|
123
|
+
install(TARGETS gmaxflow_core
|
|
124
|
+
LIBRARY DESTINATION gmaxflow/_native
|
|
125
|
+
RUNTIME DESTINATION gmaxflow/_native)
|
|
126
|
+
endif()
|
|
127
|
+
|
|
128
|
+
if(EMSCRIPTEN)
|
|
129
|
+
add_executable(gmaxflow_wasm bindings/c/capi.cpp)
|
|
130
|
+
target_link_libraries(gmaxflow_wasm PRIVATE gmf_core)
|
|
131
|
+
set_target_properties(gmaxflow_wasm PROPERTIES OUTPUT_NAME "gmaxflow")
|
|
132
|
+
target_link_options(gmaxflow_wasm PRIVATE
|
|
133
|
+
"-sMODULARIZE=1"
|
|
134
|
+
"-sEXPORT_ES6=1"
|
|
135
|
+
"-sEXPORT_NAME=createGmaxflow"
|
|
136
|
+
"-sALLOW_MEMORY_GROWTH=1"
|
|
137
|
+
"-sEXPORTED_FUNCTIONS=['_gmf_solve_json','_gmf_solve_json_n','_gmf_free','_gmf_version','_malloc','_free']"
|
|
138
|
+
"-sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','UTF8ToString','stringToUTF8','lengthBytesUTF8']"
|
|
139
|
+
"-sENVIRONMENT=web,worker,node"
|
|
140
|
+
"--no-entry")
|
|
141
|
+
endif()
|
|
142
|
+
|
|
143
|
+
# A Python wheel holds only the shared library; the static library and its
|
|
144
|
+
# headers are for an ordinary install.
|
|
145
|
+
if(NOT SKBUILD)
|
|
146
|
+
include(GNUInstallDirs)
|
|
147
|
+
install(TARGETS gmf_core ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
148
|
+
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
149
|
+
if(GMF_BUILD_CLI AND NOT EMSCRIPTEN)
|
|
150
|
+
install(TARGETS gmaxflow RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
151
|
+
endif()
|
|
152
|
+
endif()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wesboyt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|