Refuse the whole conversion rather than drop the inconvenient member
M4.2 moves individuals into the M4.1 record and does only that: no advance, no materialization back, no transfer between habitats, no persistence. Collapse is two phases over one sample. plan_collapse reads the members once and returns an immutable plan that already carries a validated cohort; commit applies exactly that plan and derives nothing, so replaying a committed sample cannot resample, and a record that would not validate fails during planning rather than after the ledger has moved. A controlled, suspended, dead or unsettled member refuses the whole plan instead of being skipped. Filtering would let a caller obtain a plan by omitting whoever was inconvenient, and the result would be indistinguishable from an honest conversion, which is the adversarial selection the model forbids. Ages are carried into declared classes and a member fitting none refuses the plan, so nobody is quietly moved or dropped for having nowhere to go. Reserves are summed per class and never redistributed, so the distribution M4.1 exists to keep survives the move. Conservation runs through the ledger rather than beside it: one atomic transaction, one leg per member, each moving that member's entire reserve, so the conserved total is unchanged by construction. Dual representation is closed from both ends. A member must be emptied exactly, and a reservoir holding anything other than what was sampled makes the plan stale rather than partly applicable. The destination is proved available before anything moves, so no rejection can strand biomass in a reservoir nothing owns. Reversing that order is detected by the tests, which is the point: the ordering prevents the failure rather than a comment claiming it cannot happen. Two gaps are stated rather than implied covered. This cannot tell whether the members offered were all there were, so completeness is the caller's obligation. And emptying a reservoir is not withdrawing the right to use it, because the ledger has no removal. ReservoirId and Transfer gain the defaulted comparisons every other value type here already has, so a plan's legs can be compared. Additive, and ADR-0037 says so rather than claiming no M1 change. All ten guards were confirmed load-bearing by removing each and rerunning. One of my own expectations was wrong rather than the code: a replayed commit reported stale_plan where I expected destination_occupied. Both are pure checks made before anything moves, so only the diagnosis differed; the destination check runs first now, because "this already happened" says more about a replay. Release 35/35, analysis, ASan 35/35 and clang-format all ran and passed here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+6
-1
@@ -47,7 +47,7 @@ target_link_libraries(evo_biology PUBLIC evo::accounting)
|
||||
target_compile_features(evo_biology PUBLIC cxx_std_23)
|
||||
evo_owned_target(evo_biology)
|
||||
|
||||
add_library(evo_ecology STATIC src/ecology/cohort.cpp)
|
||||
add_library(evo_ecology STATIC src/ecology/cohort.cpp src/ecology/collapse.cpp)
|
||||
add_library(evo::ecology ALIAS evo_ecology)
|
||||
target_include_directories(evo_ecology PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_link_libraries(evo_ecology PUBLIC evo::accounting evo::biology)
|
||||
@@ -115,6 +115,11 @@ if(BUILD_TESTING)
|
||||
evo_owned_target(evo-cohort-tests)
|
||||
add_test(NAME cohort-contracts COMMAND evo-cohort-tests)
|
||||
set_tests_properties(cohort-contracts PROPERTIES TIMEOUT 60)
|
||||
add_executable(evo-collapse-tests tests/collapse_tests.cpp)
|
||||
target_link_libraries(evo-collapse-tests PRIVATE evo::ecology)
|
||||
evo_owned_target(evo-collapse-tests)
|
||||
add_test(NAME collapse-contracts COMMAND evo-collapse-tests)
|
||||
set_tests_properties(collapse-contracts PROPERTIES TIMEOUT 60)
|
||||
add_executable(evo-ledger-tests tests/ledger_tests.cpp)
|
||||
target_link_libraries(evo-ledger-tests PRIVATE evo::accounting)
|
||||
evo_owned_target(evo-ledger-tests)
|
||||
|
||||
Reference in New Issue
Block a user