Пример #1
0
        public void EvaluateWithinBranchPerformsProperInterAndExtrapolation()
        {
            //network 2 branches
            var network = RouteHelperTest.GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0),
                                                          new Point(100, 100));
            var networkCoverage = new NetworkCoverage {Network = network};

            IBranch branch = network.Branches[0];

            networkCoverage[new NetworkLocation(branch, 1)] = 1.0;
            networkCoverage[new NetworkLocation(branch, 2)] = 2.0;
            networkCoverage[new NetworkLocation(branch, 3)] = 3.0;
            
            var knownLocations = networkCoverage.GetLocationsForBranch(branch);

            networkCoverage.Locations.ExtrapolationType = ExtrapolationType.Constant;
            networkCoverage.Locations.InterpolationType = InterpolationType.Linear;

            var offsetValues = knownLocations.Select(l => l.Chainage).Concat(new[] {0, 1.4, 2.4, 3.1}).OrderBy(o => o);
            var results = networkCoverage.EvaluateWithinBranch(branch, offsetValues, knownLocations);

            results[0].Should("1").Be.EqualTo(1.0);
            results[2].Should("2").Be.EqualTo(1.4);
            results[4].Should("3").Be.EqualTo(2.4);
            results[6].Should("4").Be.EqualTo(3.0);

            /*
             * Linear extrapolation is not support until the 'normal' evaluate does this also to prevent differences
                        networkCoverage.Locations.ExtrapolationType = ExtrapolationType.Linear;
                        networkCoverage.Locations.InterpolationType = InterpolationType.Constant;
                        results = networkCoverage.EvaluateWithinBranch(locations);
                        results[0].Should("5").Be.EqualTo(0.0);
                        results[2].Should("6").Be.EqualTo(1.0);
                        results[4].Should("7").Be.EqualTo(2.0);
                        results[6].Should("8").Be.EqualTo(3.1);
            */
        }
Пример #2
0
        public void EvaluateWithinBranchThrowsExceptionForNonConstantExtraPolation()
        {
            var network = RouteHelperTest.GetSnakeNetwork(false, 1);
            var networkCoverage = new NetworkCoverage { Network = network };

            IBranch branch = network.Branches[0];

            networkCoverage[new NetworkLocation(branch, 10)] = 1.0;
            networkCoverage[new NetworkLocation(branch, 20)] = 2.0;
            networkCoverage[new NetworkLocation(branch, 30)] = 3.0;
            networkCoverage.Locations.ExtrapolationType = ExtrapolationType.Linear;

            var locations = networkCoverage.GetLocationsForBranch(branch);
            networkCoverage.EvaluateWithinBranch( branch, new [] {5.0}.OrderBy(o => o), locations);

        }
Пример #3
0
        public void EvaluateAndEvaluateWithinBranchesAreConsistent()
        {
            // create network with two branches connected by 
            // order number:
            //
            //      nr=1         nr=1          nr=-1
            // X-----A------X-----B------X-----C------X
            //
            var network = new Network();

            var node1 = new Node("node1");
            var node2 = new Node("node2");
            var node3 = new Node("node3");
            var node4 = new Node("node4");
            network.Nodes.Add(node1);
            network.Nodes.Add(node2);
            network.Nodes.Add(node3);
            network.Nodes.Add(node4);

            var branchA = new Branch("branchA", node1, node2, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)"), OrderNumber = 1 };
            var branchB = new Branch("branchB", node2, node3, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (100 0, 200 0)"), OrderNumber = 1 };
            var branchC = new Branch("branchC", node3, node4, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (200 0, 300 0)"), OrderNumber = -1 };
            network.Branches.Add(branchA);
            network.Branches.Add(branchB);
            network.Branches.Add(branchC);

            // set up coverage with some values
            INetworkCoverage networkCoverage = new NetworkCoverage { Network = network };
            networkCoverage.Locations.InterpolationType = InterpolationType.Linear;
            networkCoverage[new NetworkLocation(branchA, 0.50 * branchA.Length)] = 103.8;
            networkCoverage[new NetworkLocation(branchB, 0.32 * branchB.Length)] = 7.6;
            networkCoverage[new NetworkLocation(branchB, 0.66 * branchB.Length)] = 12.0;
            networkCoverage[new NetworkLocation(branchB, 0.98 * branchB.Length)] = 30.0;
            networkCoverage[new NetworkLocation(branchC, 0.50 * branchC.Length)] = -20.0;

            var knownLocations = networkCoverage.GetLocationsForBranch(branchB);
            var allLocations = knownLocations.Concat(
                new[]
                    {
                        new NetworkLocation(branchB, 0.0),
                        new NetworkLocation(branchB, branchB.Length/2.015),
                        new NetworkLocation(branchB, branchB.Length)
                    }).ToList();

            var sortedLocations = allLocations.OrderBy(o => o).ToList();
            var sortedOffsets = sortedLocations.Select(l => l.Chainage).OrderBy(o => o);
            var result = networkCoverage.EvaluateWithinBranch(branchB, sortedOffsets, knownLocations);
            int index = 0;
            foreach (var location in sortedLocations)
            {
                Assert.AreEqual(result[index++], networkCoverage.Evaluate(location),
                                String.Format("Where offset equals {0}", location.Chainage));
            }

        }