All MicroEvals
module planner import schemas pub struct CycleError { pub:...
Create MicroEval
Header image for module planner

import schemas

pub struct CycleError {
pub:...

module planner import schemas pub struct CycleError { pub:...

Prompt

module planner import schemas pub struct CycleError { pub: cycle []string } pub fn (e CycleError) msg() string { return 'Dependency cycle detected: ${e.cycle.join(' -> ')}' } pub fn (e CycleError) code() int { return 0 } pub fn topological_sort(subtasks []schemas.SubtaskSpec) ![]schemas.SubtaskSpec { if subtasks.len == 0 { return []schemas.SubtaskSpec{} } mut id_to_spec := map[string]schemas.SubtaskSpec{} for s in subtasks { id_to_spec[s.id.str()] = s } mut in_degree := map[string]int{} mut adjacency := map[string][]string{} for s in subtasks { in_degree[s.id.str()] = 0 } for s in subtasks { for dep in s.dependency_ids { dep_key := dep.str() if dep_key !in id_to_spec { return error("Subtask '${s.id}' references unknown dependency '${dep_key}'") } adjacency[dep_key] << s.id.str() in_degree[s.id.str()]++ } } mut queue := []string{} for k, deg in in_degree { if deg == 0 { queue << k } } mut sorted_ids := []string{} for queue.len > 0 { current := queue[0] queue = queue[1..] sorted_ids << current for successor in adjacency[current] { in_degree[successor]-- if in_degree[successor] == 0 { queue << successor } } } if sorted_ids.len != subtasks.len { mut remaining := []string{} for k, deg in in_degree { if deg > 0 { remaining << k } } cycle := find_cycle(remaining, adjacency) return CycleError{cycle: cycle} } mut result := []schemas.SubtaskSpec{} for order, sid in sorted_ids { mut spec := id_to_spec[sid] spec.execution_order = order result << spec } return result } pub fn find_parallel_groups(subtasks []schemas.SubtaskSpec) [][]schemas.SubtaskSpec { if subtasks.len == 0 { return [][]schemas.SubtaskSpec{} } mut id_to_spec := map[string]schemas.SubtaskSpec{} for s in subtasks { id_to_spec[s.id.str()] = s } mut level := map[string]int{} for s in subtasks { if s.dependency_ids.len == 0 { level[s.id.str()] = 0 } else { mut max_dep_level := 0 for dep in s.dependency_ids { dep_level := level[dep.str()] or { 0 } if dep_level > max_dep_level { max_dep_level = dep_level } } level[s.id.str()] = max_dep_level + 1 } } mut groups_map := map[int][]schemas.SubtaskSpec{} mut max_level := 0 for s in subtasks { lvl := level[s.id.str()] groups_map[lvl] << s if lvl > max_level { max_level = lvl } } mut groups := [][]schemas.SubtaskSpec{} for lvl in 0 .. max_level + 1 { groups << groups_map[lvl] } return groups } pub fn critical_path_length(subtasks []schemas.SubtaskSpec) int { if subtasks.len == 0 { return 0 } mut id_to_spec := map[string]schemas.SubtaskSpec{} for s in subtasks { id_to_spec[s.id.str()] = s } mut depth := map[string]int{} mut max_depth := 0 // compute depths iteratively over the DAG for i := 0; i < subtasks.len; i++ { for s in subtasks { if s.id.str() in depth { continue } if s.dependency_ids.len == 0 { depth[s.id.str()] = 1 continue } mut all_known := true mut max_dep := 0 for dep in s.dependency_ids { if d := depth[dep.str()] { if d > max_dep { max_dep = d } } else { all_known = false } } if all_known { depth[s.id.str()] = 1 + max_dep } } } for s in subtasks { d := depth[s.id.str()] or { 1 } if d > max_depth { max_depth = d } } return max_depth } pub fn validate_budget_constraints(subtasks []schemas.SubtaskSpec, task_max_cost_usd f64, task_max_latency_seconds int) !(f64, int) { mut total_cost := 0.0 for s in subtasks { total_cost += s.max_cost_budget_usd } mut id_to_spec := map[string]schemas.SubtaskSpec{} for s in subtasks { id_to_spec[s.id.str()] = s } mut memo := map[string]int{} mut critical_latency := 0 for i := 0; i < subtasks.len; i++ { for s in subtasks { if s.id.str() in memo { continue } if s.dependency_ids.len == 0 { memo[s.id.str()] = s.max_time_budget_seconds continue } mut all_known := true mut max_dep := 0 for dep in s.dependency_ids { if d := memo[dep.str()] { if d > max_dep { max_dep = d } } else { all_known = false } } if all_known { memo[s.id.str()] = s.max_time_budget_seconds + max_dep } } } for s in subtasks { l := memo[s.id.str()] or { s.max_time_budget_seconds } if l > critical_latency { critical_latency = l } } if total_cost > task_max_cost_usd { return error("Plan estimated cost \$${total_cost:.2f} exceeds task budget \$${task_max_cost_usd:.2f}") } if critical_latency > task_max_latency_seconds { return error('Plan critical-path latency ${critical_latency}s exceeds task budget ${task_max_latency_seconds}s') } return total_cost, critical_latency } fn find_cycle(nodes []string, adjacency map[string][]string) []string { mut visited := map[string]bool{} mut result := []string{} for start_node in nodes { if start_node in visited { continue } mut stack := []string{} mut path_set := map[string]bool{} // iterative DFS with explicit frame stack mut frames := [][]string{} frames << [start_node] for frames.len > 0 { frame := frames[frames.len - 1] if frame.len == 0 { frames.delete_last() if stack.len > 0 { last := stack[stack.len - 1] stack.delete_last() path_set[last] = false } continue } node := frame[frame.len - 1] frames[frames.len - 1] = frame[..frame.len - 1] if node in visited { continue } visited[node] = true stack << node path_set[node] = true for neighbour in adjacency[node] { if neighbour !in nodes { continue } if neighbour !in visited { frames << [neighbour] } else if path_set[neighbour] { mut start := 0 for si in 0 .. stack.len { if stack[si] == neighbour { start = si break } } result = stack[start..].clone() result << neighbour return result } } } } return result } Send back the complete code with all the fixes. Fix each of the listed errors one by one, making sure to actually correct them so that there are 0 errors remaining. Keep the original imports, since the files exist. Write out every single character; do not abbreviate anything. Fix every error. There must be exactly one file. Do not write anything else; just output the complete code, and it must not contain any comments. Never, under any circumstances, use simplified, substitute, dummy, simulated, or fake code. Write the entire file as complete, unabridged, production-ready code in a single code block. It must be 100% error-free, a complete, error-free file, and must be submitted as a downloadable file. These requirements are mandatory and must be strictly adhered to. If no list of errors is provided, you must find all the errors and fix them. If there were comments in the original code, delete them. And most importantly: YOU MUST NEVER SIMPLIFY!

Drag to resize
Drag to resize
Drag to resize