Refine virtual district

This commit is contained in:
WQY\qiong
2023-04-30 11:30:47 +08:00
parent 93ec527fff
commit 493b46fd4e

View File

@@ -1,6 +1,6 @@
from .database import *
from .s0_base import get_node_links
from .s32_region_util import calculate_convex_hull
from .s32_region_util import calculate_boundary, calculate_convex_hull, inflate_boundary
def calculate_virtual_district(name: str, centers: list[str]) -> dict[str, Any]:
@@ -41,6 +41,7 @@ def calculate_virtual_district(name: str, centers: list[str]) -> dict[str, Any]:
for center in centers:
for node, index in node_index.items():
if node == center:
node_distance[node] = { 'center': center, 'distance' : 0.0 }
continue
# TODO: check none
distance = float(read(name, f"select max(agg_cost) as distance from pgr_dijkstraCost('select id, source, target, cost from temp_vd_topology', {index}, {node_index[center]}, false)")['distance'])
@@ -61,7 +62,9 @@ def calculate_virtual_district(name: str, centers: list[str]) -> dict[str, Any]:
vds: list[dict[str, Any]] = []
for center, value in center_node.items():
xys = calculate_convex_hull(name, value)
vds.append({ 'center': center, 'nodes': value, 'boundary': xys })
p = calculate_boundary(name, value)
b = inflate_boundary(name, p)
c = calculate_convex_hull(name, value)
vds.append({ 'center': center, 'nodes': value, 'path': p, 'boundary': b, 'convex_hull': c})
return { 'virtual_districts': vds, 'isolated_nodes': isolated_nodes }