It is difficult to determine which path among many options is the most direct way to reach a specific goal. Identifying the most efficient route through a series of steps can be complex.
The tool analyzes a list of movements and compares them against target goals to calculate a score. It measures how closely a sequence of steps matches the desired outcome.
It provides a clear way to measure how effectively a path reaches a goal.
It was run inside an isolated container with no network access. This is the exact command and the real output it produced — captured process output, not written by a model.
$ python3 state_space_efficiency.py
{
"paths": [
{
"path": [
"A"
],
"similarity": 0.0
},
{
"path": [
"A",
"B"
],
"similarity": 0.0
},
{
"path": [
"A",
"B",
"C"
],
"similarity": 0.25
},
{
"path": [
"A",
"B",
"C",
"D"
],
"similarity": 0.2
},
{
"path": [
"A",
"B",
"C",
"D",
"E"
],A screenshot of that run.
A clean run proves this does what is shown above, in a CPU-only sandbox. It is a small research demo — not a production tool, and nothing here was published anywhere.
All of it — 72 lines, one file, standard library only.
import sys
import json
from collections import deque
def build_graph(transitions):
graph = {}
for current, next_state in transitions:
if current not in graph:
graph[current] = []
graph[current].append(next_state)
return graph
def explore_paths(graph, start_state, max_depth=5):
paths = []
queue = deque()
queue.append(([start_state], start_state))
while queue:
path, current_state = queue.popleft()
if len(path) > max_depth:
continue
paths.append(path)
if current_state in graph:
for next_state in graph[current_state]:
new_path = path + [next_state]
queue.append((new_path, next_state))
return paths
def jaccard_similarity(path, goals):
path_states = set(path)
goal_states = set(goals)
intersection = path_states & goal_states
union = path_states | goal_states
return len(intersection) / len(union) if union else 0.0
def main():
try:
data = json.loads(sys.stdin.read())
except json.JSONDecodeError:
data = {
"transitions": [["A", "B"], ["B", "C"], ["C", "D"], ["D", "E"]],
"goals": ["C", "E"],
"start_state": "A"
}
transitions = data.get("transitions", [])
goals = data.get("goals", [])
start_state = data.get("start_state", "A")
graph = build_graph(transitions)
paths = explore_paths(graph, start_state)
if not paths:
print(json.dumps({"error": "No paths found."}))
return
scores = [jaccard_similarity(path, goals) for path in paths]
avg_score = sum(scores) / len(scores)
# Sort paths by similarity score descending
sorted_path_scores = sorted(zip(paths, scores), key=lambda x: -x[1])
result = {
"paths": [{"path": path, "similarity": score} for path, score in zip(paths, scores)],
"average_score": avg_score,
"sorted_paths": [{"path": p, "similarity": s} for p, s in sorted_path_scores],
"optimal_path": sorted_path_scores[0][0] if sorted_path_scores else None
}
print(json.dumps(result, indent=2))
if __name__ == "__main__":
main()