Skip to content

Commit

Permalink
working on intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
vantagesol committed May 29, 2018
1 parent 67393de commit ea18508
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Binary file modified Python-Code/__pycache__/car.cpython-36.pyc
Binary file not shown.
Binary file modified Python-Code/__pycache__/intersection.cpython-36.pyc
Binary file not shown.
Binary file modified Python-Code/__pycache__/map.cpython-36.pyc
Binary file not shown.
28 changes: 17 additions & 11 deletions Python-Code/intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,31 @@ def __init__(self, name, x, y, map=None):
self.y = y #int - Y coordinate on the map
self.queue = [] #Queue - Queue of Cars at this location
self.q_size = 0 #int - Current number of elements in the queue
self.edge_list = [] #List - List of connected edges
self.out_edges = []
self.in_edges = [] #List - List of connected edges
self.neighbor_nodes = [] #List - List of neighboring nodes
self.cap = 0 #int - Allowed size of queue
self.time_steps = 2 #int - Number of time steps to pass through node
self.visted = False #bool - Used for dijkstra's shortest path
self.value = sys.maxsize #int - Used for dijkstra's shortest path
self.trail = [] #List - The list of nodes in the shortest path
self.trail = []
self.priority_Q = PriorityQueue() #List - The list of nodes in the shortest path

def __cmp__(self, other):
return self.value < other.value

def add_edge(self, edge):
self.edge_list.append(edge) #Add the edge to list of edges

def add_edge(self, edge, out=True):
if out == True:
self.out_edges.append(edge)
else:
self.in_edges.append(edge)
self.cap += edge.num_lanes

#Add the edge to list of edges
#Determine which node your neighbor is
neighbor_node = edge.u if self.id \
!= edge.u.id else edge.v

self.neighbor_nodes.append(neighbor_node) #Add the node to your neighbor list
self.neighbor_nodes.append(neighbor_node)#Add the node to your neighbor list

def add(self, car):
if(len(self.queue) + 1 <= self.cap):
Expand Down Expand Up @@ -71,7 +77,7 @@ def tick(self, modified):
"""

def shortest_path(self, destination):
self.priority_Q = PriorityQueue()
#self.priority_Q = PriorityQueue()
self.value = 0
self.priority_Q.put_nowait(self)
current = self
Expand All @@ -91,11 +97,11 @@ def shortest_path(self, destination):


def relax_neighbors(self):
for edge in self.edge_list:
for edge in self.out_edges:
neighbor_node = edge.v
if not neighbor_node.visted:
neighbor_node.value = edge.time_steps + neighbor_node.time_steps
self.priority_Q.put_nowait(self)
self.priority_Q.put_nowait((self.value, neighbor_node))
else:
pass

Expand Down Expand Up @@ -134,7 +140,7 @@ def visit_node(self, node):
node.visted = True
#Edit each connected node to this current node
for edge in node.edge_list:
for edge in node.out_edges:
#Determine what node you are i.e. nodeA or nodeB
my_node = edge.nodeA if node.id == edge.nodeA.id else edge.nodeB
Expand Down
2 changes: 1 addition & 1 deletion Python-Code/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Map:
"""
def __init__(self, center_lat=47.608013, center_long=-122.335167, \
dist=500, num_cars=10):
dist=150, num_cars=10):
"""
"""
Expand Down

0 comments on commit ea18508

Please sign in to comment.