Evaluating and Improving Complex Reasoning in LLMs: Benchmarking and Practical Tips

    This article explores why complex reasoning tasks act as a dividing line for large language model capabilities, using two representative problems: multi-objective shortest paths in time-dependent graphs and idempotent replay of out-of-order logs with snapshots. It breaks down the modeling essentials, algorithm skeletons, hidden pitfalls, and countermeasures for each task, then shares engineering practices for evaluation and score improvement, including layered test cases, separate scoring for correctness, complexity, and stability, feedback loops, and sandbox-based execution. Readers will find reusable Python examples and a repeatable evaluation pipeline approach.

    1. Why Complex Reasoning Tasks Separate Strong Models from the Rest

    In real development work, generating runnable code is no longer impressive. The real difficulty lies in problems with tightly coupled constraints and dense edge cases. The source material presents two typical task types: one is an earliest-arrival path with time-window and periodicity constraints, and the other is idempotent replay of out-of-order logs with snapshot recording. They share a common trait: the problem statement looks clear, but many constraints are hidden, and any modeling bias causes the solution to break on extreme data. When evaluating such tasks, the focus is not on “whether the model can outline an approach,” but on “whether it can stay correct and keep complexity under control under massive constraints.”

    2. Task One: Multi-Objective Shortest Path in a Time-Dependent Graph

    2.1 Problem Essence

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

    2.2 Modeling Essentials

    • Time is not a weight but part of the state; waiting time is determined by a congruence condition.
    • A legal departure time can be written as: if (T - phase) % period == 0 then depart = T, otherwise depart = T + (period - (T - phase) % period).
    • Arrival time is depart + duration, and the accumulated cost adds cost.

    2.3 Algorithm Skeleton (Illustrative)

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

    2.4 Hidden Pitfalls and Countermeasures

    • period=1 and cost=0 produce many equivalent paths, so lexicographic order is needed as a third key; maintain the path during relaxation or compare sequences when time and cost are equal.
    • When s==t, return (start_time, 0, [s]) directly.
    • Multi-edges must be processed one by one and must not be deduplicated.
    • Time can reach 1e18, so integer arithmetic is mandatory and floating point is forbidden.
    • The complexity is about O((n+m)log n), which is only manageable at a scale of 2e5 nodes and 3e5 edges.

    3. Task Two: Idempotent Replay of Out-of-Order Logs with Snapshots

    3.1 Rule Abstraction

    Logs are replayed in ascending order of (ts, actor, op_id); for the same actor, later occurrences of a duplicate op_id are ignored; add creates only if the id does not exist; move/delete take effect only when the owner matches; snapshot records the visible state of given ids, with missing ones recorded as None.

    3.2 Implementation Essentials

    • Sort first, then use a set to record the (actor, op_id) pairs that have taken effect.
    • Maintain object state with a dictionary mapping id -> (owner, value).
    • Snapshot output needs a stable order; sort the ids before retrieving values.
    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. key = (actor, op_id)
    7. if key in seen:
    8. continue
    9. seen.add(key)
    10. if kind == "add":
    11. oid, val = payload
    12. if oid not in objs:
    13. objs[oid] = [actor, val]
    14. elif kind == "move":
    15. oid, new_owner = payload
    16. if oid in objs and objs[oid][0] == actor:
    17. objs[oid][0] = new_owner
    18. elif kind == "delete":
    19. oid = payload
    20. if oid in objs and objs[oid][0] == actor:
    21. del objs[oid]
    22. elif kind == "snapshot":
    23. label, ids = payload
    24. snaps.append((label, [(i, objs[i][1] if i in objs else None) for i in sorted(ids)]))
    25. return snaps

    3.3 Common Mistakes

    • Forgetting idempotent deduplication, causing operations to take effect repeatedly.
    • Failing to verify the owner in move/delete.
    • Not recording missing ids as None in snapshots or producing unstable ordering.

    4. Engineering Practices for Evaluation and Score Improvement

    • Layer test cases: basic semantics, edge cases (s==t, empty edges, duplicate op_id), extreme scale, and equivalent paths.
    • Split metrics: score correctness, complexity, and stability separately to avoid “passing by chance.”
    • Feedback loop: have the model justify its complexity and edge-case handling, then iterate against hidden cases.
    • Engineering implementation: use a container platform for sandboxed execution, track failure clustering with logging services and monitoring alerts; store data and samples in object storage, and decouple asynchronous tasks with a message queue.
    • In Baidu AI Cloud related practice, the general capabilities above can support an evaluation pipeline, but the specific implementation should follow the official documentation to avoid assuming proprietary interfaces.

    5. Conclusion

    Improving complex reasoning ability depends on precise modeling of constraints, exhaustive verification of edge cases, and continuous refinement of complexity and stability. Only by turning evaluation into a repeatable pipeline can occasional correctness be transformed into stable reliability.