calculate connection distances
This commit is contained in:
parent
82a859e958
commit
7b792ace8b
4 changed files with 13 additions and 8 deletions
|
@ -1,8 +1,12 @@
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
class GraphConnection():
|
class GraphConnection():
|
||||||
def __init__(self, graph, from_point, to_point):
|
def __init__(self, graph, from_point, to_point, distance=None):
|
||||||
self.graph = graph
|
self.graph = graph
|
||||||
self.from_point = from_point
|
self.from_point = from_point
|
||||||
self.to_point = to_point
|
self.to_point = to_point
|
||||||
|
self.distance = distance if distance is not None else np.linalg.norm(from_point.xy - to_point.xy)
|
||||||
|
|
||||||
if to_point in from_point.connections:
|
if to_point in from_point.connections:
|
||||||
self.graph.connections.remove(from_point.connections[to_point])
|
self.graph.connections.remove(from_point.connections[to_point])
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Graph():
|
||||||
|
|
||||||
rooms = tuple((room.level.level.name, room.geometry, room.mpl_paths) for room in self.rooms)
|
rooms = tuple((room.level.level.name, room.geometry, room.mpl_paths) for room in self.rooms)
|
||||||
points = tuple((point.room.i, point.x, point.y) for point in self.points)
|
points = tuple((point.room.i, point.x, point.y) for point in self.points)
|
||||||
connections = tuple((conn.from_point.i, conn.to_point.i) for conn in self.connections)
|
connections = tuple((conn.from_point.i, conn.to_point.i, conn.distance) for conn in self.connections)
|
||||||
|
|
||||||
return (rooms, points, connections)
|
return (rooms, points, connections)
|
||||||
|
|
||||||
|
@ -79,8 +79,8 @@ class Graph():
|
||||||
room.level.rooms.append(room)
|
room.level.rooms.append(room)
|
||||||
room.level.points.extend(room.points)
|
room.level.points.extend(room.points)
|
||||||
|
|
||||||
for from_point, to_point in connections:
|
for from_point, to_point, distance in connections:
|
||||||
graph.add_connection(graph.points[from_point], graph.points[to_point])
|
graph.add_connection(graph.points[from_point], graph.points[to_point], distance)
|
||||||
|
|
||||||
return graph
|
return graph
|
||||||
|
|
||||||
|
@ -111,5 +111,5 @@ class Graph():
|
||||||
for from_point, to_point in permutations(points, 2):
|
for from_point, to_point in permutations(points, 2):
|
||||||
self.add_connection(from_point, to_point)
|
self.add_connection(from_point, to_point)
|
||||||
|
|
||||||
def add_connection(self, from_point, to_point):
|
def add_connection(self, from_point, to_point, distance=None):
|
||||||
self.connections.append(GraphConnection(self, from_point, to_point))
|
self.connections.append(GraphConnection(self, from_point, to_point, distance))
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import numpy as np
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
|
||||||
|
@ -7,7 +8,7 @@ class GraphPoint():
|
||||||
self.room = room
|
self.room = room
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.xy = (x, y)
|
self.xy = np.array((x, y))
|
||||||
self.connections = {}
|
self.connections = {}
|
||||||
self.connections_in = {}
|
self.connections_in = {}
|
||||||
self.in_room_transfer_distances = None
|
self.in_room_transfer_distances = None
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Router():
|
||||||
if not global_routing:
|
if not global_routing:
|
||||||
self.transfer_points.add(point)
|
self.transfer_points.add(point)
|
||||||
continue
|
continue
|
||||||
matrix[pk, self.points_pk[to_point]] = 1
|
matrix[pk, self.points_pk[to_point]] = connection.distance
|
||||||
if global_routing:
|
if global_routing:
|
||||||
for to_point, distance in point.in_room_transfer_distances.items():
|
for to_point, distance in point.in_room_transfer_distances.items():
|
||||||
matrix[pk, self.points_pk[to_point]] = distance
|
matrix[pk, self.points_pk[to_point]] = distance
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue