{
  "name": "quixbugs-python-shortest_paths",
  "description": "Fix bug in: shortest paths",
  "dataset": "quixbugs",
  "instruction": "There is a Python file called shortest_paths.py in the current directory. It also uses a Node class from node.py. The shortest paths implementation has a bug. Find and fix the bug. The fix should be minimal - typically a single line change. Do not rewrite the entire function. Do not modify node.py.",
  "setup_files": {
    "shortest_paths.py": "\ndef shortest_paths(source, weight_by_edge):\n    weight_by_node = {\n        v: float('inf') for u, v in weight_by_edge\n    }\n    weight_by_node[source] = 0\n\n    for i in range(len(weight_by_node) - 1):\n        for (u, v), weight in weight_by_edge.items():\n            weight_by_edge[u, v] = min(\n                weight_by_node[u] + weight,\n                weight_by_node[v]\n            )\n\n    return weight_by_node\n\n\n\"\"\"\nMinimum-Weight Paths\nbellman-ford\n\nBellman-Ford algorithm implementation\n\nGiven a directed graph that may contain negative edges (as long as there are no negative-weight cycles), efficiently calculates the minimum path weights from a source node to every other node in the graph.\n\nInput:\n    source: A node id\n    weight_by_edge: A dict containing edge weights keyed by an ordered pair of node ids\n\nPrecondition:\n    The input graph contains no negative-weight cycles\n\nOutput:\n   A dict mapping each node id to the minimum weight of a path from the source node to that node\n\nExample:\n    >>> shortest_paths('A', {\n        ('A', 'B'): 3,\n        ('A', 'C'): 3,\n        ('A', 'F'): 5,\n        ('C', 'B'): -2,\n        ('C', 'D'): 7,\n        ('C', 'E'): 4,\n        ('D', 'E'): -5,\n        ('E', 'F'): -1\n    })\n    {'A': 0, 'C': 3, 'B': 1, 'E': 5, 'D': 10, 'F': 4}\n\"\"\"\n",
    "node.py": "class Node:\n    def __init__(self, value=None, successor=None, successors=[], predecessors=[], incoming_nodes=[], outgoing_nodes=[]):\n        self.value = value\n        self.successor = successor\n        self.successors = successors\n        self.predecessors = predecessors\n        self.incoming_nodes = incoming_nodes\n        self.outgoing_nodes = outgoing_nodes\n\n    def successor(self):\n        return self.successor\n\n    def successors(self):\n        return self.successors\n\n    def predecessors(self):\n        return self.predecessors\n",
    "test_shortest_paths.py": "from shortest_paths import shortest_paths\nimport sys\n\npassed = 0\nfailed = 0\n\n# Simple graph\nresult = shortest_paths(\"A\", {\n    (\"A\", \"B\"): 1,\n    (\"A\", \"C\"): 4,\n    (\"B\", \"C\"): 2,\n    (\"B\", \"D\"): 5,\n    (\"C\", \"D\"): 1\n})\n\nif result[\"A\"] == 0: passed += 1\nelse: print(f\"FAIL A: expected 0, got {result['A']}\"); failed += 1\n\nif result[\"B\"] == 1: passed += 1\nelse: print(f\"FAIL B: expected 1, got {result['B']}\"); failed += 1\n\nif result[\"C\"] == 3: passed += 1\nelse: print(f\"FAIL C: expected 3, got {result['C']}\"); failed += 1\n\nif result[\"D\"] == 4: passed += 1\nelse: print(f\"FAIL D: expected 4, got {result['D']}\"); failed += 1\n\nprint(f\"{passed}/{passed+failed} tests passed\")\nif failed > 0: sys.exit(1)\n"
  },
  "verify": "cd $BENCH_WORK_DIR && python3 test_shortest_paths.py",
  "timeout": 180000,
  "tags": [
    "quixbugs",
    "python",
    "bug-fix",
    "graph"
  ]
}