SlideShare a Scribd company logo
1 of 6
Download to read offline
Your task is to implement an informed search algorithm that will calculate a driving route
between two points in Romania with a minimal time and space cost. There is a
search_submission_tests.py file to help you along the way. We will be using an undirected
network representing a map of Romania.
you might only have to edit the def test_bidirectional_a_star(self) to complete the task
submission.py
# coding=utf-8
import pickle
import random
import unittest
import matplotlib.pyplot as plt
import networkx
from explorable_graph import ExplorableGraph
from submission import PriorityQueue, a_star, bidirectional_a_star
from visualize_graph import plot_search
class TestPriorityQueue(unittest.TestCase):
"""Test Priority Queue implementation"""
def test_append_and_pop(self):
"""Test the append and pop functions"""
queue = PriorityQueue()
temp_list = []
for _ in range(10):
a = random.randint(0, 10000)
queue.append((a, 'a'))
temp_list.append(a)
temp_list = sorted(temp_list)
for item in temp_list:
popped = queue.pop()
self.assertEqual(popped[0], item)
def test_fifo_property(self):
"Test the fifo property for nodes with same priority"
queue = PriorityQueue()
temp_list = [(1,'b'), (1, 'c'), (1, 'a')]
for node in temp_list:
queue.append(node)
for expected_node in temp_list:
actual_node = queue.pop()
#print("DEBUG FIFO", actual_node[-1], " ", expected_node[-1])
self.assertEqual(actual_node[-1], expected_node[-1])
class TestBasicSearch(unittest.TestCase):
"""Test the simple search algorithms: BFS, UCS, A*"""
def setUp(self):
"""Romania map data from Russell and Norvig, Chapter 3."""
with open('romania_graph.pickle', 'rb') as rom:
romania = pickle.load(rom)
self.romania = ExplorableGraph(romania)
self.romania.reset_search()
def test_a_star(self):
"""Test and visualize A* search"""
start = 'a'
goal = 'u'
node_positions = {n: self.romania.nodes[n]['pos'] for n in
self.romania.nodes.keys()}
self.romania.reset_search()
path = a_star(self.romania, start, goal)
self.draw_graph(self.romania, node_positions=node_positions,
start=start, goal=goal, path=path,
title='test_astar blue=start, yellow=goal, green=explored')
def test_a_star_num_explored(self):
"""Test A* for correct path and number of explored nodes"""
start = 'a'
goal = 'u'
node_positions = {n: self.romania.nodes[n]['pos'] for n in
self.romania.nodes.keys()}
self.romania.reset_search()
path = a_star(self.romania, start, goal)
self.assertEqual(path, ['a', 's', 'r', 'p', 'b', 'u']) # Check for correct path
explored_nodes = sum(list(self.romania.explored_nodes().values()))
self.assertEqual(explored_nodes, 8) # Compare explored nodes to reference
implementation
@staticmethod
def draw_graph(graph, node_positions=None, start=None, goal=None,
path=None, title=''):
"""Visualize results of graph search"""
explored = [key for key in graph.explored_nodes() if graph.explored_nodes()[key] > 0]
labels = {}
for node in graph:
labels[node] = node
if node_positions is None:
node_positions = networkx.spring_layout(graph)
networkx.draw_networkx_nodes(graph, node_positions)
networkx.draw_networkx_edges(graph, node_positions, style='dashed')
networkx.draw_networkx_labels(graph, node_positions, labels)
networkx.draw_networkx_nodes(graph, node_positions, nodelist=explored,
node_color='g')
edge_labels = networkx.get_edge_attributes(graph, 'weight')
networkx.draw_networkx_edge_labels(graph, node_positions, edge_labels=edge_labels)
if path is not None:
edges = [(path[i], path[i + 1]) for i in range(0, len(path) - 1)]
networkx.draw_networkx_edges(graph, node_positions, edgelist=edges,
edge_color='b')
if start:
networkx.draw_networkx_nodes(graph, node_positions,
nodelist=[start], node_color='b')
if goal:
networkx.draw_networkx_nodes(graph, node_positions,
nodelist=[goal], node_color='y')
plt.title(title)
plt.plot()
plt.show()
class TestBidirectionalSearch(unittest.TestCase):
"""Test the bidirectional search algorithms: UCS, A*"""
def setUp(self):
with open('romania_graph.pickle', 'rb') as rom:
romania = pickle.load(rom)
self.romania = ExplorableGraph(romania)
self.romania.reset_search()
def test_bidirectional_a_star(self):
"""Test and generate GeoJSON for bidirectional A* search"""
start = 'a'
goal = 'u'
node_positions = {n: self.romania.nodes[n]['pos'] for n in
self.romania.nodes.keys()}
path = bidirectional_a_star(self.romania, start, goal)
self.draw_graph(self.romania, node_positions=node_positions,
start=start, goal=goal, path=path,
title='test_bidirectional_astar blue=start, yellow=goal, green=explored')
@staticmethod
def draw_graph(graph, node_positions=None, start=None, goal=None,
path=None, title=''):
"""Visualize results of graph search"""
explored = [key for key in graph.explored_nodes() if graph.explored_nodes()[key] > 0]
labels = {}
for node in graph:
labels[node] = node
if node_positions is None:
node_positions = networkx.spring_layout(graph)
networkx.draw_networkx_nodes(graph, node_positions)
networkx.draw_networkx_edges(graph, node_positions, style='dashed')
networkx.draw_networkx_labels(graph, node_positions, labels)
networkx.draw_networkx_nodes(graph, node_positions, nodelist=explored,
node_color='g')
edge_labels = networkx.get_edge_attributes(graph, 'weight')
networkx.draw_networkx_edge_labels(graph, node_positions, edge_labels=edge_labels)
if path is not None:
edges = [(path[i], path[i + 1]) for i in range(0, len(path) - 1)]
networkx.draw_networkx_edges(graph, node_positions, edgelist=edges,
edge_color='b')
if start:
networkx.draw_networkx_nodes(graph, node_positions,
nodelist=[start], node_color='b')
if goal:
networkx.draw_networkx_nodes(graph, node_positions,
nodelist=[goal], node_color='y')
plt.title(title)
plt.plot()
plt.show()
if __name__ == '__main__':
unittest.main()

More Related Content

Similar to Your task is to implement an informed search algorithm that will cal.pdf

Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)BoneyGawande
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programmingLukasz Dynowski
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfUmarMustafa13
 
Nyc open-data-2015-andvanced-sklearn-expanded
Nyc open-data-2015-andvanced-sklearn-expandedNyc open-data-2015-andvanced-sklearn-expanded
Nyc open-data-2015-andvanced-sklearn-expandedVivian S. Zhang
 
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...Yao Yao
 
05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developer05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developerAndrea Antonello
 
Using the following code Install Packages pip install .pdf
Using the following code Install Packages   pip install .pdfUsing the following code Install Packages   pip install .pdf
Using the following code Install Packages pip install .pdfpicscamshoppe
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
support vector regression
support vector regressionsupport vector regression
support vector regressionAkhilesh Joshi
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Introzhang tao
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)Yeshwanth Kumar
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project FileDeyvessh kumar
 
NUMPY [Autosaved] .pptx
NUMPY [Autosaved]                    .pptxNUMPY [Autosaved]                    .pptx
NUMPY [Autosaved] .pptxcoolmanbalu123
 
Java patterns in Scala
Java patterns in ScalaJava patterns in Scala
Java patterns in ScalaRadim Pavlicek
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
 

Similar to Your task is to implement an informed search algorithm that will cal.pdf (20)

Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
 
Nyc open-data-2015-andvanced-sklearn-expanded
Nyc open-data-2015-andvanced-sklearn-expandedNyc open-data-2015-andvanced-sklearn-expanded
Nyc open-data-2015-andvanced-sklearn-expanded
 
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
 
Collection and framework
Collection and frameworkCollection and framework
Collection and framework
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developer05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developer
 
Using the following code Install Packages pip install .pdf
Using the following code Install Packages   pip install .pdfUsing the following code Install Packages   pip install .pdf
Using the following code Install Packages pip install .pdf
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
support vector regression
support vector regressionsupport vector regression
support vector regression
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project File
 
NUMPY [Autosaved] .pptx
NUMPY [Autosaved]                    .pptxNUMPY [Autosaved]                    .pptx
NUMPY [Autosaved] .pptx
 
Java patterns in Scala
Java patterns in ScalaJava patterns in Scala
Java patterns in Scala
 
NUMPY
NUMPY NUMPY
NUMPY
 
Javascript
JavascriptJavascript
Javascript
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
 

More from amie1085

You have been working for the Soto Board of Education in Japan for t.pdf
You have been working for the Soto Board of Education in Japan for t.pdfYou have been working for the Soto Board of Education in Japan for t.pdf
You have been working for the Soto Board of Education in Japan for t.pdfamie1085
 
You isolate two mutations in a bacteriophage. One causes larger plaq.pdf
You isolate two mutations in a bacteriophage. One causes larger plaq.pdfYou isolate two mutations in a bacteriophage. One causes larger plaq.pdf
You isolate two mutations in a bacteriophage. One causes larger plaq.pdfamie1085
 
You have been exposed to diverse social media phenomena since you ar.pdf
You have been exposed to diverse social media phenomena since you ar.pdfYou have been exposed to diverse social media phenomena since you ar.pdf
You have been exposed to diverse social media phenomena since you ar.pdfamie1085
 
You have been charged to develop a computational family tree for the.pdf
You have been charged to develop a computational family tree for the.pdfYou have been charged to develop a computational family tree for the.pdf
You have been charged to develop a computational family tree for the.pdfamie1085
 
You have received the following feedback from a client after present.pdf
You have received the following feedback from a client after present.pdfYou have received the following feedback from a client after present.pdf
You have received the following feedback from a client after present.pdfamie1085
 
________ se calcula sumando los gastos que no son en efectivo a las .pdf
________ se calcula sumando los gastos que no son en efectivo a las .pdf________ se calcula sumando los gastos que no son en efectivo a las .pdf
________ se calcula sumando los gastos que no son en efectivo a las .pdfamie1085
 
_____ 12) Todas las siguientes afirmaciones sobre el interfer�n son .pdf
_____ 12) Todas las siguientes afirmaciones sobre el interfer�n son .pdf_____ 12) Todas las siguientes afirmaciones sobre el interfer�n son .pdf
_____ 12) Todas las siguientes afirmaciones sobre el interfer�n son .pdfamie1085
 
_______ focuses on the leader and not on how he or she responds to t.pdf
_______ focuses on the leader and not on how he or she responds to t.pdf_______ focuses on the leader and not on how he or she responds to t.pdf
_______ focuses on the leader and not on how he or she responds to t.pdfamie1085
 
_______ es m�s probable que se subcontrate al mejor postor. Habili.pdf
_______ es m�s probable que se subcontrate al mejor postor. Habili.pdf_______ es m�s probable que se subcontrate al mejor postor. Habili.pdf
_______ es m�s probable que se subcontrate al mejor postor. Habili.pdfamie1085
 
[10pts] Show that i=0ni!ei=n!1uneu�du.pdf
[10pts] Show that i=0ni!ei=n!1uneu�du.pdf[10pts] Show that i=0ni!ei=n!1uneu�du.pdf
[10pts] Show that i=0ni!ei=n!1uneu�du.pdfamie1085
 
Zoom el desaf�o de escalar con COVID-19 en el horizonte Serie de .pdf
Zoom el desaf�o de escalar con COVID-19 en el horizonte Serie de .pdfZoom el desaf�o de escalar con COVID-19 en el horizonte Serie de .pdf
Zoom el desaf�o de escalar con COVID-19 en el horizonte Serie de .pdfamie1085
 
Zero trust is a security stance for networking based on not trusting.pdf
Zero trust is a security stance for networking based on not trusting.pdfZero trust is a security stance for networking based on not trusting.pdf
Zero trust is a security stance for networking based on not trusting.pdfamie1085
 
Zeynep, ABD�de mezuniyetini kutlamak ve bahar tatili i�in Meksika� ya .pdf
Zeynep, ABD�de mezuniyetini kutlamak ve bahar tatili i�in Meksika� ya .pdfZeynep, ABD�de mezuniyetini kutlamak ve bahar tatili i�in Meksika� ya .pdf
Zeynep, ABD�de mezuniyetini kutlamak ve bahar tatili i�in Meksika� ya .pdfamie1085
 
Zara es la cadena principal del minorista de ropa del Grupo Inditex,.pdf
Zara es la cadena principal del minorista de ropa del Grupo Inditex,.pdfZara es la cadena principal del minorista de ropa del Grupo Inditex,.pdf
Zara es la cadena principal del minorista de ropa del Grupo Inditex,.pdfamie1085
 
Z0.975=1.96 What does the 0.975 represent What does the 1.96 repr.pdf
Z0.975=1.96 What does the 0.975 represent What does the 1.96 repr.pdfZ0.975=1.96 What does the 0.975 represent What does the 1.96 repr.pdf
Z0.975=1.96 What does the 0.975 represent What does the 1.96 repr.pdfamie1085
 
y^=2.5+22x Using least-squares regression, the forecast for the number.pdf
y^=2.5+22x Using least-squares regression, the forecast for the number.pdfy^=2.5+22x Using least-squares regression, the forecast for the number.pdf
y^=2.5+22x Using least-squares regression, the forecast for the number.pdfamie1085
 
You have been at an industry trade show in Toronto all week. At the .pdf
You have been at an industry trade show in Toronto all week. At the .pdfYou have been at an industry trade show in Toronto all week. At the .pdf
You have been at an industry trade show in Toronto all week. At the .pdfamie1085
 
Your assignment is to research and investigate the Watergate Break I.pdf
Your assignment is to research and investigate the Watergate Break I.pdfYour assignment is to research and investigate the Watergate Break I.pdf
Your assignment is to research and investigate the Watergate Break I.pdfamie1085
 
You have a patient, Janet, that has screening for her son, Julian, t.pdf
You have a patient, Janet, that has screening for her son, Julian, t.pdfYou have a patient, Janet, that has screening for her son, Julian, t.pdf
You have a patient, Janet, that has screening for her son, Julian, t.pdfamie1085
 
You work as the IT administrator for a small business and are respon.pdf
You work as the IT administrator for a small business and are respon.pdfYou work as the IT administrator for a small business and are respon.pdf
You work as the IT administrator for a small business and are respon.pdfamie1085
 

More from amie1085 (20)

You have been working for the Soto Board of Education in Japan for t.pdf
You have been working for the Soto Board of Education in Japan for t.pdfYou have been working for the Soto Board of Education in Japan for t.pdf
You have been working for the Soto Board of Education in Japan for t.pdf
 
You isolate two mutations in a bacteriophage. One causes larger plaq.pdf
You isolate two mutations in a bacteriophage. One causes larger plaq.pdfYou isolate two mutations in a bacteriophage. One causes larger plaq.pdf
You isolate two mutations in a bacteriophage. One causes larger plaq.pdf
 
You have been exposed to diverse social media phenomena since you ar.pdf
You have been exposed to diverse social media phenomena since you ar.pdfYou have been exposed to diverse social media phenomena since you ar.pdf
You have been exposed to diverse social media phenomena since you ar.pdf
 
You have been charged to develop a computational family tree for the.pdf
You have been charged to develop a computational family tree for the.pdfYou have been charged to develop a computational family tree for the.pdf
You have been charged to develop a computational family tree for the.pdf
 
You have received the following feedback from a client after present.pdf
You have received the following feedback from a client after present.pdfYou have received the following feedback from a client after present.pdf
You have received the following feedback from a client after present.pdf
 
________ se calcula sumando los gastos que no son en efectivo a las .pdf
________ se calcula sumando los gastos que no son en efectivo a las .pdf________ se calcula sumando los gastos que no son en efectivo a las .pdf
________ se calcula sumando los gastos que no son en efectivo a las .pdf
 
_____ 12) Todas las siguientes afirmaciones sobre el interfer�n son .pdf
_____ 12) Todas las siguientes afirmaciones sobre el interfer�n son .pdf_____ 12) Todas las siguientes afirmaciones sobre el interfer�n son .pdf
_____ 12) Todas las siguientes afirmaciones sobre el interfer�n son .pdf
 
_______ focuses on the leader and not on how he or she responds to t.pdf
_______ focuses on the leader and not on how he or she responds to t.pdf_______ focuses on the leader and not on how he or she responds to t.pdf
_______ focuses on the leader and not on how he or she responds to t.pdf
 
_______ es m�s probable que se subcontrate al mejor postor. Habili.pdf
_______ es m�s probable que se subcontrate al mejor postor. Habili.pdf_______ es m�s probable que se subcontrate al mejor postor. Habili.pdf
_______ es m�s probable que se subcontrate al mejor postor. Habili.pdf
 
[10pts] Show that i=0ni!ei=n!1uneu�du.pdf
[10pts] Show that i=0ni!ei=n!1uneu�du.pdf[10pts] Show that i=0ni!ei=n!1uneu�du.pdf
[10pts] Show that i=0ni!ei=n!1uneu�du.pdf
 
Zoom el desaf�o de escalar con COVID-19 en el horizonte Serie de .pdf
Zoom el desaf�o de escalar con COVID-19 en el horizonte Serie de .pdfZoom el desaf�o de escalar con COVID-19 en el horizonte Serie de .pdf
Zoom el desaf�o de escalar con COVID-19 en el horizonte Serie de .pdf
 
Zero trust is a security stance for networking based on not trusting.pdf
Zero trust is a security stance for networking based on not trusting.pdfZero trust is a security stance for networking based on not trusting.pdf
Zero trust is a security stance for networking based on not trusting.pdf
 
Zeynep, ABD�de mezuniyetini kutlamak ve bahar tatili i�in Meksika� ya .pdf
Zeynep, ABD�de mezuniyetini kutlamak ve bahar tatili i�in Meksika� ya .pdfZeynep, ABD�de mezuniyetini kutlamak ve bahar tatili i�in Meksika� ya .pdf
Zeynep, ABD�de mezuniyetini kutlamak ve bahar tatili i�in Meksika� ya .pdf
 
Zara es la cadena principal del minorista de ropa del Grupo Inditex,.pdf
Zara es la cadena principal del minorista de ropa del Grupo Inditex,.pdfZara es la cadena principal del minorista de ropa del Grupo Inditex,.pdf
Zara es la cadena principal del minorista de ropa del Grupo Inditex,.pdf
 
Z0.975=1.96 What does the 0.975 represent What does the 1.96 repr.pdf
Z0.975=1.96 What does the 0.975 represent What does the 1.96 repr.pdfZ0.975=1.96 What does the 0.975 represent What does the 1.96 repr.pdf
Z0.975=1.96 What does the 0.975 represent What does the 1.96 repr.pdf
 
y^=2.5+22x Using least-squares regression, the forecast for the number.pdf
y^=2.5+22x Using least-squares regression, the forecast for the number.pdfy^=2.5+22x Using least-squares regression, the forecast for the number.pdf
y^=2.5+22x Using least-squares regression, the forecast for the number.pdf
 
You have been at an industry trade show in Toronto all week. At the .pdf
You have been at an industry trade show in Toronto all week. At the .pdfYou have been at an industry trade show in Toronto all week. At the .pdf
You have been at an industry trade show in Toronto all week. At the .pdf
 
Your assignment is to research and investigate the Watergate Break I.pdf
Your assignment is to research and investigate the Watergate Break I.pdfYour assignment is to research and investigate the Watergate Break I.pdf
Your assignment is to research and investigate the Watergate Break I.pdf
 
You have a patient, Janet, that has screening for her son, Julian, t.pdf
You have a patient, Janet, that has screening for her son, Julian, t.pdfYou have a patient, Janet, that has screening for her son, Julian, t.pdf
You have a patient, Janet, that has screening for her son, Julian, t.pdf
 
You work as the IT administrator for a small business and are respon.pdf
You work as the IT administrator for a small business and are respon.pdfYou work as the IT administrator for a small business and are respon.pdf
You work as the IT administrator for a small business and are respon.pdf
 

Recently uploaded

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 

Recently uploaded (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 

Your task is to implement an informed search algorithm that will cal.pdf

  • 1. Your task is to implement an informed search algorithm that will calculate a driving route between two points in Romania with a minimal time and space cost. There is a search_submission_tests.py file to help you along the way. We will be using an undirected network representing a map of Romania. you might only have to edit the def test_bidirectional_a_star(self) to complete the task submission.py # coding=utf-8 import pickle import random import unittest import matplotlib.pyplot as plt import networkx from explorable_graph import ExplorableGraph from submission import PriorityQueue, a_star, bidirectional_a_star from visualize_graph import plot_search class TestPriorityQueue(unittest.TestCase): """Test Priority Queue implementation""" def test_append_and_pop(self): """Test the append and pop functions""" queue = PriorityQueue() temp_list = [] for _ in range(10): a = random.randint(0, 10000) queue.append((a, 'a')) temp_list.append(a) temp_list = sorted(temp_list) for item in temp_list:
  • 2. popped = queue.pop() self.assertEqual(popped[0], item) def test_fifo_property(self): "Test the fifo property for nodes with same priority" queue = PriorityQueue() temp_list = [(1,'b'), (1, 'c'), (1, 'a')] for node in temp_list: queue.append(node) for expected_node in temp_list: actual_node = queue.pop() #print("DEBUG FIFO", actual_node[-1], " ", expected_node[-1]) self.assertEqual(actual_node[-1], expected_node[-1]) class TestBasicSearch(unittest.TestCase): """Test the simple search algorithms: BFS, UCS, A*""" def setUp(self): """Romania map data from Russell and Norvig, Chapter 3.""" with open('romania_graph.pickle', 'rb') as rom: romania = pickle.load(rom) self.romania = ExplorableGraph(romania) self.romania.reset_search() def test_a_star(self): """Test and visualize A* search""" start = 'a' goal = 'u' node_positions = {n: self.romania.nodes[n]['pos'] for n in self.romania.nodes.keys()} self.romania.reset_search() path = a_star(self.romania, start, goal)
  • 3. self.draw_graph(self.romania, node_positions=node_positions, start=start, goal=goal, path=path, title='test_astar blue=start, yellow=goal, green=explored') def test_a_star_num_explored(self): """Test A* for correct path and number of explored nodes""" start = 'a' goal = 'u' node_positions = {n: self.romania.nodes[n]['pos'] for n in self.romania.nodes.keys()} self.romania.reset_search() path = a_star(self.romania, start, goal) self.assertEqual(path, ['a', 's', 'r', 'p', 'b', 'u']) # Check for correct path explored_nodes = sum(list(self.romania.explored_nodes().values())) self.assertEqual(explored_nodes, 8) # Compare explored nodes to reference implementation @staticmethod def draw_graph(graph, node_positions=None, start=None, goal=None, path=None, title=''): """Visualize results of graph search""" explored = [key for key in graph.explored_nodes() if graph.explored_nodes()[key] > 0] labels = {} for node in graph: labels[node] = node if node_positions is None: node_positions = networkx.spring_layout(graph) networkx.draw_networkx_nodes(graph, node_positions)
  • 4. networkx.draw_networkx_edges(graph, node_positions, style='dashed') networkx.draw_networkx_labels(graph, node_positions, labels) networkx.draw_networkx_nodes(graph, node_positions, nodelist=explored, node_color='g') edge_labels = networkx.get_edge_attributes(graph, 'weight') networkx.draw_networkx_edge_labels(graph, node_positions, edge_labels=edge_labels) if path is not None: edges = [(path[i], path[i + 1]) for i in range(0, len(path) - 1)] networkx.draw_networkx_edges(graph, node_positions, edgelist=edges, edge_color='b') if start: networkx.draw_networkx_nodes(graph, node_positions, nodelist=[start], node_color='b') if goal: networkx.draw_networkx_nodes(graph, node_positions, nodelist=[goal], node_color='y') plt.title(title) plt.plot() plt.show() class TestBidirectionalSearch(unittest.TestCase): """Test the bidirectional search algorithms: UCS, A*""" def setUp(self): with open('romania_graph.pickle', 'rb') as rom: romania = pickle.load(rom) self.romania = ExplorableGraph(romania) self.romania.reset_search() def test_bidirectional_a_star(self):
  • 5. """Test and generate GeoJSON for bidirectional A* search""" start = 'a' goal = 'u' node_positions = {n: self.romania.nodes[n]['pos'] for n in self.romania.nodes.keys()} path = bidirectional_a_star(self.romania, start, goal) self.draw_graph(self.romania, node_positions=node_positions, start=start, goal=goal, path=path, title='test_bidirectional_astar blue=start, yellow=goal, green=explored') @staticmethod def draw_graph(graph, node_positions=None, start=None, goal=None, path=None, title=''): """Visualize results of graph search""" explored = [key for key in graph.explored_nodes() if graph.explored_nodes()[key] > 0] labels = {} for node in graph: labels[node] = node if node_positions is None: node_positions = networkx.spring_layout(graph) networkx.draw_networkx_nodes(graph, node_positions) networkx.draw_networkx_edges(graph, node_positions, style='dashed') networkx.draw_networkx_labels(graph, node_positions, labels) networkx.draw_networkx_nodes(graph, node_positions, nodelist=explored, node_color='g') edge_labels = networkx.get_edge_attributes(graph, 'weight') networkx.draw_networkx_edge_labels(graph, node_positions, edge_labels=edge_labels) if path is not None: edges = [(path[i], path[i + 1]) for i in range(0, len(path) - 1)]
  • 6. networkx.draw_networkx_edges(graph, node_positions, edgelist=edges, edge_color='b') if start: networkx.draw_networkx_nodes(graph, node_positions, nodelist=[start], node_color='b') if goal: networkx.draw_networkx_nodes(graph, node_positions, nodelist=[goal], node_color='y') plt.title(title) plt.plot() plt.show() if __name__ == '__main__': unittest.main()