State-Space Graph Modelling

Context: FIT2004_MOC · the W5–W6 applied LO1 paradigm — when a problem breaks a standard algorithm, change the graph, not the algorithm ➔ vehicles are BFS (unweighted) and Dijkstra (weighted) Parent Framework: Graph

Quick Revision

  • 🎯 Objective: a vertex stops being a place and becomes a situation ➔ every variable that controls what you may do next is folded into the vertex, and the untouched algorithm runs on the enlarged graph.
  • 📦 Core Components: state | edges legal transitions only | start the initial state | answer over all accepting states.
  • ⚡ Key Constraint: modifying a known algorithm risks its correctness proof; transforming the input keeps the algorithm a black box, so its guarantee transfers for free — that trade-off is the examinable point.

📝 How It Works

1. The Symptom — the Standard Algorithm Must Revisit a Vertex

  • The tell ➔ the optimal route needs to enter a vertex twice, which every visited flag forbids by construction.
  • Worked symptom (dotted/solid edges) ➔ edges are solid or dotted, and no path may use two consecutive dotted edges. On dotted, solid, dotted, the only legal route is : step out to and back purely to spend a solid edge before the final dotted one.
  • Why plain BFS returns nothing ➔ it marks visited on first arrival, never returns to it, and reports unreachable — the answer is not merely suboptimal, it is wrong.
  • The diagnosis, stated for marks ➔ the current vertex is not a sufficient description of the situation; a second variable (was the last edge dotted?) decides which edges are legal from here.

2. Choosing the State

  • The rule ➔ the state must capture everything that changes what you may do next, and nothing else. Too little ⟹ the algorithm is wrong; too much ⟹ the graph blows up.
  • Dotted/solid ➔ ⟹ states.
  • Fuel (W6 applied P3) ➔ ⟹ states ➔ Dijkstra’s Algorithm §5 for the weighted worked shape.
  • Reading the multiplier off the question ➔ the extra variable is whatever the constraint sentence mentions besides position: “cannot use two dotted in a row” ⟹ a boolean; “tank holds litres” ⟹ a counter ; “at most transfers” ⟹ .
  • A revisit becomes two distinct vertices ➔ visiting twice in the original graph is visiting and once each in the state graph, which is exactly what restores the visited flag’s legality.

3. Wiring the Edges — Legality Is Structural, Not Conditional

  • The rule ➔ an edge exists iff the transition is legal; the algorithm then needs no extra test, because an illegal move is simply not in the graph.
  • From (last edge was solid, or we are at the start) ➔ everything is permitted: solid gives · dotted gives .
  • From (last edge was dotted) ➔ only solid , giving ; the dotted edges out of are absent, which is how “no two consecutive dotted” is enforced.
  • The graph turns directed ➔ even from an undirected input, transitions carry a before/after asymmetry, so the state graph is a digraph — say so before tracing.
  • Weights come from the cost model, not the topology ➔ in the fuel problem travelling is weight and refuelling is weight , because money is what is minimised; here every transition is one edge of the original walk, so all weights are and BFS suffices.

4. Start, Accept, and Reading the Answer

  • Start state ➔ — at the source no edge has been used, so both edge types are available.
  • Accepting states ➔ arriving at is a win however we got there ⟹ both and count.
  • The answer ➔ — forgetting the over accepting states is the most common way a correct model still scores zero.
  • Never re-derive the algorithm ➔ run BFS unmodified for unit costs, Dijkstra unmodified for non-negative weights; the shortest-path guarantee transfers because the state graph is just a graph.

5. The Sibling Move — Transform the Input, Not the Code (applied P4)

  • Same paradigm, other direction ➔ multi-source shortest path is solved either by modifying BFS (seed the queue with all sources at distance ) or by modifying the graph (add a super source joined to every source, run stock BFS, subtract ).
  • Why the sheet prefers the transformation ➔ modifying a complex algorithm risks breaking a correctness proof you did not write; transforming the input leaves the algorithm a black box, so you only have to justify that the transformation preserves the answer.
  • They coincide ➔ the super source’s first BFS iteration puts exactly the sources in the queue at distance — the seeded-queue solution offset by one ➔ Uninformed Search (BFS and DFS) §7.
  • The examinable sentence (LO1) ➔ map the problem onto one a known algorithm already solves, and justify that the mapping is answer-preserving — the transferable pattern outranks any named algorithm.

⚙️ Core Implementation

🔹 Build the state graph, then call BFS unchanged

⚖️ Complexity

Let be the number of values the extra variable can take.

QuantityOriginal graphState graphNote
Verticesdotted/solid · fuel
Edgeseach original edge spawns transitions
BFS (unit costs) for constant the is a constant factor
Dijkstra (weighted)fuel:
Auxiliary spaceone dist/visited slot per state
  • Constant is free, parametric is not ➔ a boolean flag leaves the bound unchanged; a capacity from the input multiplies it, so quote the bound in and say so.
  • Do not add redundant transitions ➔ at weight is already the composition of two single-litre edges; it only makes larger.

📊 Exam Execution Trace & Applied Exercises

Input: dotted, solid, dotted. State graph edges, with / for was the previous edge dotted: · · · · · · · .

Manual Execution Trace

BFS from .

StepServedNewly discoveredQueue afterdist set
, both
——
——

Final Extracted Output: , ⟹ answer , realising . The forbidden revisit of appears in the trace as two different vertices served at steps and — and — which is the whole point of the construction.

Applied Exercise

Problem: a graph has towns and roads; a tank holds litres and refuelling costs per litre in town . Size the state graph and quote the bound.

Final Extracted Output: feasible, and the bound must be quoted in — writing hides a factor of that came from the modelling decision, not from the algorithm.

⚠️ Common Mistakes

  • 💡 Under-specifying the state ➔ if two situations with the same state permit different next moves, the model is wrong; test the candidate state by asking does this alone determine my legal edges?
  • 💡 Keeping the answer at one accepting state ➔ take the over every state that counts as “arrived”, here and .
  • 💡 Forgetting the graph became directed ➔ transitions are asymmetric even from undirected input; drawing undirected edges in part (d) loses the constraint entirely.
  • 💡 Patching the algorithm instead of the graph ➔ an if inside Dijkstra invalidates the correctness proof you are relying on; the black-box argument is what makes the transformation defensible.

🧠 Active Recall