Food Packaging — C++¶
The C++ lives in optimaru/food_packaging/cpp/; the paths below are relative to it,
and its C++ tests are in tests/food_packaging/cpp/.
The food-packaging use case implemented on core/optimaru/ (the header-only
engine). Files:
fp/model/domain.hpp— domain structs, the mapping of the three score levels (hard / medium / soft) onto the engine's two (kMediumUnit = 10^10, declared once askMediumFold = MediumFold::intoSoft(10^10)and registered withMediumFoldOf<PackagingSchedule>), the sequence-shapeSolutionTraitsspecialization (including the position translation that hides the pinned prefix from the engine view)fp/constraints/*_cost.hpp— one plugin component per constraint (MaxEndTimeCost,AfterIdealEndTimeCost,SquaredMakespanCost,OperatorCleaningConflictCost,UnassignedJobsCost), each declaring itskDefaultWeight/kDefaultLevel;fp/constraints.hppassembles the default setfp/score/score_calculator.hpp— the full-recompute reference implementation (prepare/updateShadowVariables/score/analyze, whoseConstraintBreakdownmembers carry the registry names; C++ only)fp/score/incremental_calculator.hpp— incremental calculator on the before/after list hooks, O(changed line length) (re-derives the job times per line)fp/solver.hpp— engine wrapper.Line::operator_index(the second decision variable) is optimized alternately by hill climbing between engine legsfp/model/demo_data.cpp— the demo plant (5 lines, 100 jobs), drawn from a seededstd::mt19937_64(seed 37; Monday 00:00 == minute 0)cpp/main.cpp— runs the demo (default 10 s, non-zero exit when hard 0 is not reached)tests/food_packaging/cpp/fp_test.cpp— per-constraint hand-computed cases, 2000 random sequence moves cross-checked incremental==full, ScoreChecks::Full solve, pinning/pool/operator/ demo checkstests/food_packaging/cpp/fp_plugin_test.cpp— the plugin assembly == the monolith, plugin incremental == full, raw costs by hand (a positive and a zero case per constraint), the catalog (info()== the components' constants), the medium level (fold,hard()/soft()/ weight), ScoreChecks::Full plugin solves andon_new_bestreporting the same levels as the finalschedule.score
Build¶
cmake -B build -DCMAKE_BUILD_TYPE=Release -DOPTIMARU_USE_CASES=food_packaging
cmake --build build -j4
./build/food_packaging/fp_test && ./build/food_packaging/fp_plugin_test && ./build/food_packaging/fp_demo
Semantic notes¶
minStartTimeandpriorityare data fields that no constraint reads.- The first job gets a zero-length cleaning window at the line start and starts producing immediately.
- Job pairs on the same line also share an operator, but their cleaning windows are sequential and never overlap — the full calculator iterates the pairs as they are and the incremental calculator keeps only cross-line pairs (same meaning).
- Lines without an operator (
operator_index == -1) are grouped together, as if they shared one operator. - caveat:
Line::operator_indexis not searched together with the job order, move by move, but reassigned between engine legs. With operators >= lines the assignment is injective and the conflict constraint is always 0, so nothing is lost (the demo is this case); with operators < lines it is an alternating heuristic. - Pinned jobs must be a prefix of their line (validated by
prepare). Pinning the jobs that have already started (those "before now") always gives a prefix.