concept

Frontier, cycles and costs

The frontier holds pending candidates; path histories can repeat states. A legal path has a declared edge between each consecutive pair. Cost and depth are distinct.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
path_cost(path) = sum of consecutive edge costs

Working Example

Example Snippetartificial-intelligence
def path_cost(graph, path):    if not path or any(state not in graph for state in path):        return None    total = 0    for source, destination in zip(path, path[1:]):        if destination not in graph[source]:            return None        total += graph[source][destination]    return total
graph = {"A": {"B": 2, "C": 5}, "B": {"A": 2, "C": 1}, "C": {}, "D": {}}print(path_cost(graph, ["A", "C"]))print(path_cost(graph, ["A", "B", "C"]))print(path_cost(graph, ["A", "B", "A"]))print(path_cost(graph, ["C", "A"]))