Esempio n. 1
0
        public void BranchSplitWillCompensateRouteLocations()
        {
            // Create Network
            var nodeA = new Node("nodeA"){ Geometry = new Point(0,0) };
            var nodeB = new Node("nodeB"){ Geometry = new Point(100,0) };
            var branch = new Branch(nodeA, nodeB)
                             {
                                 Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(100, 0) }),
                                 Name = "branch"
                             };
            var network = new Network();
            network.Branches.Add(branch);

            // Create route network coverage
            var route = new Route { Network = network };
            route.Locations.AddValues(new[] { new NetworkLocation(branch, 10.0), new NetworkLocation(branch, 90.0) });

            NetworkHelper.SplitBranchAtNode(branch, 50.0);

            Assert.AreEqual(2, route.Locations.Values.Count);
            Assert.AreEqual(network.Branches[0], route.Locations.Values[0].Branch);
            Assert.AreEqual(network.Branches[1], route.Locations.Values[1].Branch);
            Assert.AreEqual(10.0, route.Locations.Values[0].Chainage, BranchFeature.Epsilon);
            Assert.AreEqual(40.0, route.Locations.Values[1].Chainage, BranchFeature.Epsilon);
        }
Esempio n. 2
0
 /// <summary>
 /// Returns all locations in the route. Route cannot contain doubles for now because side view should
 /// draw structures double etc. Would complicate more then the use-case would justify
 /// </summary>
 /// <param name="source"></param>
 /// <param name="route"></param>
 /// <returns></returns>
 public static IList<INetworkLocation> GetLocationsInRoute(INetworkCoverage source, Route route)
 {
     IList<INetworkLocation> locations = new List<INetworkLocation>();
     
     foreach (INetworkSegment segment in route.Segments.Values)
     {
         var locationsForSegment = GetLocationsForSegment(segment, source, true);
         foreach (var location in locationsForSegment)
         {
             //add location if we didn't just add it..this can happens when segments go like 1-->3 3-->4 4-->5 
             //don't want the start and endnodes causing doubles so should be like 1-->3-->4-->5
             if (!location.Equals(locations.LastOrDefault()))
             {
                 locations.Add(location);    
             }
             
         }
     }
     return locations;
 }
Esempio n. 3
0
        public void LocationAreUniqueIsCorrectForTouchingLocations()
        {
            var network = CreateThreeNodesNetwork();

            NetworkCoverage source = new NetworkCoverage { Network = network };
            source[new NetworkLocation(network.Branches[0], 10.0)] = 10.0;
            source[new NetworkLocation(network.Branches[0], 50.0)] = 30.0;
            source[new NetworkLocation(network.Branches[1], 50.0)] = 20.0;
            source[new NetworkLocation(network.Branches[1], 150.0)] = 10.0;

            var returningRoute = new Route
            {
                Network = network,
            };
            //route going back to branch 0
            returningRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            returningRoute.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));
            returningRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 10.0));

            Assert.IsFalse((RouteHelper.LocationsAreUniqueOnRoute(source, returningRoute)));

            var singleRoute = new Route
            {
                Network = network,
                SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations
            };
            //route going one way
            singleRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            singleRoute.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));

            Assert.IsTrue((RouteHelper.LocationsAreUniqueOnRoute(source, singleRoute)));
        }
Esempio n. 4
0
        public void LocationAreUniqueIsCorrect()
        {
            //take a input coverage e.g depth Ci
            //take a route coverage Cr
            //result is Function dependend of X with components equal to the components of Ci
            //where x is distance along Cr
            var network = CreateThreeNodesNetwork();

            NetworkCoverage source = new NetworkCoverage { Network = network };
            source[new NetworkLocation(network.Branches[0], 10.0)] = 10.0;
            source[new NetworkLocation(network.Branches[0], 50.0)] = 30.0;
            source[new NetworkLocation(network.Branches[1], 50.0)] = 20.0;
            source[new NetworkLocation(network.Branches[1], 150.0)] = 10.0;

            var returningRoute = new Route
            {
                Network = network,
            };
            //route going back to branch 0
            returningRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            returningRoute.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));
            returningRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 10.0));

            Assert.IsFalse((RouteHelper.LocationsAreUniqueOnRoute(source, returningRoute)));

            var singleRoute = new Route
            {
                Network = network,
            };
            //route going one way
            singleRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            singleRoute.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));

            Assert.IsTrue((RouteHelper.LocationsAreUniqueOnRoute(source, singleRoute)));
        }
Esempio n. 5
0
        public void GetRouteChainageCustomLength()
        {
            var network = CreateThreeNodesNetwork();

            network.Branches[0].IsLengthCustom = true;
            network.Branches[0].Length *= 2;
            network.Branches[1].IsLengthCustom = true;
            network.Branches[1].Length *= 3;

            var networkLocation = new NetworkLocation(network.Branches[1], 30);
            NetworkHelper.AddBranchFeatureToBranch(networkLocation, network.Branches[1], 30);

            var route = new Route
            {
                Network = network,
            };
            //route going back to branch 0
            route.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            route.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));
            route.Locations.Values.Add(new NetworkLocation(network.Branches[1], 110.0));
            Assert.AreEqual(225.0, RouteHelper.GetRouteChainage(route, networkLocation));
        }
Esempio n. 6
0
        public void GetRouteLengthCustomLength()
        {
            var network = CreateThreeNodesNetwork();

            network.Branches[0].IsLengthCustom = true;
            network.Branches[0].Length *= 2;

            var route = new Route
            {
                Network = network,
            };
            //route going back to branch 0
            route.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            route.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));
            route.Locations.Values.Add(new NetworkLocation(network.Branches[0], 10.0));
            Assert.AreEqual(505.0, RouteHelper.GetRouteLength(route));
        }
Esempio n. 7
0
 public static bool LocationsAreUniqueOnRoute(INetworkCoverage source, Route route)
 {
     //find all locations and checks for doubles.
     var locationsSet = new HashSet<INetworkLocation>();
     foreach (var segment in route.Segments.Values)
     {
         IEnumerable<INetworkLocation> locations = GetLocationsForSegment(segment, source, false);
         
         if (locationsSet.Overlaps(locations))
             return false;
         foreach (var location in locations)
         {
             locationsSet.Add(location);
         }
     }
     return true;
 }
Esempio n. 8
0
        public void RouteDoesNotContainLoopsWorks()
        {
            var network = CreateThreeNodesNetwork();

            var returningRoute = new Route
            {
                Network = network,
            };
            //route going back to branch 0
            returningRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            returningRoute.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));
            returningRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 10.0));

            Assert.IsTrue(RouteHelper.RouteContainLoops(returningRoute));
            
            var leapingRoute = new Route
            {
                Network = network,
            };
            //route going back to branch 0
            leapingRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 10.0));
            leapingRoute.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));
            leapingRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));

            Assert.IsTrue(RouteHelper.RouteContainLoops(leapingRoute));

            var singleRoute = new Route
            {
                Network = network,
            };
            //route going one way
            singleRoute.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            singleRoute.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));

            Assert.IsFalse(RouteHelper.RouteContainLoops(singleRoute));
        }
Esempio n. 9
0
 public static bool RouteContainLoops(Route networkRoute)
 {
     //see if there is any location which lies *within* (so excluding start & end) a segment
     return networkRoute.Locations.Values.Any(location => 
         networkRoute.Segments.Values.Any(segment => IsWithinSegment(segment,location)));
 }
Esempio n. 10
0
 public static double GetRouteChainage(Route route, IBranchFeature branchFeature)
 {
     var chainage = GetRouteChainageInternal(route, branchFeature);
     if (chainage >= 0)
     {
         if (chainage > GetRouteLength(route))
         {
             chainage = -1;
         }
     }
     else
     {
         chainage = -1;
     }
     
     return chainage;
 }
Esempio n. 11
0
 /// <summary>
 /// returns the chainage of the branchfeature in the route. -1 if branchfeature is not in the route.
 /// </summary>
 /// <param name="route"></param>
 /// <param name="branchFeature"></param>
 /// <returns></returns>
 private static double GetRouteChainageInternal(Route route, IBranchFeature branchFeature)
 {
     double chainage = 0;
     foreach (var segment in route.Segments.Values)
     {
         if (branchFeature.Branch != segment.Branch)
         {
             chainage += segment.Length;
         }
         else
         {
             if (segment.DirectionIsPositive)
             {
                 if (branchFeature.Chainage > segment.Chainage + segment.Length + ErrorMargin)
                 {
                     chainage += segment.Length;
                 }
                 else
                 {
                     chainage += (branchFeature.Chainage - segment.Chainage);
                     return chainage;
                 }
             }
             else
             {
                 if (branchFeature.Chainage > segment.Chainage)// + segment.Length)
                 {
                     chainage += segment.Length;
                 }
                 else
                 {
                     chainage += (segment.Chainage - branchFeature.Chainage);
                     return chainage;
                 }
             }
         }
     }
     return -1;
 }
Esempio n. 12
0
 public static bool IsBranchFeatureInRoute(Route route, IBranchFeature branchFeature)
 {
     return GetRouteChainage(route, branchFeature) >= 0;
 }
Esempio n. 13
0
        /// <summary>
        /// Creates a route with the given locations. Now route is stored in argument.
        /// This makes it impossible to have doubles. :( But makes drawing etc easy.
        /// </summary>
        /// <param name="locations"></param>
        /// <returns></returns>
        public static Route CreateRoute(params INetworkLocation[] locations)
        {
            var network = locations[0].Branch.Network;

            ThrowIfInputInvalid(locations, network);

            var route = new Route
                            {
                                Network = network,
                            };
            route.Components[0].Unit = new Unit("meters", "m");
            route.SetLocations(locations);
            return route;
        }
Esempio n. 14
0
 public void GetRouteSegments()
 {
     INetwork network = CreateThreeNodesNetwork();
     var route = new Route
                                 {
                                     Network = network,
                                 };
     route.Locations.Values.Add(new NetworkLocation(network.Branches[0], 0));
     route.Locations.Values.Add(new NetworkLocation(network.Branches[0], 100.0));
     Assert.AreEqual(1, route.Segments.Values.Count);
     Assert.AreEqual(100, route.Segments.Values[0].EndChainage);
     Assert.AreEqual(0, route.Segments.Values[0].Chainage);
 }
Esempio n. 15
0
        public static bool IsDisconnected(Route networkRoute)
        {
            for(int i = 0; i < networkRoute.Locations.Values.Count-1; i++)
            {
                var segments = NetworkHelper.GetShortestPathBetweenBranchFeaturesAsNetworkSegments(networkRoute.Network,
                                                                                    networkRoute.Locations.Values[i],
                                                                                    networkRoute.Locations.Values[i + 1]);

                if (segments.Count == 0)
                {
                    return true;
                }
            }

            return false;
        }
Esempio n. 16
0
        public void GetRouteForBranchCustomLength()
        {
            var network = GetSnakeNetwork(true, 1);
            var route = new Route
            {
                Network = network,
            };
            Assert.AreEqual(100.0, network.Branches[0].Length, 1.0e-6);
            network.Branches[0].IsLengthCustom = true;

            route.Locations.Values.Add(new NetworkLocation(network.Branches[0], 10));
            route.Locations.Values.Add(new NetworkLocation(network.Branches[0], 80.0));
            Assert.AreEqual(1, route.Segments.Values.Count);
            Assert.AreEqual(10, route.Segments.Values[0].Chainage, 1.0e-6);
            Assert.AreEqual(80, route.Segments.Values[0].EndChainage, 1.0e-6);

            network.Branches[0].Length = network.Branches[0].Length * 2;
            Assert.AreEqual(200.0, network.Branches[0].Length, 1.0e-6);

            Assert.AreEqual(1, route.Segments.Values.Count);
            Assert.AreEqual(20, route.Segments.Values[0].Chainage, 1.0e-6);
            Assert.AreEqual(160, route.Segments.Values[0].EndChainage, 1.0e-6);

        }
Esempio n. 17
0
 /// <summary>
 /// returns the segment where networkLocation is located.
 /// networkLocation does not have to be a networkLocation in route.Locations.
 /// </summary>
 /// <param name="route"></param>
 /// <param name="networkLocation"></param>
 /// <returns></returns>
 public static INetworkSegment GetSegmentForNetworkLocation(Route route, INetworkLocation networkLocation)
 {
     var segments = route.Segments.Values.ToArray();
     foreach (var segment in segments)
     {
         if (segment.Branch != networkLocation.Branch)
         {
             continue;
         }
         if ((networkLocation.Chainage > segment.Chainage) && (networkLocation.Chainage < segment.EndChainage))
         {
             return segment;
         }
         // segment can be reversed in coverage
         if ((networkLocation.Chainage < segment.Chainage) && (networkLocation.Chainage > segment.EndChainage))
         {
             return segment;
         }
     }
     return null;
 }
Esempio n. 18
0
        public void RouteIsDisconnectedWorks()
        {
            var network = CreateThreeNodesNetwork();
            
            var route = new Route
            {
                Network = network,
            };
            
            route.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            route.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));

            Assert.IsFalse(RouteHelper.IsDisconnected(route));
            
            //disconnect the two branches
            var extraNode = new Node();
            network.Nodes.Add(extraNode);
            network.Branches[0].Target = extraNode;

            Assert.IsTrue(RouteHelper.IsDisconnected(route));
        }
Esempio n. 19
0
 //this code gives the geometry length, not the physical length!!
 public static double GetRouteLength(Route coverage)
 {
     return coverage.Segments.Values.Sum(seg => seg.Length);
 }