Beispiel #1
0
        public void AnotherInterpolationNoTime()
        {
            var network = CreateNetwork();

            INetworkCoverage networkCoverage = new NetworkCoverage {
                Network = network
            };

            networkCoverage[new NetworkLocation(network.Branches[0], 10.0)] = 0.1;
            networkCoverage[new NetworkLocation(network.Branches[0], 90.0)] = 0.9;

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

            // at the exact locations
            Assert.AreEqual(0.1, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 10.0)));
            Assert.AreEqual(0.9, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 90.0)));

            // at start and end outside the locations
            Assert.AreEqual(0.10, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 5.0)));
            Assert.AreEqual(0.90, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 95.0)), 1e-6);

            // in between the 2 locations
            Assert.AreEqual(0.35, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 35.0)), 1e-6);
        }
Beispiel #2
0
        public void Evaluate()
        {
            // create network
            var network = new Network();

            var node1 = new Node("node1");
            var node2 = new Node("node2");

            network.Nodes.Add(node1);
            network.Nodes.Add(node2);

            var branch1 = new Branch("branch1", node1, node2, 100.0)
            {
                Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)")
            };

            network.Branches.Add(branch1);

            // create network coverage
            INetworkCoverage networkCoverage = new NetworkCoverage {
                Network = network
            };

            networkCoverage.Locations.InterpolationType = ApproximationType.Linear;

            networkCoverage[new NetworkLocation(network.Branches[0], 0.0)]   = 0;
            networkCoverage[new NetworkLocation(network.Branches[0], 100.0)] = 10;

            // evaluate
            var value = networkCoverage.Evaluate <double>(50.0, 0.0);

            value.Should().Be.EqualTo(5); // linear interpolation
        }
        public void ExtractTimeSliceUseLocationsFromTarget()
        {
            var network         = GetNetwork();
            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network
            };

            DateTime[] dateTimes = new DateTime[10];

            for (int i = 0; i < 10; i++)
            {
                dateTimes[i] = new DateTime(2000, 1, 1, 1, /* minute */ i, 0);
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[0], 10.0)] = 10.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[0], 50.0)] = 50.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[0], 90.0)] = 90.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[1], 10.0)] = 110.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[1], 50.0)] = 150.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[1], 90.0)] = 190.0 + i;
            }

            var slice = new NetworkCoverage("slice", false)
            {
                Network = network
            };

            Assert.AreEqual(false, slice.IsTimeDependent);
            slice[new NetworkLocation(network.Branches[0], 20.0)] = 2;
            slice[new NetworkLocation(network.Branches[0], 80.0)] = 8;
            slice[new NetworkLocation(network.Branches[1], 20.0)] = 12;
            slice[new NetworkLocation(network.Branches[1], 80.0)] = 18;

            NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, slice,
                                                   new DateTime(2000, 1, 1, 1, /* minute */ 0, 0), false);

            // expected results at time step 0 are 20 80 120 180; this are interpolated values
            Assert.AreEqual(4, slice.Locations.Values.Count);
            Assert.AreEqual(10 /*20*/, slice.Evaluate(new NetworkLocation(network.Branches[0], 20.0)), 1.0e-6);
            Assert.AreEqual(50 /*80*/, slice.Evaluate(new NetworkLocation(network.Branches[0], 80.0)), 1.0e-6);
            Assert.AreEqual(90 /*120*/, slice.Evaluate(new NetworkLocation(network.Branches[1], 20.0)), 1.0e-6);
            Assert.AreEqual(110 /*180*/, slice.Evaluate(new NetworkLocation(network.Branches[1], 80.0)), 1.0e-6);

            NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, slice,
                                                   new DateTime(2000, 1, 1, 1, /* minute */ 3, 0), false);

            // expected results at time step 3 are 23 83 123 183; this are interpolated values
            Assert.AreEqual(4, slice.Locations.Values.Count);
            Assert.AreEqual(13 /*23*/, slice.Evaluate(new NetworkLocation(network.Branches[0], 20.0)), 1.0e-6);
            Assert.AreEqual(53 /*83*/, slice.Evaluate(new NetworkLocation(network.Branches[0], 80.0)), 1.0e-6);
            Assert.AreEqual(93 /*123*/, slice.Evaluate(new NetworkLocation(network.Branches[1], 20.0)), 1.0e-6);
            Assert.AreEqual(113 /*183*/, slice.Evaluate(new NetworkLocation(network.Branches[1], 80.0)), 1.0e-6);
        }
Beispiel #4
0
        public void DefaultValueTest()
        {
            var network = CreateNetwork();

            INetworkCoverage networkCoverage = new NetworkCoverage {
                Network = network, DefaultValue = 0.33
            };
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);

            // no network location set in networkCoverage expect the default value to return
            Assert.AreEqual(0.33, networkCoverage.Evaluate(nl11));
        }
Beispiel #5
0
        public void DefaultValueTestInvalidTime()
        {
            var network = CreateNetwork();

            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network, DefaultValue = 0.33
            };

            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);

            // no network location set in networkCoverage expect the default value to return
            Assert.AreEqual(0.33, networkCoverage.Evaluate(DateTime.Now, nl11));
        }
Beispiel #6
0
        public void InterpolationTime()
        {
            var network = CreateNetwork();

            var dateTime = DateTime.Now;

            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network
            };
            // test for defaultvalue

            // set values
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);
            INetworkLocation nl12 = new NetworkLocation(network.Branches[0], 100.0);
            INetworkLocation nl13 = new NetworkLocation(network.Branches[1], 100.0);

            networkCoverage[dateTime, nl11] = 0.1;
            networkCoverage[dateTime, nl12] = 0.2;
            networkCoverage[dateTime, nl13] = 0.3;

            // test the exact networklocation
            Assert.AreEqual(0.1, networkCoverage.Evaluate(dateTime, nl11));
            Assert.AreEqual(0.2, networkCoverage.Evaluate(dateTime, nl12));
            Assert.AreEqual(0.3, networkCoverage.Evaluate(dateTime, nl13));

            INetworkLocation nl21 = new NetworkLocation(network.Branches[0], 0.0);
            INetworkLocation nl22 = new NetworkLocation(network.Branches[0], 100.0);
            INetworkLocation nl23 = new NetworkLocation(network.Branches[1], 0.0);
            INetworkLocation nl24 = new NetworkLocation(network.Branches[1], 200.0);

            // test for networklocations at same location but other instances
            // branch and offset nl21 equals nl11
            Assert.AreEqual(0.1, networkCoverage.Evaluate(dateTime, nl21));
            // branch and offset nl22 equals nl12
            Assert.AreEqual(0.2, networkCoverage.Evaluate(dateTime, nl22));

            // test for value at new location with constant interpolation (1 values available at branch)
            // expect value of nl13 to be set for complete branches[1]
            Assert.AreEqual(0.3, networkCoverage.Evaluate(dateTime, nl23));
            Assert.AreEqual(0.3, networkCoverage.Evaluate(dateTime, nl24));

            // test for interpolation
            INetworkLocation nl1 = new NetworkLocation(network.Branches[0], 50.0);

            Assert.AreEqual(0.15, networkCoverage.Evaluate(dateTime, nl1), 1e-6);
        }
        public void ExtractTimeSlice()
        {
            var network         = GetNetwork();
            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network
            };

            DateTime [] dateTimes = new DateTime[10];

            for (int i = 0; i < 10; i++)
            {
                dateTimes[i] = new DateTime(2000, 1, 1, 1, /* minute */ i, 0);
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[0], 10.0)] = 10.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[0], 90.0)] = 90.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[1], 10.0)] = 110.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[1], 90.0)] = 190.0 + i;
            }

            INetworkCoverage slice = NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, new DateTime(2000, 1, 1, 1, /* minute */ 0, 0));

            Assert.AreEqual(false, slice.IsTimeDependent);
            Assert.AreEqual(10.0 + 0, slice.Evaluate(new NetworkLocation(network.Branches[0], 10.0)));
            Assert.AreEqual(90.0 + 0, slice.Evaluate(new NetworkLocation(network.Branches[0], 90.0)));
            Assert.AreEqual(110.0 + 0, slice.Evaluate(new NetworkLocation(network.Branches[1], 10.0)));
            Assert.AreEqual(190.0 + 0, slice.Evaluate(new NetworkLocation(network.Branches[1], 90.0)));

            //slice = NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, new DateTime(2000, 1, 1, 1, /* minute */9, 0));
            slice = new NetworkCoverage(networkCoverage.Name, false);
            NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, slice,
                                                   new DateTime(2000, 1, 1, 1, /* minute */ 9, 0), true);
            Assert.AreEqual(false, slice.IsTimeDependent);
            Assert.AreEqual(10.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[0], 10.0)));
            Assert.AreEqual(90.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[0], 90.0)));
            Assert.AreEqual(110.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[1], 10.0)));
            Assert.AreEqual(190.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[1], 90.0)));

            // just repeat the previous action; refilling a coverage should also work
            NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, slice,
                                                   new DateTime(2000, 1, 1, 1, /* minute */ 9, 0), true);
            Assert.AreEqual(false, slice.IsTimeDependent);
            Assert.AreEqual(10.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[0], 10.0)));
            Assert.AreEqual(90.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[0], 90.0)));
            Assert.AreEqual(110.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[1], 10.0)));
            Assert.AreEqual(190.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[1], 90.0)));
        }
Beispiel #8
0
        public void AnotherInterpolationTime()
        {
            var network = CreateNetwork();

            var dateTime        = DateTime.Now;
            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network
            };

            networkCoverage[dateTime, new NetworkLocation(network.Branches[0], 10.0)] = 0.1;
            networkCoverage[dateTime, new NetworkLocation(network.Branches[0], 90.0)] = 0.9;

            // at the exact locations
            Assert.AreEqual(0.1, networkCoverage.Evaluate(dateTime, new NetworkLocation(network.Branches[0], 10.0)), 1e-6);
            Assert.AreEqual(0.9, networkCoverage.Evaluate(dateTime, new NetworkLocation(network.Branches[0], 90.0)), 1e-6);

            // at start and end outside the locations
            Assert.AreEqual(0.10, networkCoverage.Evaluate(dateTime, new NetworkLocation(network.Branches[0], 5.0)), 1e-6);
            Assert.AreEqual(0.90, networkCoverage.Evaluate(dateTime, new NetworkLocation(network.Branches[0], 95.0)), 1e-6);

            // in between the 2 locations
            Assert.AreEqual(0.35, networkCoverage.Evaluate(dateTime, new NetworkLocation(network.Branches[0], 35.0)), 1e-6);
        }
Beispiel #9
0
        public void ExtraPolationNoTime()
        {
            var network = CreateNetwork();

            INetworkCoverage networkCoverage = new NetworkCoverage {
                Network = network
            };

            // test for defaultvalue

            // set two values
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 5.0);
            INetworkLocation nl12 = new NetworkLocation(network.Branches[0], 10.0);

            networkCoverage[nl11] = 0.1;
            networkCoverage[nl12] = 0.1;

            //extrapolation
            Assert.AreEqual(0.1, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 20.0)));
        }
Beispiel #10
0
        public void DefaultValueTestValidTime()
        {
            var network = CreateNetwork();

            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network, DefaultValue = 0.33
            };

            var dateTime = DateTime.Now;

            networkCoverage[dateTime, new NetworkLocation(network.Branches[0], 50.0)] = 0.1;
            networkCoverage.Locations.ExtrapolationType = ApproximationType.Constant;

            // ask value form other branch; default value is expected
            INetworkLocation nl11 = new NetworkLocation(network.Branches[1], 0.0);

            // no network location set in networkCoverage expect the default value to return
            Assert.AreEqual(0.33, networkCoverage.Evaluate(dateTime, nl11));
        }
Beispiel #11
0
        public void EvaluateThrowsExceptionWhenEvaluatingWithNonConstantExtrapolation()
        {
            //network 1 branch
            var network = RouteHelperTest.GetSnakeNetwork(false, 1);

            var networkCoverage = new NetworkCoverage { Network = network };

            //set values on the branch
            IBranch firstBranch = network.Branches[0];
            networkCoverage[new NetworkLocation(firstBranch, 10)] = 10.0;
            networkCoverage[new NetworkLocation(firstBranch, 20)] = 10.0;

            //evaluate before the first location (extrapolation)
            networkCoverage.Locations.ExtrapolationType = ExtrapolationType.Linear;
            networkCoverage.Evaluate(new NetworkLocation(firstBranch, 5));


        }
        public void ExtractTimeSlice()
        {
            var network = GetNetwork();
            var networkCoverage = new NetworkCoverage("test", true) { Network = network };

            DateTime []dateTimes = new DateTime[10];

            for (int i = 0; i < 10; i++)
            {
                dateTimes[i] = new DateTime(2000, 1, 1, 1, /* minute */i, 0);
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[0], 10.0)] = 10.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[0], 90.0)] = 90.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[1], 10.0)] = 110.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[1], 90.0)] = 190.0 + i;
            }

            INetworkCoverage slice = NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, new DateTime(2000, 1, 1, 1, /* minute */0, 0));
            Assert.AreEqual(false, slice.IsTimeDependent);
            Assert.AreEqual(10.0 + 0, slice.Evaluate(new NetworkLocation(network.Branches[0], 10.0)));
            Assert.AreEqual(90.0 + 0, slice.Evaluate(new NetworkLocation(network.Branches[0], 90.0)));
            Assert.AreEqual(110.0 + 0, slice.Evaluate(new NetworkLocation(network.Branches[1], 10.0)));
            Assert.AreEqual(190.0 + 0, slice.Evaluate(new NetworkLocation(network.Branches[1], 90.0)));

            //slice = NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, new DateTime(2000, 1, 1, 1, /* minute */9, 0));
            slice = new NetworkCoverage(networkCoverage.Name, false);
            NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, slice,
                                                           new DateTime(2000, 1, 1, 1, /* minute */9, 0), true);
            Assert.AreEqual(false, slice.IsTimeDependent);
            Assert.AreEqual(10.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[0], 10.0)));
            Assert.AreEqual(90.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[0], 90.0)));
            Assert.AreEqual(110.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[1], 10.0)));
            Assert.AreEqual(190.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[1], 90.0)));

            // just repeat the previous action; refilling a coverage should also work
            NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, slice,
                                                           new DateTime(2000, 1, 1, 1, /* minute */9, 0), true);
            Assert.AreEqual(false, slice.IsTimeDependent);
            Assert.AreEqual(10.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[0], 10.0)));
            Assert.AreEqual(90.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[0], 90.0)));
            Assert.AreEqual(110.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[1], 10.0)));
            Assert.AreEqual(190.0 + 9, slice.Evaluate(new NetworkLocation(network.Branches[1], 90.0)));
        }
        public void ExtractTimeSliceUseLocationsFromTarget()
        {
            var network = GetNetwork();
            var networkCoverage = new NetworkCoverage("test", true) { Network = network };

            DateTime[] dateTimes = new DateTime[10];

            for (int i = 0; i < 10; i++)
            {
                dateTimes[i] = new DateTime(2000, 1, 1, 1, /* minute */i, 0);
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[0], 10.0)] = 10.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[0], 50.0)] = 50.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[0], 90.0)] = 90.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[1], 10.0)] = 110.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[1], 50.0)] = 150.0 + i;
                networkCoverage[dateTimes[i], new NetworkLocation(network.Branches[1], 90.0)] = 190.0 + i;
            }

            var slice = new NetworkCoverage("slice", false) { Network = network };
            Assert.AreEqual(false, slice.IsTimeDependent);
            slice[new NetworkLocation(network.Branches[0], 20.0)] = 2;
            slice[new NetworkLocation(network.Branches[0], 80.0)] = 8;
            slice[new NetworkLocation(network.Branches[1], 20.0)] = 12;
            slice[new NetworkLocation(network.Branches[1], 80.0)] = 18;

            NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, slice,
                                                           new DateTime(2000, 1, 1, 1, /* minute */0, 0), false);

            // expected results at time step 0 are 20 80 120 180; this are interpolated values
            Assert.AreEqual(4, slice.Locations.Values.Count);
            Assert.AreEqual(10 /*20*/, slice.Evaluate(new NetworkLocation(network.Branches[0], 20.0)), 1.0e-6);
            Assert.AreEqual(50 /*80*/, slice.Evaluate(new NetworkLocation(network.Branches[0], 80.0)), 1.0e-6);
            Assert.AreEqual(90 /*120*/, slice.Evaluate(new NetworkLocation(network.Branches[1], 20.0)), 1.0e-6);
            Assert.AreEqual(110 /*180*/, slice.Evaluate(new NetworkLocation(network.Branches[1], 80.0)), 1.0e-6);

            NetworkCoverageHelper.ExtractTimeSlice(networkCoverage, slice,
                                                           new DateTime(2000, 1, 1, 1, /* minute */3, 0), false);

            // expected results at time step 3 are 23 83 123 183; this are interpolated values
            Assert.AreEqual(4, slice.Locations.Values.Count);
            Assert.AreEqual(13 /*23*/, slice.Evaluate(new NetworkLocation(network.Branches[0], 20.0)), 1.0e-6);
            Assert.AreEqual(53 /*83*/, slice.Evaluate(new NetworkLocation(network.Branches[0], 80.0)), 1.0e-6);
            Assert.AreEqual(93 /*123*/, slice.Evaluate(new NetworkLocation(network.Branches[1], 20.0)), 1.0e-6);
            Assert.AreEqual(113 /*183*/, slice.Evaluate(new NetworkLocation(network.Branches[1], 80.0)), 1.0e-6);
        }
Beispiel #14
0
        public void SplittingABranchShouldPreserveSetLocationValuePairsAndAdhereToInterpolationExtrapolationType()
        {
            var network = RouteHelperTest.GetSnakeNetwork(false, new Point(0, 0), new Point(0, 100));
                                                           
            var networkCoverage = new NetworkCoverage { Network = network };
            networkCoverage.Components[0].InterpolationType = InterpolationType.Linear;
            networkCoverage.Components[0].ExtrapolationType = ExtrapolationType.Constant;

            //add locations
            var networkLocation1 = new NetworkLocation(network.Branches[0], 20);
            var networkLocation2 = new NetworkLocation(network.Branches[0], 40);
            var networkLocation3 = new NetworkLocation(network.Branches[0], 60);
            var networkLocation4 = new NetworkLocation(network.Branches[0], 80);

            networkCoverage[networkLocation1] = 1.0d;
            networkCoverage[networkLocation2] = 11.0d;
            networkCoverage[networkLocation3] = 20.0d;
            networkCoverage[networkLocation4] = 40.0d;

            //merge the branches/remove the node
            NetworkHelper.SplitBranchAtNode(network.Branches[0], 50);

            // scenario post-split:
            //  1.0  11.0  20   40.0
            //   |    |     |   |
            // O-x----x->O--x---x->O
            // N1       N3         N2

            Assert.AreEqual(1.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 10))); // Extrapolate constant: 1.0
            Assert.AreEqual(6.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 30))); // interpolate linear: (11+1)/2 = 6.0
            Assert.AreEqual(11.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 45)));// Extrapolate constant: 11.0
            Assert.AreEqual(20.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], 5)));// Extrapolate constant: 20.0
            Assert.AreEqual(30.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], 20)));// interpolate linear: (60+40)/2 = 30
            Assert.AreEqual(40.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], 40)));// Extrapolate constant: 40.0
        }
Beispiel #15
0
        public void InterpolationOverMoreThanTwoConnectedBranchesNotSupported()
        {
            var network = new Network();

            var node1 = new Node("node1");
            var node2 = new Node("node2");
            var node3 = new Node("node3");
            var centerNode = new Node("center");
            network.Nodes.Add(node1);
            network.Nodes.Add(node2);
            network.Nodes.Add(node3);
            network.Nodes.Add(centerNode);
            var branch1 = new Branch("branch1", node1, centerNode, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)"), OrderNumber = 1 };
            var branch2 = new Branch("branch2", node2, centerNode, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (200 0, 100 0)"), OrderNumber = 1 };
            var branch3 = new Branch("branch3", node3, centerNode, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (100 100, 100 0)"), OrderNumber = 1 };
            network.Branches.Add(branch1);
            network.Branches.Add(branch2);
            network.Branches.Add(branch3);

            INetworkCoverage networkCoverage = new NetworkCoverage { Network = network };
            networkCoverage.Locations.InterpolationType = InterpolationType.Linear;
            networkCoverage[new NetworkLocation(network.Branches[0], network.Branches[0].Length / 2)] = 10.0;
            networkCoverage[new NetworkLocation(network.Branches[1], network.Branches[0].Length / 2)] = 0.0;
            networkCoverage[new NetworkLocation(network.Branches[2], network.Branches[0].Length / 2)] = 0.0;

            // invalid vertex: more than 2 branches with equal ordernumber, no interpolation:
            Assert.IsTrue(networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], network.Branches[0].Length)).Equals(10.0));
            Assert.IsTrue(networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], network.Branches[0].Length)).Equals(0.0));
            Assert.IsTrue(networkCoverage.Evaluate(new NetworkLocation(network.Branches[2], network.Branches[0].Length)).Equals(0.0));
        }
Beispiel #16
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));
            }

        }
Beispiel #17
0
        public void DefaultValueTestValidTime()
        {
            var network = CreateNetwork();

            var networkCoverage = new NetworkCoverage("test", true) { Network = network, DefaultValue = 0.33 };

            var dateTime = DateTime.Now;
            networkCoverage[dateTime, new NetworkLocation(network.Branches[0], 50.0)] = 0.1;
            networkCoverage.Locations.ExtrapolationType = ExtrapolationType.Constant;

            // ask value form other branch; default value is expected
            INetworkLocation nl11 = new NetworkLocation(network.Branches[1], 0.0);

            // no network location set in networkCoverage expect the default value to return
            Assert.AreEqual(0.33, networkCoverage.Evaluate(dateTime, nl11));
        }
Beispiel #18
0
        public void AnotherInterpolationTime()
        {
            var network = CreateNetwork();

            var dateTime = DateTime.Now;
            var networkCoverage = new NetworkCoverage("test", true) { Network = network };

            networkCoverage[dateTime, new NetworkLocation(network.Branches[0], 10.0)] = 0.1;
            networkCoverage[dateTime, new NetworkLocation(network.Branches[0], 90.0)] = 0.9;

            // at the exact locations
            Assert.AreEqual(0.1, networkCoverage.Evaluate(dateTime, new NetworkLocation(network.Branches[0], 10.0)), 1e-6);
            Assert.AreEqual(0.9, networkCoverage.Evaluate(dateTime, new NetworkLocation(network.Branches[0], 90.0)), 1e-6);

            // at start and end outside the locations
            Assert.AreEqual(0.10, networkCoverage.Evaluate(dateTime, new NetworkLocation(network.Branches[0], 5.0)), 1e-6);
            Assert.AreEqual(0.90, networkCoverage.Evaluate(dateTime, new NetworkLocation(network.Branches[0], 95.0)), 1e-6);

            // in between the 2 locations
            Assert.AreEqual(0.35, networkCoverage.Evaluate(dateTime, new NetworkLocation(network.Branches[0], 35.0)), 1e-6);
        }
Beispiel #19
0
        public void EvaluateWithNonExistingTimeValueTakesPreviousTimeValue()
        {
            // network 1 branch
            var network = RouteHelperTest.GetSnakeNetwork(false, 1);

            var networkCoverage = new NetworkCoverage("", true) {Network = network};
            
            var firstBranch = network.Branches[0];
            var loc1 = new NetworkLocation(firstBranch, 10);
            var loc2 = new NetworkLocation(firstBranch, 15);
            var loc3 = new NetworkLocation(firstBranch, 20);

            var time1 = new DateTime(2000, 1, 1);
            var time2 = new DateTime(2000, 1, 3);

            networkCoverage[time1, loc1] = 10.0;
            networkCoverage[time1, loc3] = 20.0;
            networkCoverage[time2, loc1] = 30.0;
            networkCoverage[time2, loc3] = 40.0;

            // evaluate for time takes the previous value
            // evaluate for location by linear interpolation
            Assert.AreEqual(15.0, networkCoverage.Evaluate(new DateTime(2000, 1, 2), loc2));
        }
Beispiel #20
0
        public void InterpolationTime()
        {
            var network = CreateNetwork();

            var dateTime = DateTime.Now;

            var networkCoverage = new NetworkCoverage("test", true) { Network = network };
            // test for defaultvalue

            // set values
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);
            INetworkLocation nl12 = new NetworkLocation(network.Branches[0], 100.0);
            INetworkLocation nl13 = new NetworkLocation(network.Branches[1], 100.0);
            networkCoverage[dateTime, nl11] = 0.1;
            networkCoverage[dateTime, nl12] = 0.2;
            networkCoverage[dateTime, nl13] = 0.3;

            // test the exact networklocation
            Assert.AreEqual(0.1, networkCoverage.Evaluate(dateTime, nl11));
            Assert.AreEqual(0.2, networkCoverage.Evaluate(dateTime, nl12));
            Assert.AreEqual(0.3, networkCoverage.Evaluate(dateTime, nl13));

            INetworkLocation nl21 = new NetworkLocation(network.Branches[0], 0.0);
            INetworkLocation nl22 = new NetworkLocation(network.Branches[0], 100.0);
            INetworkLocation nl23 = new NetworkLocation(network.Branches[1], 0.0);
            INetworkLocation nl24 = new NetworkLocation(network.Branches[1], 200.0);

            // test for networklocations at same location but other instances
            // branch and offset nl21 equals nl11 
            Assert.AreEqual(0.1, networkCoverage.Evaluate(dateTime, nl21));
            // branch and offset nl22 equals nl12 
            Assert.AreEqual(0.2, networkCoverage.Evaluate(dateTime, nl22));

            // test for value at new location with constant interpolation (1 values available at branch)
            // expect value of nl13 to be set for complete branches[1]
            Assert.AreEqual(0.3, networkCoverage.Evaluate(dateTime, nl23));
            Assert.AreEqual(0.3, networkCoverage.Evaluate(dateTime, nl24));

            // test for interpolation
            INetworkLocation nl1 = new NetworkLocation(network.Branches[0], 50.0);
            Assert.AreEqual(0.15, networkCoverage.Evaluate(dateTime, nl1), 1e-6);
        }
Beispiel #21
0
        public void ExtraPolationNoTime()
        {
            var network = CreateNetwork();

            INetworkCoverage networkCoverage = new NetworkCoverage { Network = network };

            // test for defaultvalue

            // set two values
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 5.0);
            INetworkLocation nl12 = new NetworkLocation(network.Branches[0], 10.0);
            networkCoverage[nl11] = 0.1;
            networkCoverage[nl12] = 0.1;

            //extrapolation 
            Assert.AreEqual(0.1, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 20.0)));
        }
Beispiel #22
0
        public void DefaultValueTestInvalidTime()
        {
            var network = CreateNetwork();

            var networkCoverage = new NetworkCoverage("test", true) { Network = network, DefaultValue = 0.33 };

            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);

            // no network location set in networkCoverage expect the default value to return
            Assert.AreEqual(0.33, networkCoverage.Evaluate(DateTime.Now, nl11));
        }
Beispiel #23
0
        public void EvaluateCoordinateOnTimeFilteredCoverage()
        {
            // create network
            var network = new Network();

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

            var branch1 = new Branch("branch1", node1, node2, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)") };
            network.Branches.Add(branch1);

            // create network coverage
            INetworkCoverage networkCoverage = new NetworkCoverage("",true) { Network = network };

            var time0 = new DateTime(2000);
            networkCoverage[time0, new NetworkLocation(network.Branches[0], 0.0)] = 5.0;
            networkCoverage[time0, new NetworkLocation(network.Branches[0], 100.0)] = 10.0;
            networkCoverage[new DateTime(2001), new NetworkLocation(network.Branches[0], 0.0)] = 20.0;
            networkCoverage[new DateTime(2001), new NetworkLocation(network.Branches[0], 100.0)] = 30.0;

            networkCoverage = (INetworkCoverage) networkCoverage.FilterTime(time0);

            // evaluate
            var value = networkCoverage.Evaluate(new Coordinate(1, 0));

            value.Should().Be.EqualTo(5.0*1.01); // constant interpolation
        }
Beispiel #24
0
        public void InterpolationOverNonDirectedChainNetwork()
        {
            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);

            // ---b1---> <---b2--- <---b3---
            var branch1 = new Branch("branch1", node1, node2, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)"), OrderNumber = 1 };
            var branch2 = new Branch("branch2", node3, node2, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (100 0, 200 0)"), OrderNumber = 1 };
            var branch3 = new Branch("branch3", node4, node3, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (200 0, 300 0)"), OrderNumber = 1 };
            network.Branches.Add(branch1);
            network.Branches.Add(branch2);
            network.Branches.Add(branch3);

            INetworkCoverage networkCoverage = new NetworkCoverage { Network = network };
            networkCoverage.Locations.InterpolationType = InterpolationType.Linear;
            networkCoverage[new NetworkLocation(network.Branches[0], network.Branches[0].Length / 4)] = 10.0;
            networkCoverage[new NetworkLocation(network.Branches[2], network.Branches[0].Length / 4)] = 20.0;

            // result at {branch2, 20} => 10 + (20-10)*155/250 = 16.2
            var result = networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], network.Branches[1].Length/5));
            Assert.AreEqual(16.2, result, float.Epsilon, "Interpolated value for coverage");
        }
Beispiel #25
0
        public void EvaluateWithConstantInterpolation()
        {
            // create network
            var network = new Network();

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

            var branch1 = new Branch("branch1", node1, node2, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)") };
            network.Branches.Add(branch1);

            // create network coverage
            INetworkCoverage networkCoverage = new NetworkCoverage { Network = network };
            networkCoverage.Locations.InterpolationType = InterpolationType.Constant;

            networkCoverage[new NetworkLocation(network.Branches[0], 0.0)] = 0.0;
            networkCoverage[new NetworkLocation(network.Branches[0], 100.0)] = 10.0;

            // evaluate
            var value = networkCoverage.Evaluate<double>(60.0, 0.0);

            value.Should().Be.EqualTo(10.0); // constant interpolation
        }
Beispiel #26
0
        public void DefaultValueTest()
        {
            var network = CreateNetwork();

            INetworkCoverage networkCoverage = new NetworkCoverage { Network = network, DefaultValue = 0.33 };
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);

            // no network location set in networkCoverage expect the default value to return
            Assert.AreEqual(0.33, networkCoverage.Evaluate(nl11));
        }
Beispiel #27
0
        public void EvaluateInterpolationOverConnectedBranchesWithSameOrderNumber()
        {
            var network = new Network();

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

            var branch1 = new Branch("branch1", node1, node2, 100.0)
                              {Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)"), OrderNumber = 1};
            var branch2 = new Branch("branch2", node2, node3, 100.0)
                              {Geometry = GeometryFromWKT.Parse("LINESTRING (100 0, 200 0)"), OrderNumber = 1};
            var branch3 = new Branch("branch3", node2, nodeX, 100.0)
                              {Geometry = GeometryFromWKT.Parse("LINESTRING (100 0, 100 -100)"), OrderNumber = 2};
            network.Branches.Add(branch1);
            network.Branches.Add(branch2);
            network.Branches.Add(branch3);

            INetworkCoverage networkCoverage = new NetworkCoverage {Network = network};
            networkCoverage.Locations.InterpolationType = InterpolationType.Linear;
            networkCoverage[new NetworkLocation(network.Branches[0], network.Branches[0].Length / 2)] = 20.0;
            networkCoverage[new NetworkLocation(network.Branches[1], network.Branches[1].Length / 2)] = 10.0;
            networkCoverage[new NetworkLocation(network.Branches[2], network.Branches[2].Length / 2)] = 245.0;

            // test interpolation over node
            var valueFromLeft =
                networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], network.Branches[0].Length));
            var valueFromRight = networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], 0));
            Assert.AreEqual(valueFromLeft, valueFromRight);
            valueFromLeft.Should().Be.EqualTo(15.0);

            // different order number, no interpolation:
            networkCoverage.Evaluate(new NetworkLocation(network.Branches[2], 0)).Should().Be.EqualTo(245.0);
            
            // now disconnect
            branch2.OrderNumber = -1;
            networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], 0)).Should().Be.EqualTo(10.0);
        }
Beispiel #28
0
        public void InterpolationOverConnectedBranchesHasNoInfiniteLoop()
        {
            // loop network (square) with single coverage value
            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 branch1 = new Branch("branch1", node1, node2, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)"), OrderNumber = 1 };
            var branch2 = new Branch("branch2", node2, node3, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (100 0, 100 -100)"), OrderNumber = 1 };
            var branch3 = new Branch("branch3", node3, node4, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (100 -100, 0 -100)"), OrderNumber = 1 };
            var branch4 = new Branch("branch4", node4, node1, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (0 -100, 0 0)"), OrderNumber = 1 };
            network.Branches.Add(branch1);
            network.Branches.Add(branch2);
            network.Branches.Add(branch3);
            network.Branches.Add(branch4);

            INetworkCoverage networkCoverage = new NetworkCoverage { Network = network };
            networkCoverage.Locations.InterpolationType = InterpolationType.Linear;
            networkCoverage[new NetworkLocation(network.Branches[0], network.Branches[0].Length/2)] = 30.0;
            
            // interpolation in loop (using same coverage value twice)
            networkCoverage.Evaluate(new NetworkLocation(network.Branches[2], network.Branches[2].Length/2)).Should().Be
                .EqualTo(30.0);

            // now interpolate crossing two nodes
            networkCoverage[new NetworkLocation(network.Branches[2], network.Branches[2].Length/2)] = 60.0;
            networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], network.Branches[2].Length / 2)).Should().Be
                .EqualTo(45.0);
        }
Beispiel #29
0
        public void AnotherInterpolationNoTime()
        {
            var network = CreateNetwork();

            INetworkCoverage networkCoverage = new NetworkCoverage { Network = network };

            networkCoverage[new NetworkLocation(network.Branches[0], 10.0)] = 0.1;
            networkCoverage[new NetworkLocation(network.Branches[0], 90.0)] = 0.9;

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

            // at the exact locations
            Assert.AreEqual(0.1, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 10.0)));
            Assert.AreEqual(0.9, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 90.0)));

            // at start and end outside the locations
            Assert.AreEqual(0.10, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 5.0)));
            Assert.AreEqual(0.90, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 95.0)), 1e-6);

            // in between the 2 locations
            Assert.AreEqual(0.35, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 35.0)), 1e-6);
        }
Beispiel #30
0
        public void ConstantInterpolationIsNearestNeighbourInterpolation()
        {
            var network = CreateNetwork();
            
            var networkCoverage = new NetworkCoverage("test", false) { Network = network };
            networkCoverage.Arguments[0].InterpolationType = InterpolationType.Constant;
            networkCoverage[new NetworkLocation(network.Branches[0], 0.0d)] = 0.0d;
            networkCoverage[new NetworkLocation(network.Branches[0], 100.0d)] = 10.0d;

            Assert.AreEqual(0.0, networkCoverage.Evaluate(new Coordinate(40, 0))); 
            Assert.AreEqual(10.0, networkCoverage.Evaluate(new Coordinate(60, 0)));
        }