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

Skip to content

Adding Tkinter GUI #679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions gui/romania_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from search import *
from search import breadth_first_tree_search as bfts, depth_first_tree_search as dfts, \
depth_first_graph_search as dfgs, breadth_first_search as bfs, uniform_cost_search as ucs
depth_first_graph_search as dfgs, breadth_first_search as bfs, uniform_cost_search as ucs, \
astar_search as asts
from utils import Stack, FIFOQueue, PriorityQueue
from copy import deepcopy

Expand Down Expand Up @@ -512,6 +513,14 @@ def uniform_cost_search(problem):
return best_first_graph_search(problem, lambda node: node.path_cost)


def astar_search(problem, h=None):
"""A* search is best-first graph search with f(n) = g(n)+h(n).
You need to specify the h function when you call astar_search, or
else in your Problem subclass."""
h = memoize(h or problem.h, 'h')
return best_first_graph_search(problem, lambda n: n.path_cost + h(n))


# TODO:
# Remove redundant code.
# Make the interchangbility work between various algorithms at each step.
Expand Down Expand Up @@ -561,6 +570,14 @@ def on_click():
display_final(final_path)
next_button.config(state="disabled")
counter += 1
elif "A* - Search" == algo.get():
node = astar_search(romania_problem)
if node is not None:
final_path = asts(romania_problem).solution()
final_path.append(start.get())
display_final(final_path)
next_button.config(state="disabled")
counter += 1


def reset_map():
Expand Down Expand Up @@ -589,7 +606,7 @@ def main():
root,
algo, "Breadth-First Tree Search", "Depth-First Tree Search",
"Breadth-First Search", "Depth-First Graph Search",
"Uniform Cost Search")
"Uniform Cost Search", "A* - Search")
Label(root, text="\n Search Algorithm").pack()
algorithm_menu.pack()
Label(root, text="\n Start City").pack()
Expand Down