Evaluating and Improving Complex Reasoning in Large Language Models: Two Practical Benchmarks

    This article examines why complex reasoning has become the key differentiator between large language models, using two representative tasks: shortest-path routing under periodic time-window constraints and idempotent replay of out-of-order event logs. It breaks down the core difficulty of each problem, outlines a workable solution skeleton with Python reference implementations, and explains the most common failure patterns. It then shares six evaluation and score-improvement practices, covering layered test-case design, explicit hidden constraints, integer-only arithmetic, structured prompting, self-verification loops, and reproducible evaluation pipelines.

    1. Why Complex Reasoning Tasks Separate Model Capabilities

    Once general question answering and routine code generation approach saturation, the real differentiator is multi-constraint coupling, long derivation chains, and state consistency maintenance. The source material presents two highly representative problems: a shortest-path problem with time windows and periodic constraints, and an idempotent replay problem for out-of-order event logs. They share a common trait: the problem statement looks clear, but hidden constraints are dense, and a single boundary-handling mistake makes the entire result unusable. Such tasks cannot be solved by pattern matching; the model must genuinely build a state model and reason through it step by step.

    2. Scenario 1: Earliest-Arrival Path Under Periodic Constraints

    2.1 Problem Essence

    Given a directed graph where each edge carries a phase, period, duration, and cost, departure is allowed only when the difference between the current time and the phase is divisible by the period; otherwise the traveler must wait until the nearest legal moment. The objective is to minimize arrival time first, then minimize cost, and finally pick the lexicographically smallest path.

    2.2 Main Difficulties

    • Waiting-time computation: the legal departure moment is the current time rounded up to the period grid, which requires integer arithmetic to avoid floating-point error.
    • Extremely large time values: the start time can reach the order of 10^18, so any floating-point or 32-bit integer will overflow.
    • Three-tier objective ordering: time, cost, and path lexicographic order must be compared in strict layers, never merged into a single weight.
    • Equivalent-path explosion: when the period is 1 and the cost is 0, a large number of equivalent solutions exist, so the lexicographic rule must force convergence.
    • Degenerate cases: start equal to target, parallel edges, and zero-cost edges all need explicit handling.

    2.3 Workable Solution Skeleton

    The mainstream approach is a layered shortest path over the time dimension, using a priority queue that pops by the triple (arrival time, cost, path); the first arrival at the target is the answer. Recording the current best arrival time per node provides pruning and avoids state explosion.

    1. import heapq
    2. from math import inf
    3. def timed_shortest_path(n, edges, s, t, start_time):
    4. g = [[] for _ in range(n)]
    5. for u, v, phase, period, duration, cost in edges:
    6. g[u].append((v, phase, period, duration, cost))
    7. best = [inf] * n
    8. best[s] = start_time
    9. pq = [(start_time, 0, [s])]
    10. while pq:
    11. cur, c, path = heapq.heappop(pq)
    12. u = path[-1]
    13. if u == t:
    14. return (cur, c, path)
    15. if cur > best[u]:
    16. continue
    17. for v, phase, period, duration, cost in g[u]:
    18. r = (cur - phase) % period
    19. depart = cur if r == 0 else cur + (period - r)
    20. arr = depart + duration
    21. if arr < best[v]:
    22. best[v] = arr
    23. heapq.heappush(pq, (arr, c + cost, path + [v]))
    24. return None

    2.4 Common Failure Attribution

    Most failures do not come from a wrong algorithmic direction. They come from writing the waiting formula as a modulo instead of a round-up, from leaving path comparison out of the queue ordering key, and from failing to handle degenerate inputs beyond the zero-period case.

    3. Scenario 2: Idempotent Replay of Out-of-Order Logs

    3.1 Key Rules

    Logs are replayed in ascending order by the triple (timestamp, actor, idempotency key). Any later record repeating an idempotency key under the same actor is ignored. An add takes effect only if the object does not exist. Move and delete require the actor to equal the current owner. A snapshot records the visible state of the specified objects at that moment, with missing entries recorded as empty.

    3.2 Difficulty Breakdown

    • Sorting stability: the triple sort must be stable and total, so records with the same key do not drift in order.
    • Idempotent deduplication: the deduplication set must be isolated per actor, not shared globally.
    • Ownership validation: move and delete must validate ownership before executing, otherwise unauthorized state transitions occur.
    • Snapshot semantics: a snapshot only reads and never modifies, and must correctly express “does not exist”.

    3.3 Reference Implementation

    1. def reconcile(events):
    2. seen = set()
    3. objs = {}
    4. snaps = []
    5. for ts, actor, op_id, kind, payload in sorted(events, key=lambda e: (e[0], e[1], e[2])):
    6. if (actor, op_id) in seen:
    7. continue
    8. seen.add((actor, op_id))
    9. if kind == "add":
    10. oid, val = payload
    11. objs.setdefault(oid, {"owner": actor, "value": val})
    12. elif kind == "move":
    13. oid, new_owner = payload
    14. if objs.get(oid, {}).get("owner") == actor:
    15. objs[oid]["owner"] = new_owner
    16. elif kind == "delete":
    17. if objs.get(payload, {}).get("owner") == actor:
    18. objs.pop(payload, None)
    19. elif kind == "snapshot":
    20. label, ids = payload
    21. snaps.append((label, {i: objs.get(i) for i in ids}))
    22. return objs, snaps

    4. Building the Evaluation Set and Score-Improvement Practices

    1. Layer the test cases: progress through four levels — basic correctness, boundary degeneration, equivalent-solution convergence, and extreme scale.
    2. Make hidden constraints explicit: write the period, zero cost, parallel edges, and empty input into assertions.
    3. Keep the whole pipeline integer-only: use arbitrary-precision integers for time and cost, and forbid floating point in comparisons.
    4. Use structured prompts: ask the model to output the state definition and invariants before writing code, which noticeably reduces omission rates.
    5. Close the self-verification loop: have the model double-check both the provided samples and self-constructed boundary cases, and state the failure reason explicitly.
    6. Operationalize it: build a reproducible evaluation pipeline with container platforms, logging services, and monitoring alerts so results stay traceable.

    5. Conclusion

    Improving complex reasoning does not depend on a single trick; it comes from combining constraint modeling, exhaustive boundary handling, and a self-verification process. Turning these two scenarios into reusable evaluation templates lets teams make more robust decisions during model selection and iteration.