-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment4_.py
65 lines (47 loc) · 1.6 KB
/
assignment4_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 3 20:54:42 2017
@author: l3th
"""
from IPython.display import HTML
import folium
import json
import networkx as nx
from folium import plugins
import networkx.classes.function as ncf
from osm import read_way_network, gc_dist
bryggen = read_way_network("bryggen.osm")
def find_nearest_node(graph, lat, lon):
abs_dist = {}
for node in graph.__iter__():
abs_dist[node] = gc_dist(lat, lon, graph.nodes[node]['lat'], graph.nodes[node]['lon'])
return min(abs_dist, key=abs_dist.get)
start_loc = (55.663811, 12.596087)
goal_loc = (55.665372, 12.578170)
start_node = find_nearest_node(bryggen, 55.663811, 12.596087)
goal_node = find_nearest_node(bryggen, 55.665372, 12.578170)
print(start_node, goal_node)
path = (start_node,)
solutions = []
discovered = set()
def depthFirstSearch(boardList, goalState):
frontier = set()
frontierOrdered = [(boardString, "")]
frontier.add(frontierOrdered[0][0])
explored = set()
while not len(frontier) == 0:
# print(frontier, frontierOrdered)
stateFull = frontierOrdered.pop()
state = stateFull[0]
path = stateFull[1]
explored.add(state)
if state == goalState:
return 'Succes'
for i, d in findNeighbors(state, 'dfs'):
curState = swapNeighbors(state, int(i))
if pl<len(path+d): pl = len(path+d)
if curState not in frontier and curState not in explored:
frontierOrdered.append((curState, path+d))
frontier.add(curState)
return 'Failure'