Exemplo n.º 1
0
        private async Task <AdjacencyGraph <NavigationPoint, WeightedEdge <NavigationPoint> > > GenerateCosts(
            AdjacencyGraph <NavigationPoint, TransportEdge <NavigationPoint> > segmentedGraph, OptimizationParam optimizer)
        {
            var weightedGraph  = new AdjacencyGraph <NavigationPoint, WeightedEdge <NavigationPoint> >();
            var weightingTasks = new List <Task <WeightedEdge <NavigationPoint> > >(
                segmentedGraph.Edges.Select((async edge =>
            {
                var segment = new RoutingSegment(edge.Source,
                                                 edge.Target,
                                                 edge.NavigationMode);
                var costedRoute = await _navigationCostGeneratorService.GetCostForSegment(segment, optimizer);
                _internalCache.Add(segment, costedRoute);
                return(new WeightedEdge <NavigationPoint>(edge.Source, edge.Target, edge.NavigationMode, costedRoute.cost));
            })));

            weightedGraph.AddVerticesAndEdgeRange(await Task.WhenAll(weightingTasks));
            return(weightedGraph);
        }
Exemplo n.º 2
0
        public Task <RoutingSegmentResult> GetCostForSegment(RoutingSegment segment, OptimizationParam optimizer)
        {
            var costFunction = _costFunctionFactory.GetCostFunctionByType(segment.SegmentNavigationMode);

            return(costFunction.GetCost(segment.SegmentStart, segment.SegmentEnd, optimizer));
        }
Exemplo n.º 3
0
 public void Add(RoutingSegment segment, RoutingSegmentResult result)
 {
     _internalDictionary[GetKey(segment)] = result;
 }
Exemplo n.º 4
0
 private string GetKey(RoutingSegment segment)
 {
     return($"{segment.SegmentStart.Latitude};{segment.SegmentStart.Longitude};{segment.SegmentEnd.Latitude};{segment.SegmentEnd.Longitude}");
 }
Exemplo n.º 5
0
 public RoutingSegmentResult GetByKey(RoutingSegment segment)
 {
     return(_internalDictionary[GetKey(segment)]);
 }