mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-06 23:58:51 -06:00
Make distance metric configurable; fix building period bug
This commit is contained in:
@@ -40,7 +40,6 @@ function build_graph(instance::Instance)::Graph
|
||||
end
|
||||
|
||||
# Build arcs from collection centers to plants, and from one plant to another
|
||||
metric = _KnnDrivingDistance()
|
||||
for source in [collection_shipping_nodes; plant_shipping_nodes]
|
||||
for dest in process_nodes_by_input_product[source.product]
|
||||
distance = _calculate_distance(
|
||||
@@ -48,7 +47,7 @@ function build_graph(instance::Instance)::Graph
|
||||
source.location.longitude,
|
||||
dest.location.latitude,
|
||||
dest.location.longitude,
|
||||
metric,
|
||||
instance.distance_metric,
|
||||
)
|
||||
values = Dict("distance" => distance)
|
||||
arc = Arc(source, dest, values)
|
||||
|
||||
@@ -6,19 +6,12 @@ using Geodesy
|
||||
using NearestNeighbors
|
||||
using DataFrames
|
||||
|
||||
Base.@kwdef mutable struct _KnnDrivingDistance
|
||||
tree = nothing
|
||||
ratios = nothing
|
||||
end
|
||||
|
||||
mutable struct _EuclideanDistance end
|
||||
|
||||
function _calculate_distance(
|
||||
source_lat,
|
||||
source_lon,
|
||||
dest_lat,
|
||||
dest_lon,
|
||||
::_EuclideanDistance,
|
||||
::EuclideanDistance,
|
||||
)::Float64
|
||||
x = LLA(source_lat, source_lon, 0.0)
|
||||
y = LLA(dest_lat, dest_lon, 0.0)
|
||||
@@ -30,7 +23,7 @@ function _calculate_distance(
|
||||
source_lon,
|
||||
dest_lat,
|
||||
dest_lon,
|
||||
metric::_KnnDrivingDistance,
|
||||
metric::KnnDrivingDistance,
|
||||
)::Float64
|
||||
if metric.tree === nothing
|
||||
basedir = joinpath(dirname(@__FILE__), "..", "..", "data")
|
||||
@@ -54,13 +47,8 @@ function _calculate_distance(
|
||||
end
|
||||
|
||||
# Compute Euclidean distance
|
||||
dist_euclidean = _calculate_distance(
|
||||
source_lat,
|
||||
source_lon,
|
||||
dest_lat,
|
||||
dest_lon,
|
||||
_EuclideanDistance(),
|
||||
)
|
||||
dist_euclidean =
|
||||
_calculate_distance(source_lat, source_lon, dest_lat, dest_lon, EuclideanDistance())
|
||||
|
||||
# Predict ratio
|
||||
idxs, _ = knn(metric.tree, [source_lat, source_lon, dest_lat, dest_lon], 5)
|
||||
|
||||
Reference in New Issue
Block a user