massive state space solver improvement: supercomp took ~10s, now ~40ms

achieved by imposing a 15 block limit on each board and changing the
internal representation from std::string to 4x uint64_t
This commit is contained in:
2026-03-02 05:26:18 +01:00
parent c7361fe47e
commit 592c4b6cc0
16 changed files with 1913 additions and 848 deletions

View File

@ -4,20 +4,48 @@ project(MassSprings)
set(CMAKE_CXX_STANDARD 26)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()
option(DISABLE_BACKWARD "Disable backward stacktrace printer" OFF)
option(DISABLE_TRACY "Disable the Tracy profiler client" ON)
option(DISABLE_TESTS "Disable building and running tests" ON)
# Headers + Sources
set(SOURCES
src/backward.cpp
src/graph_distances.cpp
src/input_handler.cpp
src/mass_spring_system.cpp
src/octree.cpp
src/orbit_camera.cpp
src/renderer.cpp
src/state_manager.cpp
src/threaded_physics.cpp
src/user_interface.cpp
src/puzzle.cpp
)
# Libraries
find_package(raylib REQUIRED)
set(LIBS raylib)
find_package(Boost REQUIRED)
set(LIBS raylib Boost::headers)
set(FLAGS "")
if(NOT DEFINED DISABLE_BACKWARD)
if(WIN32)
list(APPEND LIBS opengl32 gdi32 winmm)
endif()
include(FetchContent)
if(NOT DISABLE_BACKWARD)
find_package(Backward REQUIRED)
list(APPEND LIBS Backward::Backward)
list(APPEND FLAGS BACKWARD)
endif()
if(NOT DEFINED DISABLE_TRACY)
include(FetchContent)
if(NOT DISABLE_TRACY)
FetchContent_Declare(tracy
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
GIT_TAG v0.11.1
@ -32,14 +60,10 @@ if(NOT DEFINED DISABLE_TRACY)
list(APPEND FLAGS TRACY)
endif()
if(WIN32)
list(APPEND LIBS opengl32 gdi32 winmm)
endif()
# Set this after fetching tracy to hide tracy's warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wno-unused-parameter -Wunreachable-code")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O2 -ggdb") # -fsanitize=address already fails on InitWindow(), -fsanitize=undefined, -fsanitize=leak
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ggdb -Ofast -march=native")
message("-- CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message("-- CMAKE_C_FLAGS_DEBUG: ${CMAKE_C_FLAGS_DEBUG}")
@ -48,40 +72,42 @@ message("-- CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message("-- CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
message("-- CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
# Headers + Sources
include_directories(include)
set(SOURCES
src/backward.cpp
src/graph_distances.cpp
src/input_handler.cpp
src/main.cpp
src/mass_spring_system.cpp
src/octree.cpp
src/orbit_camera.cpp
src/threaded_physics.cpp
src/puzzle.cpp
src/renderer.cpp
src/state_manager.cpp
src/user_interface.cpp
)
# Main target
add_executable(masssprings ${SOURCES})
target_include_directories(masssprings PRIVATE ${RAYLIB_CPP_INCLUDE_DIR})
add_executable(masssprings src/main.cpp ${SOURCES})
target_include_directories(masssprings PRIVATE include)
target_link_libraries(masssprings PRIVATE ${LIBS})
target_compile_definitions(masssprings PRIVATE ${FLAGS})
# Testing sources
if(NOT DISABLE_TESTS AND NOT WIN32)
enable_testing()
FetchContent_Declare(Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.13.0
)
FetchContent_MakeAvailable(Catch2)
set(TEST_SOURCES
test/bits.cpp
)
add_executable(tests ${TEST_SOURCES} ${SOURCES})
target_include_directories(tests PRIVATE include)
target_link_libraries(tests Catch2::Catch2WithMain raylib)
include(Catch)
catch_discover_tests(tests)
endif()
# LTO
if(NOT WIN32)
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if(supported)
message(STATUS "IPO / LTO enabled")
set_property(TARGET masssprings PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
if(USE_TRACY)
set_property(TARGET masssprings_tracy PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
else()
message(STATUS "IPO / LTO not supported: <${error}>")
endif()
endif()
#if(NOT WIN32)
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if(supported)
message(STATUS "IPO / LTO enabled")
set_property(TARGET masssprings PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO not supported")
endif()
#endif()