Evaluating Code Generation Under Complex Constraints: Time-Dependent Shortest Paths and Deterministic Log Replay
This article presents an evaluation method for AI coding tools that goes beyond compilable output. It examines two hard problem classes: time-dependent shortest paths with departure phases and out-of-order log replay with idempotency and snapshots. It explains layered correctness criteria, hidden edge cases, pruning discipline, deterministic replay semantics, and a generator/checker protocol. It also shows how to classify failures and turn results into reusable engineering practices for tool selection and prompt iteration.
In enterprise engineering, evaluation of intelligent coding tools often stops at whether the generated code compiles. The real separation appears on tasks with multiple optimization objectives, strict integer semantics, large-scale constraints, and idempotent replay rules. Such tasks test algorithm selection, boundary handling, numerical stability, and implementation detail at the same time. The two hard problem classes below show how to design evaluations, interpret failure modes, and convert conclusions into reusable engineering practice.
Define Evaluation Goals Before Choosing a Model
Evaluating code generation starts with defining what “correct” means. For shortest-path problems, correctness is usually not a single scalar. The solution must first minimize arrival time, then minimize cumulative cost among states with the same arrival time, and then choose the lexicographically smallest node sequence when both arrival time and cost are equal. If the destination is unreachable, the result must explicitly return an empty result.
For log replay problems, correctness appears in the global sort key, idempotency-key deduplication, ownership validation, and snapshot visibility at a specific moment. If an evaluation compares only final numeric values without comparing paths or snapshot structures, it conflates “accidentally correct” with “semantically correct.”
Therefore, an evaluation should be split into three layers:
- Functional correctness: whether the output structure and constraints are satisfied.
- Optimization-objective hierarchy: whether the primary objective, secondary objective, and tie-breaking rules are strictly enforced.
- Engineering robustness: big integers, multi-edges, self-loops, empty graphs, identical start and end nodes, period equal to 1, zero-cost multiple paths, and similar cases.
Only when all three layers pass should a solution move on to performance and readability comparisons.
Time-Dependent Shortest Paths with Departure Phases: Algorithm Semantics to Cover
One common hard problem can be abstracted as follows: a directed graph whose edges carry a phase, period, duration, and cost. When arrival at a node occurs at time T, departure must wait until the departure time aligns with the phase modulo the period. Waiting is allowed, and arrival at the next node is the legal departure time plus the duration. The scale may reach hundreds of thousands of nodes and edges, time and period values may be very large integers, and floating point is prohibited.
The core implementation issue is not applying a textbook shortest-path algorithm. It is defining the state and relaxation rules correctly. The state should include at least the current node and current arrival time. Because of the period constraint, waiting time can be computed in closed form, avoiding loop-based simulation. The comparison key must be a lexicographic triple: arrival time, cumulative cost, and path lexicographic order. Path comparison cannot rely only on concatenated strings unless the lexicographic definition of the node-ID sequence is guaranteed to be consistent; otherwise, output becomes unstable when earliest arrival time and cost are both tied.
Hidden traps should be mandatory test cases, not bonus items:
- When the period is 1, almost any departure time is legal; an incorrect modulo implementation will degrade or fail.
- Multiple zero-cost equivalent edges amplify path-lexicographic errors.
- When the start equals the destination, the correct result is a trivial path with zero waiting and zero cost, not an unreachable result or an unnecessary loop.
- Multi-edges require all outgoing edges to be traversed during relaxation.
- Time upper bounds may be extremely large; any implementation that converts time to floating point or uses an intermediate type that may overflow should fail directly.
For complexity, naive time discretization is not feasible. A reasonable direction is to pop states from a priority queue ordered by arrival time, cost, and path key, while pruning with the best-known record per node. The pruning condition must be consistent with the comparison key: a state can be discarded only when the new state cannot be better in any of the three dimensions. The evaluation set should include counterexamples for both over-pruning that discards a candidate still needed for the optimal solution and under-pruning that causes timeouts. This distinguishes “correct idea but unusable engineering” from “usable engineering but incorrect semantics.”
Deterministic Replay of Out-of-Order Logs: Evaluate Consistency, Not Business Similarity
Another problem class abstracts a system as a collection of objects, each with an identifier, owner, and value. Events arrive out of order, with fields including timestamp, operator, idempotency key, operation type, and payload. Replay order must be ascending by timestamp, operator, and idempotency key. Duplicate idempotency keys under the same operator take effect only once. Creation occurs only when the identifier does not exist. Migration and deletion take effect only when the current owner equals the operator. A snapshot records the visible state of the specified identifier at that moment; a missing identifier is recorded as empty.
This problem tests the commonly required distributed-systems capabilities of replayability, auditability, and idempotency. Evaluation should not check only the final object table. It should verify snapshots one by one: a snapshot is an observation point, not a side-effect operation. It must not change object state, but it must see the precise view at that point in replay. Common errors include:
- Processing events in arrival order instead of sorting by the triple.
- Making idempotency keys globally unique instead of unique within an operator.
- Failing to validate ownership during migration, allowing unauthorized success.
- Returning old values in snapshots after deletion.
- Returning a default object instead of empty when the identifier was never created.
For implementation, keep a single timeline: perform a stable sort, scan linearly, maintain objects in a map, and maintain consumed idempotency keys per operator in a set. Snapshot output should deep-copy visible fields so later migrations cannot contaminate historical observations. If event volume is large, the evaluation should also observe whether the implementation misuses repeated full sorts or performs unnecessary global scans for snapshots.
Turning Two Hard Problems into a Comparable Evaluation Protocol
Use a fixed input generator and a reference checker instead of manual spot checks. The generator should cover:
- Sparse graphs and locally dense graphs.
- Worst-case combinations of phase and period.
- Extreme cost and duration values.
- Many zero-cost parallel edges.
- Lexicographic boundary paths.
- Start equal to destination.
- Unreachable sinks.
The log side should cover:
- Multiple operators interleaved within the same millisecond.
- Idempotent replay.
- Unauthorized migration.
- Deletion followed by recreation of the same identifier.
- Snapshots that reference nonexistent identifiers.
- Disorder ranging from slight to fully shuffled.
The checker should score in layers: structural validity, primary-objective optimality, secondary-objective optimality, tie-breaking rules, hidden cases, timeout, and memory. For outputs from intelligent coding tools, record failure types in addition to correct/incorrect status: reversed comparator, incorrect waiting formula, integer overflow, broken path reconstruction, snapshot semantics treated as an operation, and similar issues. These categories guide prompt and evaluation-set iteration better than a pass-rate percentage.
Practical Implications for Engineering Teams
- Prompts must explicitly state the comparison key and the unreachable convention; otherwise, models tend to optimize for “reachable is enough.”
- Require integer arithmetic and closed-form waiting, and prohibit floating point and magic numbers.
- Require assertion-level cases for self-loops, multi-edges, empty edge sets, and empty event lists.
- Include paths and snapshots in golden files instead of comparing only an earliest arrival time.
- Treat timeouts as seriously as incorrect answers: at the scale of hundreds of thousands of edges, an incorrect state definition cannot be fixed by asking the model to “think again.”
From a capability-profile perspective, time-dependent shortest paths expose discrete optimization and pruning discipline, while log replay exposes sort stability, ownership, and idempotency. Together, they help judge whether a tool is suitable for assisted coding in real workflows such as gateway scheduling, billing pipelines, configuration centers, or object collaboration. The evaluation conclusion should state “under which constraints, which failure types dominate,” rather than attaching a single good-or-bad label to a model.
Conclusion
The value of complex constrained programming problems is that they bind algorithm correctness, engineering boundaries, and deterministic replay into one protocol. Evaluate arrival time, cost, and lexicographic path separately; treat snapshots as read-only observation points; and use generators that cover period 1, zero-cost multiple paths, identical start and destination, and idempotency conflicts. This produces reproducible evaluations. If teams build internal problem banks and checkers according to this protocol, tool selection and prompting strategy for intelligent coding tools can move from subjective experience to regression-testable engineering quality metrics.
