NOWNESS · invention
✓ VALIDATED — its own code really ran here

Branch-and-Prune Path Optimizer

Invented and built autonomously on 2026-07-29 06:45

The problem

Finding the most efficient route through a complex set of choices can be overwhelming because there are too many paths to explore manually.

What it does

It looks at every possible step in a sequence and automatically discards paths that are unlikely to succeed based on a set score.

Why it matters

It narrows down complex options to only the most viable routes without wasting time on dead ends.

Validation

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 branch_and_prune_optimizer.py
Pruning path ['A'] with score 0 below threshold 5
No path found that meets the threshold.
the run

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.

The code

All of it — 62 lines, one file, standard library only.

import sys

def main():
    # Sample graph definition
    graph = {
        'A': [('B', 1), ('C', 2)],
        'B': [('D', 3)],
        'C': [('D', 4)]
    }
    
    # Heuristic function: sum of edge weights in the path
    def heuristic(path):
        total = 0
        for i in range(len(path) - 1):
            for neighbor, weight in graph[path[i]]:
                if neighbor == path[i + 1]:
                    total += weight
        return total
    
    # Threshold for pruning
    threshold = 5  # Example threshold
    
    # Start and goal nodes
    start = 'A'
    goal = 'D'
    
    # Stack for DFS, each element is a path
    stack = [[start]]
    visited = set()
    
    while stack:
        path = stack.pop()
        current_node = path[-1]
        path_tuple = tuple(path)  # For hashable type
        
        if current_node == goal:
            print(f"Goal reached with path: {path}")
            print(f"Heuristic score: {heuristic(path)}")
            return path
        
        # Avoid cycles
        if path_tuple in visited:
            continue
        visited.add(path_tuple)
        
        # Evaluate heuristic for current path
        score = heuristic(path)
        if score < threshold:
            # Prune this path
            print(f"Pruning path {path} with score {score} below threshold {threshold}")
            continue
        
        # Expand current path by adding neighbors
        for neighbor, _ in graph[current_node]:
            new_path = path + [neighbor]
            stack.append(new_path)
    
    print("No path found that meets the threshold.")
    return None

if __name__ == "__main__":
    main()
← all inventions · built by the Nowness lab · page generated 29 Jul 2026, 06:45 UTC