Ejemplo n.º 1
0
    def plan(self, grid_2D, agent_position, goal_position, save_maze=True):

        # current_position = {'z': int(self.zpos - self.origin_coord['z']), 'x': int(self.xpos - self.origin_coord['x'])}
        # print('current_position', current_position)

        frontier = []

        maze_map_dict = {}
        for z in range(agent_position[0] - self.scanning_range,
                       agent_position[0] + self.scanning_range +
                       1):  # 0, self.envsize):
            for x in range(agent_position[1] - self.scanning_range,
                           agent_position[1] + self.scanning_range + 1):
                if x >= 0 and x < self.envsize and z >= 0 and z < self.envsize:
                    item = grid_2D[z][x]
                    # if maze_map_dict.get(self.state_to_string(z, x)) is None:
                    #     maze_map_dict[self.state_to_string(z, x)] = set()
                    # maze_map_dict[self.state_to_string(z, x)].add(self.get_passable_neighbours(grid_2D, z, x))        import ipdb; ipdb.set_trace()
                    # import ipdb; ipdb.set_trace()

                    if self.is_passable(item):
                        maze_map_dict[self.state_to_string(
                            z,
                            x)] = self.get_passable_neighbours(grid_2D, z, x)

        print(maze_map_dict)

        print(maze_map_dict[self.state_to_string(*(agent_position))])
        print(maze_map_dict[self.state_to_string(*(goal_position))])
        # import ipdb; ipdb.set_trace()

        maze_map = search.UndirectedGraph(maze_map_dict)

        # initial_position = (self.range_z//2, self.range_x//2)

        maze_problem = search.GraphProblem(
            self.state_to_string(*(agent_position)),
            self.state_to_string(*(goal_position)), maze_map)
        # print('maze_map', maze_map)
        solution_node = search.uniform_cost_search(problem=maze_problem,
                                                   display=True)  #, h=None)
        print('solution_node', solution_node)

        if solution_node is not None:
            solution_path = [solution_node.state]
            current_node = solution_node.parent
            solution_path.append(current_node.state)
            while current_node.state != maze_problem.initial:
                current_node = current_node.parent
                solution_path.append(current_node.state)
        return solution_path
Ejemplo n.º 2
0
def main(problemID, mapID):
    problem = int(problemID)
    reward_hole = -1.0
    stochastic = False
    episodes = 100
    mapBase = mapID
    stats = {}

    # start from a known seed
    np.random.seed(12)

    # set up the environment
    env = LochLomondEnv(problem_id=problem,
                        is_stochastic=stochastic,
                        map_name_base=mapBase,
                        reward_hole=reward_hole)

    state_space_locations, state_space_actions, state_initial_id, \
        state_goal_id = env2statespace(env)

    # Insert the solution here to find and output the solution using A-star
    # define the states and actions in a table
    maze_map = search.UndirectedGraph(state_space_actions)
    maze_map.locations = state_space_locations

    maze_problem = search.GraphProblem(state_initial_id, state_goal_id,
                                       maze_map)

    for episode in range(episodes):  # iterate over episodes
        env.reset()  # reset the state of the env to the starting state
        iterations, node = my_astar_search_graph(problem=maze_problem, h=None)
        # -- Trace the solution --#
        solution_path = [node]
        cnode = node.parent
        solution_path.append(cnode)
        while cnode.state != state_initial_id:
            cnode = cnode.parent
            solution_path.append(cnode)

        print("----------------------------------------")
        print("Identified goal state:" + str(solution_path[0]))
        print("Solution trace:" + str(solution_path))
        print("Iterations:" + str(iterations))
        print("----------------------------------------")
        # log stats
    stats["solutiontrace"] = str(solution_path)
    stats["numberofiterations"] = str(iterations)

    return stats
Ejemplo n.º 3
0
alabama_map = search.UndirectedGraph(
    dict(Birmingham=dict(Tuscaloosa=45,
                         Auburn=120,
                         Montgomery=86,
                         Huntsville=90,
                         Mobile=219,
                         Dothan=197),
         Tuscaloosa=dict(Birmingham=45,
                         Auburn=160,
                         Montgomery=110,
                         Huntsville=140,
                         Mobile=211,
                         Dothan=227),
         Auburn=dict(Birmingham=120,
                     Tuscaloosa=160,
                     Montgomery=57,
                     Huntsville=212,
                     Mobile=195,
                     Dothan=130),
         Huntsville=dict(Birmingham=90,
                         Tuscaloosa=140,
                         Montgomery=166,
                         Auburn=212,
                         Mobile=302,
                         Dothan=279),
         Montgomery=dict(Birmingham=86,
                         Tuscaloosa=110,
                         Auburn=57,
                         Huntsville=166,
                         Mobile=144,
                         Dothan=120),
         Mobile=dict(Birmingham=219,
                     Tuscaloosa=211,
                     Auburn=195,
                     Montgomery=144,
                     Huntsville=302,
                     Dothan=184),
         Dothan=dict(Birmingham=197,
                     Tuscaloosa=227,
                     Auburn=130,
                     Montgomery=120,
                     Huntsville=279,
                     Mobile=184),
         Gardendale=dict(Birmingham=21),
         Fairhope=dict(Mobile=26, Birmingham=237)))
Ejemplo n.º 4
0
orange_map = search.UndirectedGraph(
    dict(
        PortJervis=dict(Middletown=34,
                        Warwick=37,
                        Monticello=30,
                        Montgomery=15,
                        Newburgh=69),
        Monticello=dict(PortJervis=30),
        Middletown=dict(PortJervis=34,
                        Warwick=29,
                        Newburgh=32,
                        Wallkill=33,
                        Washingtonville=12),
        Warwick=dict(PortJervis=37, GreenwoodLake=11, Newburgh=44),
        Newburgh=dict(Warwick=44,
                      Middletown=32,
                      Poughkeepsie=30,
                      Wallkill=32,
                      NewWindsor=7,
                      Washingtonville=34,
                      Montgomery=45,
                      PortJervis=69),
        NewWindsor=dict(Washingtonville=11, Newburgh=7),
        Poughkeepsie=dict(Newburgh=30),
        Montgomery=dict(PortJervis=15, Newburgh=45),
        Wallkill=dict(Middletown=33, Newburgh=32),
        Washingtonville=dict(Warwick=25,
                             NewWindsor=11,
                             Middletown=12,
                             Newburgh=34),
    ))
Ejemplo n.º 5
0
sumner_map = search.UndirectedGraph(dict(
 #   Portland=dict(Mitchellville=7, Fairfield=17, Cottontown=18),
 #   Cottontown=dict(Portland=18),
 #   Fairfield=dict(Mitchellville=21, Portland=17),
 #   Mitchellville=dict(Portland=7, Fairfield=21),


 #   A=dict(D=70, C=80, B=140),
 #   D=dict(A=70,C=100,Z=200),
 #   C=dict(A=80,D=100,E=80,B=70),
 #   B=dict(A=140,C=70,E=90,Z=130),
 #   E=dict(C=80,B=90,Z=60),
 #   Z=dict(D=200,E=60,B=130),


#    A=dict(B=70,C=80,E=100),
#    B=dict(A=70),
#    C=dict(A=80,E=100,D=60),
#    E=dict(A=100,C=100,Z=150),
#    D=dict(C=60,Z=90),
#    Z=dict(D=90,E=150),


    A=dict(Z=75,S=140,T=118),
    Z=dict(O=71,A=75),
    S=dict(O=151,R=80,F=99),
    T=dict(A=118,L=111),
    O=dict(Z=71,S=151),
    L=dict(T=111,M=70),
    M=dict(L=70,D=75),
    D=dict(M=75,C=120),
    R=dict(S=80,C=146,P=97),
    C=dict(R=146,P=138,D=120),
    F=dict(S=99,B=211),
    P=dict(R=97,C=138,B=101),
    B=dict(G=90,P=101,F=211),
))
Ejemplo n.º 6
0
import search
from math import (cos, pi)

# A sample map problem
Butte_map = search.UndirectedGraph(
    dict(
        Missoula=dict(Lolo=21, Philipsburg=71, Helena=111, Anaconda=94),
        Lolo=dict(Hamilton=40, Missoula=21),
        Hamilton=dict(Lolo=40, Butte=159, Sula=38),
        Salmon=dict(Cobalt=76, Bannack=128),
        DeerLodge=dict(Helena=64, Dillon=110, Anaconda=29),
        Anaconda=dict(Missoula=94, Sula=116, Dillon=70, DeerLodge=29),
        Butte=dict(Hamilton=159, Bozeman=81, Bannack=81, Astley=110),
        Dillon=dict(DeerLodge=110, Polaris=41, Anaconda=70),
        Bozeman=dict(Checkerboard=108, Helena=97, Butte=81),
        Polaris=dict(Dillon=41, Bannack=24, Jackson=24, Achlin=40),
        Jackson=dict(Sula=56, Polaris=24),
        Sula=dict(Jackson=56, Hamilton=38, Anaconda=116),
        Philipsburg=dict(Missoula=71),
        Cobalt=dict(Salmon=76),
        Bannack=dict(Salmon=128, Polaris=24, Butte=81),
        Checkerboard=dict(Bozeman=108),
        Astley=dict(Bentwood=32, Butte=110),
        Bentwood=dict(Astley=32, Achlin=70),
        Achlin=dict(Polaris=40, Bentwood=70),
    ))

#Butte_map = search.GraphProblem('Butte', 'DeerLodge', Butte_map) #BFS > DFS
Butte_map = search.GraphProblem(
    'Butte', 'Anaconda',
    Butte_map)  #UCS > BFS > DFS    where ">" means better(faster)
Ejemplo n.º 7
0
import search
from math import (cos, pi)

# A sample map problem
sumner_map = search.UndirectedGraph(
    dict(
        Portland=dict(Mitchellville=7, Fairfield=17, Cottontown=18),
        Cottontown=dict(Portland=18),
        Fairfield=dict(Mitchellville=21, Portland=17),
        Mitchellville=dict(Portland=7, Fairfield=21),
    ))

sumner_puzzle = search.GraphProblem('Cottontown', 'Mitchellville', sumner_map)

sumner_puzzle.label = 'Sumner'
sumner_puzzle.description = '''
An abbreviated map of Sumner County, TN.
This map is unique, to the best of my knowledge.
'''

romania_map = search.UndirectedGraph(
    dict(
        A=dict(Z=75, S=140, T=118),
        Z=dict(O=71, A=75),
        S=dict(O=151, R=80, F=99),
        T=dict(A=118, L=111),
        O=dict(Z=71, S=151),
        L=dict(T=111, M=70),
        M=dict(L=70, D=75),
        D=dict(M=75, C=120),
        R=dict(S=80, C=146, P=97),
Ejemplo n.º 8
0
sumner_map = search.UndirectedGraph(
    dict(
        #Portland=dict(Mitchellville=7, Fairfield=17, Cottontown=18),
        #Cottontown=dict(Portland=18),
        #Fairfield=dict(Mitchellville=21, Portland=17),
        #Mitchellville=dict(Portland=7, Fairfield=21),

        #cost is in estimated minutes of drive time from
        #https://distancefrom.co.uk
        #https://distancefrom.co.uk/from-machynlleth-to-dolgellau for example
        Newtown=dict(Machynlleth=46,
                     Dolgellau=61,
                     Conwy=113,
                     Bangor=131,
                     Caernarnfon=123,
                     Betws_y_coed=110,
                     Pwllheli=117,
                     Llangollen=63,
                     Welshpool=22,
                     Aberystwyth=70),
        Machynlleth=dict(Newtown=46,
                         Dolgellau=27,
                         Conwy=100,
                         Bangor=103,
                         Caernarnfon=88,
                         Betws_y_coed=74,
                         Wrexham=93,
                         Llangollen=81,
                         Welshpool=57,
                         Aberystwyth=33),
        Dolgellau=dict(Newtown=61,
                       Machynlleth=27,
                       Conwy=77,
                       Bangor=81,
                       Caernarnfon=65,
                       Betws_y_coed=52,
                       Wrexham=78,
                       Llangollen=63,
                       Welshpool=57,
                       Aberystwyth=60),
        Conwy=dict(Newtown=113,
                   Machynlleth=100,
                   Dolgellau=77,
                   Bangor=24,
                   Caernarnfon=31,
                   Betws_y_coed=31,
                   Wrexham=60,
                   Llangollen=72,
                   Welshpool=96,
                   Aberystwyth=133),
        Bangor=dict(Newtown=131,
                    Machynlleth=103,
                    Dolgellau=81,
                    Conwy=24,
                    Caernarnfon=18,
                    Betws_y_coed=37,
                    Wrexham=77,
                    Llangollen=86,
                    Welshpool=113,
                    Aberystwyth=136),
        Caernarnfon=dict(Newtown=123,
                         Machynlleth=88,
                         Dolgellau=65,
                         Conwy=31,
                         Bangor=18,
                         Betws_y_coed=44,
                         Wrexham=86,
                         Pwllheli=34,
                         Llangollen=93,
                         Welshpool=117,
                         Aberystwyth=121),
        Betws_y_coed=dict(Newtown=110,
                          Machynlleth=74,
                          Dolgellau=52,
                          Conwy=31,
                          Bangor=37,
                          Caernarnfon=44,
                          Wrexham=67,
                          Pwllheli=61,
                          Llangollen=51,
                          Welshpool=89,
                          Aberystwyth=108),
        Wrexham=dict(Machynlleth=93,
                     Dolgellau=78,
                     Conwy=60,
                     Bangor=77,
                     Caernarnfon=86,
                     Betws_y_coed=67,
                     Pwllheli=113,
                     Llangollen=22,
                     Aberystwyth=126),
        Pwllheli=dict(Newtown=117,
                      Caernarnfon=34,
                      Betws_y_coed=61,
                      Wrexham=113,
                      Llangollen=96,
                      Welshpool=111,
                      Aberystwyth=114),
        Llangollen=dict(Newtown=63,
                        Machynlleth=81,
                        Dolgellau=63,
                        Conwy=72,
                        Bangor=86,
                        Caernarnfon=93,
                        Betws_y_coed=51,
                        Wrexham=22,
                        Pwllheli=96,
                        Welshpool=45,
                        Aberystwyth=114),
        Welshpool=dict(Newtown=22,
                       Machynlleth=57,
                       Dolgellau=57,
                       Conwy=96,
                       Bangor=113,
                       Caernarnfon=117,
                       Betws_y_coed=89,
                       Pwllheli=111,
                       Llangollen=45,
                       Aberystwyth=90),
        Aberystwyth=dict(Newtown=70,
                         Machynlleth=33,
                         Dolgellau=60,
                         Conwy=133,
                         Bangor=136,
                         Caernarnfon=121,
                         Betws_y_coed=108,
                         Wrexham=126,
                         Pwllheli=114,
                         Llangollen=114,
                         Welshpool=90)))
Ejemplo n.º 9
0
# An abbreviated map of Sumner County, TN.
# This map is unique, to the best of my knowledge.
# '''

# My map
Germany_map = search.UndirectedGraph(
    dict(Bremen=dict(Hamburg=81, Hanover=93, Dortmund=157),
         Hamburg=dict(Bremen=81, Hanover=119, Berlin=175),
         Hanover=dict(Bremen=93,
                      Hamburg=119,
                      Berlin=189,
                      Dortmund=164,
                      Leipzig=171,
                      Frankfurt=221),
         Berlin=dict(Hamburg=175, Hanover=189, Leipzig=137, Dresden=136),
         Leipzig=dict(Berlin=137, Hanover=171, Nuremberg=170, Dresden=82),
         Dresden=dict(Berlin=136, Leipzig=82, Nuremberg=210),
         Dortmund=dict(Bremen=157, Hanover=164, Frankfurt=149, Essen=31),
         Essen=dict(Dortmund=31, Dusseldorf=34),
         Dusseldorf=dict(Essen=34, Cologne=40),
         Cologne=dict(Dusseldorf=40, Frankfurt=120),
         Frankfurt=dict(Cologne=120, Hanover=221, Nuremberg=152,
                        Stuttgart=129),
         Nuremberg=dict(Frankfurt=152, Leipzig=170, Stuttgart=132, Munich=101),
         Stuttgart=dict(Frankfurt=129, Nuremberg=132, Munich=136),
         Munich=dict(Stuttgart=136, Nuremberg=101)))
Germany_map.locations = dict(Bremen=(53.07, 8.8),
                             Hamburg=(53.55, 9.99),
                             Hanover=(52.37, 9.73),
                             Berlin=(52.52, 13.45),
                             Leipzig=(51.33, 12.37),
Ejemplo n.º 10
0
import search
from math import (cos, pi)

# A sample map problem
uk_map = search.UndirectedGraph(
    dict(Birmingham=dict(Oxford=68,
                         London=117,
                         Wolverhampton=23,
                         Cheltenham=67),
         Oxford=dict(London=84, Birmingham=68),
         London=dict(Birmingham=117, Oxford=84, Luton=104),
         Coventry=dict(Birmingham=43, Luton=204),
         Luton=dict(Coventry=204, london=104),
         Wolverhampton=dict(Birmingham=28),
         Cheltenham=dict(Birmingham=67),
         Buckingham=dict(
             Birmingham=101,
             Aylesbury=45,
         ),
         Aylesbury=dict(Buckingham=45, Watford=81),
         Watford=dict(Aylesbury=81, London=20)))
uk_map.locations = dict(Birmingham=(52.4862, 1.8904),
                        Oxford=(51.7520, 1.2577),
                        London=(51.5074, 0.1278),
                        Coventry=(52.4068, 1.5197),
                        Luton=(51.8787, 0.4200),
                        Wolverhampton=(52.5870, 2.1288),
                        Cheltenham=(51.8994, 2.0783),
                        Buckingham=(51.5014, 0.1419),
                        Aylesbury=(51.8156, 0.808),
                        Watford=(51.6565, 0.3903))
Ejemplo n.º 11
0
# ))
#
# sumner_puzzle = search.GraphProblem('Cottontown', 'Mitchellville', sumner_map)
#
# sumner_puzzle.label = 'Sumner'
# sumner_puzzle.description = '''
# An abbreviated map of Sumner County, TN.
# This map is unique, to the best of my knowledge.
# '''

ashgabat_map = search.UndirectedGraph(
    dict(
        Kommunizm=dict(Bezmein=10, Bagyr=14, Pilmile=60),
        Pewrize=dict(Bagyr=10, Shirvan=100, Faruj=130),
        Bagyr=dict(Bezmein=8, Kipchak=9, Pewrize=10, Kommunizm=14),
        Bezmein=dict(Bagyr=8, Kipchak=5, Kommunizm=10),
        Kipchak=dict(Bezmein=5, Bagyr=9),
        Shirvan=dict(Pewrize=100, Bojnourd=50, Faruj=42),
        Faruj=dict(Shirvan=42, Pewrize=130, Bojnourd=98),
        Bojnourd=dict(Faruj=98, Shirvan=50, Pilmile=50),
        Pilmile=dict(Bojnourd=50, Kommunizm=60),
    ))

ashgabat_puzzle = search.GraphProblem('Bojnourd', 'Kipchak', ashgabat_map)

ashgabat_puzzle.label = 'Ashgabat'
ashgabat_puzzle.description = '''
An abbreviated map of Ashgabat, Turkmenistan.
This map is unique, to the best of my knowledge.
'''

romania_map = search.UndirectedGraph(
Ejemplo n.º 12
0
from math import(cos, pi)

# A sample map problem
#sumner_map = search.UndirectedGraph(dict(
#   Portland=dict(Mitchellville=7, Fairfield=17, Cottontown=18),
#   Cottontown=dict(Portland=18),
#   Fairfield=dict(Mitchellville=21, Portland=17),
#   Mitchellville=dict(Portland=7, Fairfield=21),
#))

fayette_map = search.UndirectedGraph(dict(
   Uniontown=dict(Brownsville=15, Connellsville=12, Farmington=12, Perryopolis = 16, Smithfield = 9),
   Brownsville=dict(Uniontown = 15, Perryopolis = 10),
   Perryopolis=dict(Brownsville = 10, Connellsville = 13, Uniontown = 16),
   Connellsville=dict(Perryopolis=12, Ohiopyle=19, Uniontown = 12, Normalville = 8),
   Ohiopyle=dict(Farmington=7, Connellsville=19, Normalville =10, Markleysburg = 9),
   Farmington=dict(Ohiopyle=7, Uniontown=12, Markleysburg = 9),
   Smithfield=dict(Uniontown=9),
   Normalville=dict(Connellsville=8, Ohiopyle = 10),
   Markleysburg=dict(Farmington = 9, Ohiopyle =13)
))

fayette_map.locations = dict(
    Uniontown =(39.8973431,-79.742057),
    Brownsville=(40.0187766,-79.9103586),
    Perryopolis=(40.086682,-79.76838),
    Connellsville=(40.0147711,-79.6209733),
    Ohiopyle=(39.8687992,-79.5033132),
    Farmington = (39.8072964,-79.5831068),
    Smithfield = (39.8013187,-79.827878),
    Normalville = (39.9986836,-79.4656011),
Ejemplo n.º 13
0
import search
from math import(cos, pi)

sumner_map = search.UndirectedGraph(dict(
    Portland=dict(Mitchellville=7, Fairfield=17, Cottontown=18),
    Cottontown=dict(Portland=18),
    Fairfield=dict(Mitchellville=21, Portland=17),
    Mitchellville=dict(Portland=7, Fairfield=21),
))

sumner_puzzle = search.GraphProblem('Cottontown', 'Mitchellville', sumner_map)

sumner_puzzle.description = '''
An abbreviated map of Sumner County, TN.
This map is unique, to the best of my knowledge.
'''

myPuzzles = [
    sumner_puzzle,
]
from matplotlib import lines

from ipywidgets import interact
import ipywidgets as widgets
from IPython.display import display
import time

import search as s

romania_map = s.UndirectedGraph(dict(
    Arad=dict(Zerind=75, Sibiu=140, Timisoara=118),
    Bucharest=dict(Urziceni=85, Pitesti=101, Giurgiu=90, Fagaras=211),
    Craiova=dict(Drobeta=120, Rimnicu=146, Pitesti=138),
    Drobeta=dict(Mehadia=75),
    Eforie=dict(Hirsova=86),
    Fagaras=dict(Sibiu=99),
    Hirsova=dict(Urziceni=98),
    Iasi=dict(Vaslui=92, Neamt=87),
    Lugoj=dict(Timisoara=111, Mehadia=70),
    Oradea=dict(Zerind=71, Sibiu=151),
    Pitesti=dict(Rimnicu=97),
    Rimnicu=dict(Sibiu=80),
    Urziceni=dict(Vaslui=142)))

romania_map.locations = dict(
    Arad=(91, 492), Bucharest=(400, 327), Craiova=(253, 288),
    Drobeta=(165, 299), Eforie=(562, 293), Fagaras=(305, 449),
    Giurgiu=(375, 270), Hirsova=(534, 350), Iasi=(473, 506),
    Lugoj=(165, 379), Mehadia=(168, 339), Neamt=(406, 537),
    Oradea=(131, 571), Pitesti=(320, 368), Rimnicu=(233, 410),
    Sibiu=(207, 457), Timisoara=(94, 410), Urziceni=(456, 350),
    Vaslui=(509, 444), Zerind=(108, 531))
Ejemplo n.º 15
0
import search
from math import (cos, pi)

# A sample map problem
sumner_map = search.UndirectedGraph(
    dict(
        Amsterdam=dict(Utrecht=53, Hague=60, Zwolle=112, Haarlem=20),
        Arnhem=dict(Eindhoven=84, Maastricht=167),
        Breda=dict(Rotterdam=50, Heerlen=148),
        Eindhoven=dict(Rotterdam=110, Utrecht=92, Arnhem=84, Maastricht=88),
        Haarlem=dict(Amsterdam=20, Hague=52),
        Hague=dict(Utrecht=68, Rotterdam=30, Amsterdam=60, Haarlem=52),
        Heerlen=dict(Maastricht=25, Breda=148),
        Maastricht=dict(Eindhoven=88, Arnhem=167, Heerlen=25),
        Rotterdam=dict(Utrecht=61, Hague=30, Eindhoven=110, Breda=50),
        Utrecht=dict(Amsterdam=53,
                     Zwolle=90,
                     Hague=68,
                     Eindhoven=92,
                     Rotterdam=61),
        Zwolle=dict(Utrecht=90, Amsterdam=112),
    ))

sumner_map.locations = dict(Amsterdam=(217, 386),
                            Arnhem=(378, 314),
                            Breda=(209, 201),
                            Eindhoven=(322, 169),
                            Haarlem=(201, 389),
                            Hague=(137, 330),
                            Heerlen=(286, 40),
                            Maastricht=(346, 32),
Ejemplo n.º 16
0
from math import(cos, pi)

# scale latitude and longitude,
# so that the distance between two points is an estimate of
# the minutes it takes to drive between them
def travelTime(lat, long):
    latFudge = 43 # convert degrees of latitude into travel minutes
    longFudge = latFudge * cos(long * pi / 180)
    return lat*latFudge, long*longFudge

sumner_map = search.UndirectedGraph(dict(
    Portland=dict(Mitchellville=7, Fairfield=17, Graball=18,
                  Cottontown=18),
    Cottontown=dict(Portland=18, Graball=14, S=6),
    Fairfield=dict(Graball=16,Mitchellville=21, Portland=17),
    Graball=dict(Cottontown=14, Fairfield=17, Portland=18),
    Mitchellville=dict(Portland=7, Fairfield=21, Q=6),
    Q=dict(Mitchellville=6, R=6),
    R=dict(Q=6, S=6),
    S=dict(R=6, Cottontown=6),
))
sumner_map.locations = dict(
    Portland=travelTime(36.581538,-86.6534912),
    Fairfield=travelTime(36.6182314,-86.3761194),
    Cottontown=travelTime(36.449575,-86.5697851),
    Graball=travelTime(36.4788454,-86.4750586),
    Mitchellville=travelTime(36.6334132,-86.5480556),
    Q=travelTime(36.49553455,-86.564352725),
    R=travelTime(36.5414941,-86.55892035),
    S=travelTime(36.58745365,-86.553487975),
)
Ejemplo n.º 17
0
import search
import math
from copy import deepcopy
from math import(cos, pi)

# A sample map problem
sumner_map = search.UndirectedGraph(dict(
    Portland=dict(Mitchellville=7, Fairfield=17, Cottontown=18),
    Cottontown=dict(Portland=18),
    Fairfield=dict(Mitchellville=21, Portland=17),
    Mitchellville=dict(Portland=7, Fairfield=21),
))
#converts latitude to miles:
def latitude(lat):
    return lat * 69
#converts longitude to miles:
def longitude(lat,long):
    return long * 69 * math.cos(math.radians(lat))
kc_map = search.UndirectedGraph(dict(
    KansasCity=dict(Independence=11,OverlandPark=12,Atchison=50,),
    Independence=dict(Higginsville=46,LeesSummit=18,KansasCity=11),
    Higginsville=dict(Warrensburg=22,Independence=46),
    LeesSummit=dict(Warrensburg=39,Independence=18),
    Warrensburg=dict(Sedalia=30,Higginsville=22,LeesSummit=39),
    Sedalia=dict(Warsaw=35,Warrensburg=30),
    Warsaw=dict(Clinton=30, Sedalia=35),
    Clinton=dict(RichHill=51,Warsaw=30),
    RichHill=dict(Ottawa=87,Clinton=51),
    Ottawa=dict(OsageCity=32,RichHill=87),
    OsageCity=dict(Ottawa=32),
    OverlandPark=dict(Olathe=12,Lawrence=35,KansasCity=12,Holton=98),
Ejemplo n.º 18
0
import search
from math import (cos, pi)

# A sample map problem
erie_map = search.UndirectedGraph(
    dict(Clarence=dict(Lancaster=11, Amherst=8),
         Amherst=dict(GrandIsland=15, Clarence=8, Buffalo=19),
         Lancaster=dict(Cheektowaga=4, Clarence=17, WestSeneca=10),
         GrandIsland=dict(Amherst=15, Buffalo=13),
         Cheektowaga=dict(Lancaster=4, Buffalo=10),
         WestSeneca=dict(OrchardPark=4, Buffalo=10),
         OrchardPark=dict(WestSeneca=4, Buffalo=18),
         Buffalo=dict(GrandIsland=13,
                      Amherst=19,
                      Cheektowaga=10,
                      WestSeneca=10,
                      OrchardPark=18),
         Hamburg=dict(Buffalo=12),
         Fredonia=dict(Hamburg=10),
         SBuffalo=dict(Buffalo=3)))

erie_map.locations = dict(Clarence=(27, 41),
                          Amherst=(19, 41),
                          Lancaster=(27, 30),
                          GrandIsland=(4, 40),
                          Cheektowaga=(23, 31),
                          WestSeneca=(24, 22),
                          OrchardPark=(26, 17),
                          Buffalo=(9, 28),
                          Hamburg=(20, 17),
                          Fredonia=(10, 10),
Ejemplo n.º 19
0
import search
from math import (cos, pi)

# A sample map problem
zimbabwe_map = search.UndirectedGraph(
    dict(
        Harare=dict(MountDarwin=118, Kadoma=102, Chikore=138, Mutare=197),
        Kadoma=dict(Harare=102, Gweru=107),
        Gweru=dict(Kadoma=107, Bulawayo=99, Lubimbi=267),
        Bulawayo=dict(Gweru=99, Lubimbi=183),
        Lubimbi=dict(Gweru=267, Bulawayo=183),
        Mutare=dict(Harare=197, Nyanga=98),
        MountDarwin=dict(Harare=118),
        Nyanga=dict(Chikore=106, Mutare=98),
        Chikore=dict(Harare=138, Nyanga=106),
    ))
zimbabwe_map.locations = dict(Harare=(613, 200),
                              MountDarwin=(662, 101),
                              Chikore=(731, 201),
                              Nyanga=(769, 234),
                              Mutare=(761, 311),
                              Kadoma=(512, 248),
                              Gweru=(502, 359),
                              Lumbini=(271, 264),
                              Bulawayo=(394, 423))

harare_mutare_puzzle = search.GraphProblem('Harare', 'Mutare', zimbabwe_map)

harare_mutare_puzzle.label = 'Zimbabwe Map'
harare_mutare_puzzle.description = '''
An abbreviated map of several cities in Zimbabwe.
Ejemplo n.º 20
0
swiss_map = search.UndirectedGraph(
    dict(Basel=dict(Bern=63,
                    Biel=59,
                    Fribourg=81,
                    Lausanne=127,
                    Lucerne=62,
                    Lugano=166,
                    Schaffhausen=85,
                    Sion=157,
                    Thun=77,
                    Winterhur=67,
                    Zug=69,
                    Zurich=54),
         Bern=dict(Basel=63,
                   Biel=27,
                   Fribourg=20,
                   Lausanne=64,
                   Lucerne=70,
                   Lugano=173,
                   Schaffhausen=108,
                   Sion=96,
                   Thun=18,
                   Winterhur=90,
                   Zug=84),
         Biel=dict(
             Basel=59,
             Fribourg=44,
             Lausanne=66,
             Lugano=169,
             Schaffhausen=104,
             Sion=120,
         ),
         Chur=dict(
             Lausanne=190,
             Lucerne=92,
             Lugano=111,
             Zug=74,
             Zurich=81,
         ),
         Fribourg=dict(
             Basel=81,
             Bern=20,
             Biel=44,
             Chur=159,
             Geneva=79,
             Lausanne=39,
             Lucerne=72,
             Lugano=177,
             Schaffhausen=111,
             Sion=81,
             Thun=31,
             Winterhur=109,
             Zug=89,
             Zurich=94,
         ),
         Geneva=dict(
             Fribourg=79,
             Lausanne=37,
             Lucerne=145,
             Lugano=211,
             Schaffhausen=181,
             Sion=85,
             Winterhur=179,
         ),
         Lausanne=dict(
             Basel=127,
             Bern=64,
             Biel=66,
             Chur=190,
             Fribourg=39,
             Geneva=37,
             Lucerne=108,
             Lugano=50,
             Schaffhausen=144,
             Sion=60,
             Thun=69,
             Winterhur=142,
             Zug=126,
             Zurich=129,
         ),
         Lucerne=dict(
             Basel=62,
             Bern=70,
             Chur=92,
             Fribourg=72,
             Geneva=145,
             Lausanne=108,
             Lugano=146,
             Schaffhausen=68,
             Sion=110,
             Thun=49,
             Zug=16,
         ),
         Lugano=dict(
             Basel=166,
             Bern=173,
             Biel=169,
             Chur=111,
             Fribourg=177,
             Geneva=211,
             Lausanne=50,
             Lucerne=146,
             Schaffhausen=202,
             Sion=125,
             Thun=145,
             Zug=160,
             Zurich=177,
         ),
         Schaffhausen=dict(
             Basel=85,
             Bern=108,
             Biel=104,
             Fribourg=111,
             Geneva=181,
             Lausanne=144,
             Lucerne=68,
             Lugano=202,
             Sion=163,
             Thun=103,
             Winterhur=18,
             Zurich=31,
         ),
         Sion=dict(
             Zurich=545,
             Basel=157,
             Bern=96,
             Biel=120,
             Fribourg=81,
             Geneva=85,
             Lausanne=60,
             Lucerne=110,
             Lugano=125,
             Schaffhausen=163,
             Winterhur=157,
         ),
         Thun=dict(
             Basel=77,
             Bern=18,
             Fribourg=31,
             Lausanne=69,
             Lucerne=49,
             Lugano=145,
             Schaffhausen=103,
             Winterhur=97,
             Zurich=83,
         ),
         Winterhur=dict(
             Basel=67,
             Bern=90,
             Fribourg=109,
             Geneva=179,
             Lausanne=142,
             Schaffhausen=18,
             Sion=157,
             Thun=97,
             Zug=35,
             Zurich=15,
         ),
         Zug=dict(
             Basel=69,
             Bern=84,
             Chur=74,
             Fribourg=89,
             Lausanne=126,
             Lucerne=16,
             Lugano=160,
             Winterhur=35,
             Zurich=20,
         ),
         Zurich=dict(Basel=54,
                     Bern=77,
                     Chur=81,
                     Fribourg=94,
                     Lausanne=129,
                     Lugano=177,
                     Schaffhausen=31,
                     Sion=545,
                     Thun=83,
                     Winterhur=15,
                     Zug=20)))
Ejemplo n.º 21
0
# A sample map problem
# sumner_map = search.UndirectedGraph(dict(
#    Portland=dict(Mitchellville=7, Fairfield=17, Cottontown=18),
#    Cottontown=dict(Portland=18),
#    Fairfield=dict(Mitchellville=21, Portland=17),
#    Mitchellville=dict(Portland=7, Fairfield=21),
# ))

gray_map = search.UndirectedGraph(dict(
   Boston=dict(Cambridge=14, Brookline=21, Chelsea=13, Arlington=3),
   Chelsea=dict(Boston=13, Winthrop=13, Somerville=16, Arlington=8),
   Winthrop=dict(Chelsea=13),
   Somerville=dict(Chelsea=16, Cambridge=10, Medford=5, Arlington=6),
   Cambridge=dict(Boston=14, Brookline=21, Watertown=16, Belmont=15,
                  Medford=15, Somerville=10, Arlington=10),
   Medford=dict(Cambridge=15, Belmont=5, Somerville=5),
   Brookline=dict(Boston=21, Cambridge=21, Watertown=20),
   Watertown=dict(Belmont=7, Cambridge=16, Brookline=20),
   Belmont=dict(Watertown=7, Cambridge=15, Medford=5),
   Arlington=dict(Somerville=6, Cambridge=10, Boston=3, Chelsea=8)
))

gray_puzzle = search.GraphProblem('Belmont', 'Chelsea', gray_map)

gray_puzzle.label = 'Boston'
gray_puzzle.description = '''
An abbreviated map of Sumner County, TN.
This map is unique, to the best of my knowledge.
'''
Ejemplo n.º 22
0
#    Fairfield=dict(Mitchellville=21, Portland=17),
#    Mitchellville=dict(Portland=7, Fairfield=21),
# ))

# HW 5 Custom map
wayne_map = search.UndirectedGraph(
    dict(Plymouth=dict(Livonia=11, Westland=17),
         Livonia=dict(Plymouth=14, Hamtramck=26, Detroit=23, Garden_City=10),
         Hamtramck=dict(Livonia=26, Detroit=12),
         Westland=dict(Plymouth=17, Garden_City=6, Wayne=10),
         Garden_City=dict(Livonia=10, Westland=6, Dearborn=16),
         Detroit=dict(Hamtramck=12, Livonia=23, Dearborn=13, Lincoln_Park=21),
         Wayne=dict(Westland=10, Dearborn=20, Romulus=12),
         Dearborn=dict(Garden_City=16,
                       Detroit=13,
                       Lincoln_Park=21,
                       Wayne=20,
                       Taylor=15),
         Lincoln_Park=dict(Detroit=21, Dearborn=11, Wyandotte=8),
         Belleville=dict(Romulus=11),
         Romulus=dict(Belleville=11, Wayne=12, Taylor=13),
         Taylor=dict(Romulus=13, Dearborn=15, Woodhaven=11),
         Wyandotte=dict(Lincoln_Park=8, Trenton=15),
         Flat_Rock=dict(Woodhaven=8),
         Woodhaven=dict(Flat_Rock=8, Taylor=11, Trenton=13),
         Trenton=dict(Woodhaven=13, Wyandotte=15)))

# sumner_puzzle = search.GraphProblem('Cottontown', 'Mitchellville', sumner_map)
myPuzzle = search.GraphProblem('Livonia', 'Belleville', wayne_map)

myPuzzle.label = 'Wayne County'
Ejemplo n.º 23
0
#))

#My map problem
from utils import is_in

potter_map = search.UndirectedGraph(
    dict(
        Amarillo=dict(Washburn=15, Panhandle=34),
        Canyon=dict(Umbarger=10, Happy=22, VigoPark=35),
        Washburn=dict(Amarillo=15, Claude=14),
        Umbarger=dict(Canyon=10, Arney=15),
        Arney=dict(Umbarger=15, Nazareth=15),
        Nazareth=dict(Arney=15, Happy=20, Tulia=22, Dimmit=12),
        Happy=dict(Nazareth=20, Canyon=22, Tulia=18),
        Tulia=dict(Nazareth=22, Happy=18, Silverton=30, VigoPark=20),
        Panhandle=dict(Claude=20, Fritch=25, Amarillo=34),
        Claude=dict(Washburn=14, Panhandle=20),
        Silverton=dict(Tulia=30, VigoPark=20),
        Dimmit=dict(Nazareth=12),
        VigoPark=dict(Tulia=20, Silverton=30, Happy=28, Claude=35),
        Masterson=dict(Amarillo=31, BoysRanch=30),
        Fritch=dict(Masterson=15, Panhandle=25),
        Groom=dict(Claude=10, Panhandle=10),
        Love=dict(Fritch=29, Groom=7),
    ))

potter_map.locations = dict(
    Amarillo=(20, 16),
    Canyon=(10, 35),
    Washburn=(35, 65),
    Umbarger=(0, 30),
Ejemplo n.º 24
0
#))

#sumner_puzzle = search.GraphProblem('Cottontown', 'Mitchellville', sumner_map)

#sumner_puzzle.label = 'Sumner Map'
#sumner_puzzle.description = '''
#An abbreviated map of Sumner County, TN.
#This map is unique, to the best of my knowledge.

# My Northern Il and Indiana map
northernIl_map = search.UndirectedGraph(dict(
    Rockford=dict(CrystalLake=42),
    CrystalLake=dict(Chicago=53, Aurora=35),
    Chicago=dict(Aurora=41, Hammond=27, Detriot=284),
    Detriot=dict(Indianapolis=287),
    Aurora=dict(Chicago=41, Kankakee=81),
    Hammond=dict(SouthBend=71),
    Kankakee=dict(Champaign=160),
    Champaign=dict(Lafayette=91),
    Lafayette=dict(Indianapolis=62),
    Indianapolis=dict(SouthBend=150),
))
northernIl_puzzle2 = search.GraphProblem('Rockford', 'Indianapolis', northernIl_map)
northernIl_map.locations = dict(
    Rockford = (42, 89),
    CrystalLake= (42, 88),
    Chicago= (41, 87),
    Detriot= (42, 83),
    Aurora= (41, 88),
    Hammond= (41, 87),
    Champaign= (40, 88),
    Lafayette = (40, 86),
Ejemplo n.º 25
0
# This map is unique, to the best of my knowledge.
# '''

#=========================================================================
#=========================================================================
norfolk_map = search.UndirectedGraph(
    dict(
        Norfolk=dict(Suffolk=50, Chesapeake=15, VirginiaBeach=35),
        Suffolk=dict(Norfolk=50,
                     Chesapeake=35,
                     Hampton=60,
                     Moyock=150,
                     Sunbury=120),
        Chesapeake=dict(Suffolk=35, Norfolk=15, VirginiaBeach=40, Moyock=120),
        VirginiaBeach=dict(Norfolk=35, Chesapeake=40),
        Hampton=dict(Norfolk=30, Suffolk=60, NewportNews=15),
        NewportNews=dict(Hampton=15,
                         Jamestown=35,
                         Williamsburg=30,
                         Yorktown=15),
        Jamestown=dict(NewportNews=35, Williamsburg=15),
        Williamsburg=dict(Jamestown=15, NewportNews=30, Yorktown=20),
        Yorktown=dict(Williamsburg=20, Newportnews=15),
        Sunbury=dict(Suffolk=120, Moyock=45),
        Moyock=dict(Suffolk=150, Chesapeak=120),
    ))

norfolk_puzzle = search.GraphProblem('Jamestown', 'Yorktown', norfolk_map)

norfolk_puzzle.label = 'Norfolk'
norfolk_puzzle.description = 'This is a map of the Norfolk, VA area.' \
Ejemplo n.º 26
0
import search
from math import(cos, pi)

# A sample map problem
slo_map = search.UndirectedGraph(dict(
   #Portland=dict(Mitchellville=7, Fairfield=17, Cottontown=18),
   #Cottontown=dict(Portland=18),
   #Fairfield=dict(Mitchellville=21, Portland=17),
   #Mitchellville=dict(Portland=7, Fairfield=21),
    SanLuis=dict(AvilaBeach=11, MorroBay=15, Atascadero=18),
    AvilaBeach=dict(SanLuis=11, MorroBay=28, SantaMaria=30),
    Atascadero=dict(Templeton=7, SanLuis=18, MorroBay=23, Cayucos=27),
    MorroBay=dict(Cayucos=8, SanLuis=15, AvilaBeach=28, Atascadero=23),
    SantaMaria=dict(AvilaBeach=30, Nipomo=11),
    Nipomo=dict(SantaMaria=11, SanLuis=25),
    Cayucos=dict(MorroBay=8, Atascadero=27, Templeton=31),
    Templeton=dict(Atascadero=7, Cayucos=31),


))

slo_puzzle = search.GraphProblem('Cayucos', 'SantaMaria', slo_map)

slo_puzzle.label = 'SLO'
slo_puzzle.description = '''
An abbreviated map of San Luis Obispo, CA.
This map is unique, to the best of my knowledge.
'''

romania_map = search.UndirectedGraph(dict(
    A=dict(Z=75,S=140,T=118),
Ejemplo n.º 27
0
import search
from math import(cos, pi)


dallas_map = search.UndirectedGraph (dict(

    Dallas=dict(Rockwall=25, Fortworth = 35),
    Rockwall=dict (Dallas = 25, Richardson = 24),
    Richardson=dict (Rockwall = 24, Coppell = 21),
    Fortworth=dict (Dallas = 35, Azle = 17, Garland = 33, Frisco = 45),
    Azle=dict (Fortworth = 17, Reno = 10, Frisco = 33, Fubu = 41),
    Reno=dict (Azle = 10, Coppell = 47, Garland =19, Lakewood= 45),
    Coppell=dict (Richardson = 21, Reno = 47, Lakewood = 8),
    Frisco=dict (Azle = 33, Fortworth =45),
    Lakewood= dict( Reno = 45, Coppell=8),
    Garland= dict (Fortworth = 33, Reno = 19),
    Fubu= dict(Azle = 41, Nike = 51, Pfflyers = 38, Atoka =128),
    Pfflyers= dict(Fubu = 38),
    Nike= dict(Fubu = 51),
    Atoka= dict(Fubu = 128, Ada=18),
    Ada= dict(Atoka = 18),


))

Dallas_puzzle = search.GraphProblem('Frisco', 'Richardson', dallas_map)

Dallas_puzzle.label = 'Dallas'
Dallas_puzzle.description = '''
An abbreviated map of Dallas, Tx.
This map is unique, to the best of my knowledge.
Ejemplo n.º 28
0
import search
from math import (cos, pi)

# A sample map problem
il_map = search.UndirectedGraph(
    dict(
        # Portland=dict(Mitchellville=7, Fairfield=17, Cottontown=18),
        # Cottontown=dict(Portland=18),
        # Fairfield=dict(Mitchellville=21, Portland=17),
        # Mitchellville=dict(Portland=7, Fairfield=21),
        Chicago=dict(Springfield=204, Peoria=169),
        Jacksonville=dict(Springfield=38, Peoria=97, Quincy=79),
        Springfield=dict(Chicago=204, Jacksonville=38, Peoria=68),
        Peoria=dict(Chicago=169, Jacksonville=97, Springfield=68, Quincy=146),
        Quincy=dict(Jacksonville=79, Peoria=146),
    ))

illinois_puzzle = search.GraphProblem('Chicago', 'Jacksonville', il_map)

illinois_puzzle.label = 'Illinois Map'
illinois_puzzle.description = '''
An abbreviated map of Illinois.
This map is unique, to the best of my knowledge.
'''


# A trivial Problem definition
class LightSwitch(search.Problem):
    def actions(self, state):
        return ['up', 'down']
Ejemplo n.º 29
0
import search
import numpy as np
from math import (cos, pi)

# A sample map problem
from utils import is_in

madison_map = search.UndirectedGraph(
    dict(
        # Portland=dict(Mitchellville=7, Fairfield=17, Cottontown=18),
        # Cottontown=dict(Portland=18),
        #Fairfield=dict(Mitchellville=21, Portland=17),
        #Mitchellville=dict(Portland=7, Fairfield=21),
        Jackson=dict(Humboldt=27),
        Humboldt=dict(Jackson=27, ThreeWay=8),
        ThreeWay=dict(Humboldt=8, Medon=34),
        Medon=dict(Jackson=17, Humboldt=43, ThreeWay=34),
        SpringCreek=dict(ThreeWay=18, Medon=34, Humboldt=29)))

# Coordinates for map. May not be entirely accurate but as close as possible
madison_map.locations = (dict(Jackson=(485, 512),
                              Humboldt=(482, 482),
                              ThreeWay=(474, 474),
                              Medon=(495, 501),
                              SpringCreek=(474, 464)))

madison_puzzle = search.GraphProblem('Jackson', 'ThreeWay', madison_map)
madison_puzzle1 = search.GraphProblem('SpringCreek', 'Jackson', madison_map)

madison_puzzle.label = 'Madison'
madison_puzzle.description = '''
Ejemplo n.º 30
0
import search
from math import (cos, pi)

sumner_map = search.UndirectedGraph(
    dict(
        Dublin=dict(Mullingar=79),
        Mullingar=dict(Naas=70, Dublin=79),
        Naas=dict(Mullingar=70, Carlow=58),
        Kells=dict(Dublin=65, Mullingar=42),
        Arklow=dict(Naas=97, Dublin=71),
        Carlow=dict(Naas=58),
    ))

sumner_map.locations = dict(Dublin=(69, 42),
                            Mullingar=(0, 22),
                            Naas=(41, 53),
                            Kells=(30, 0),
                            Arklow=(75, 101),
                            Carlow=(62, 25))

sumner_puzzle = search.GraphProblem('Mullingar', 'Carlow', sumner_map)
sumner_puzzle.label = 'Sumner Map'
sumner_puzzle.description = '''
An abbreviated map of Eastern Ireland.
This map is unique, to the best of my knowledge.
'''
sumner_puzzle2 = search.GraphProblem('Mullingar', 'Arklow', sumner_map)
sumner_puzzle2.label = 'Sumner Map 2'
sumner_puzzle2.description = '''
An abbreviated map of Eastern Ireland.
This map is unique, to the best of my knowledge.