Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be8302f

Browse files
antmarakisnorvig
authored andcommitted
Search: Find Min Edges in GraphProblem (aimacode#553)
* Update search.py * Update test_search.py
1 parent 8b77d30 commit be8302f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

search.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,15 @@ def result(self, state, action):
835835
def path_cost(self, cost_so_far, A, action, B):
836836
return cost_so_far + (self.graph.get(A, B) or infinity)
837837

838+
def find_min_edge(self):
839+
"""Find minimum value of edges."""
840+
m = infinity
841+
for d in self.graph.dict.values():
842+
local_min = min(d.values())
843+
m = min(m, local_min)
844+
845+
return m
846+
838847
def h(self, node):
839848
"""h function is straight-line distance from a node's state to goal."""
840849
locs = getattr(self.graph, 'locations', None)

tests/test_search.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
LRTA_problem = OnlineSearchProblem('State_3', 'State_5', one_dim_state_space)
88

99

10+
def test_find_min_edge():
11+
assert romania_problem.find_min_edge() == 70
12+
13+
1014
def test_breadth_first_tree_search():
1115
assert breadth_first_tree_search(
1216
romania_problem).solution() == ['Sibiu', 'Fagaras', 'Bucharest']

0 commit comments

Comments
 (0)