Exemplo n.º 1
0
        public void GeometryTypeGeneratedThemeIsCorrect()
        {
            var featureCoverage = new FeatureCoverage();

            featureCoverage.Arguments.Add(new Variable<Branch>());
            featureCoverage.Components.Add(new Variable<double>());

            var network = new Network() { Name = "Test network" };

            var branch1 = new Branch()
                              {
                                  Name = "Link1",
                                  Geometry =
                                      new LineString(new[] {new Point(0, 0).Coordinate, new Point(10, 0).Coordinate})
                              };

            var branch2 = new Branch()
                              {
                                  Name = "Link2",
                                  Geometry =
                                      new LineString(new[] {new Point(10, 0).Coordinate, new Point(20, 0).Coordinate})
                              };


            network.Branches.AddRange(new[] {branch1, branch2});

            featureCoverage[branch1] = 1;
            featureCoverage[branch2] = 2;
            
            var fcLayer = new FeatureCoverageLayer { Coverage = featureCoverage };

            Assert.AreEqual(typeof(ILineString) ,fcLayer.Style.GeometryType);
            Assert.AreEqual(typeof(ILineString), ((VectorStyle)fcLayer.Theme.ThemeItems[0].Style).GeometryType);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private static Network GetNetwork()
        {
            var network = new Network();
            var node1 = new Node("node1");
            var node2 = new Node("node2"); 
            var node3 = new Node("node3");
            

            var geometry1 = new LineString(new[]
                                              {
                                                  new Coordinate(0, 0),
                                                  new Coordinate(0, 100)
                                              });
            var geometry2 = new LineString(new[]
                                              {
                                                  new Coordinate(0, 100),
                                                  new Coordinate(0, 200)
                                              });
            IBranch branch1 = new Branch(node1, node2, 100) { Geometry = geometry1, Name = "branch1" };
            IBranch branch2 = new Branch(node2, node3, 100) { Geometry = geometry2, Name = "branch2" };
            
            network.Nodes.Add(node1);
            network.Nodes.Add(node2);
            network.Nodes.Add(node3);
            network.Branches.Add(branch1);
            network.Branches.Add(branch2);

            return network;
        }
        public void ConvertToStore()
        {
            var network = new Network();

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

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

            var location = new NetworkLocation(network.Branches[1], 22);

            var typeConverter = new NetworkLocationTypeConverter(network);
            var tuple = typeConverter.ConvertToStore(location); 
            Assert.AreEqual(5,tuple.Length);

            //id 
            Assert.AreEqual(1,tuple[0]);
            //chainage
            Assert.AreEqual(22.0d, tuple[1]);
            //branch name
            Assert.AreEqual("branch2".PadRight(30).ToCharArray(), tuple[2]);
            //x
            Assert.AreEqual(106.957d, (double)tuple[3],0.001d);
            //y
            Assert.AreEqual(20.871d, (double)tuple[4], 0.001d);
        }
Exemplo n.º 5
0
        public static INetwork GetSnakeHydroNetwork(bool generateIDs, params Point[] points)
        {
            var network = new Network();
            for (int i = 0; i < points.Length; i++)
            {
                var nodeName = "node" + (i + 1);

                network.Nodes.Add(new Node(nodeName) { Geometry = points[i] });
            }
            for (int i = 1; i < points.Length; i++)
            {
                var lineGeometry = new LineString(new[]
                                              {
                                                  new Coordinate(points[i-1].X, points[i-1].Y),
                                                  new Coordinate(points[i].X, points[i].Y)
                                              });

                var branchName = "branch" + i;
                var branch = new Branch(network.Nodes[i - 1], network.Nodes[i], lineGeometry.Length)
                {
                    Geometry = lineGeometry,
                    Name = branchName,

                };
                //setting id is optional ..needed for netcdf..but fatal for nhibernate (thinks it saved already)
                if (generateIDs)
                {
                    branch.Id = i;
                }
                network.Branches.Add(branch);
            }
            return network;
        }
Exemplo n.º 6
0
        public void ShortestPathOnNetwork()
        {
            var network = new Network();

            var nodeA = new Node { Name = "A" };
            var nodeB1 = new Node { Name = "B1_IAmShort" };
            var nodeB2 = new Node { Name = "B2_PleaseAvoidMeIAmLooooooooooooong" };
            var nodeC = new Node { Name = "C" };

            var edgeAB1 = new Branch(nodeA, nodeB1);
            var edgeAB2 = new Branch(nodeA, nodeB2);
            var edgeB1C = new Branch(nodeB1, nodeC);
            var edgeB2C = new Branch(nodeB2, nodeC);

            network.Nodes.Add(nodeA);
            network.Nodes.Add(nodeB1);
            network.Nodes.Add(nodeB2);
            network.Nodes.Add(nodeC);

            network.Branches.Add(edgeAB1);
            network.Branches.Add(edgeAB2);
            network.Branches.Add(edgeB1C);
            network.Branches.Add(edgeB2C);

            var shortestPath = network.GetShortestPath(nodeA, nodeC, b => b.Name.Length);

            log.Debug(String.Join(" -> ", shortestPath.Select(b => b.Name).ToArray()));

            Assert.AreEqual(2, shortestPath.Count());
            Assert.AreEqual(edgeAB1, shortestPath.First());
            Assert.AreEqual(edgeB1C, shortestPath.Last());
        }
Exemplo n.º 7
0
        public void NetworkWithDisconnectedNodesMustBeInvalid()
        {
            var network = new Network
                              {
                                  Nodes = {new Node {Name = "node1"}, new Node {Name = "node2"}}
                              };

            var result = network.Validate();
            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(2, result.Messages.Count());
        }
Exemplo n.º 8
0
 public static INetwork CreateTestNetwork()
 {
     var network = new Network();
     var branch = new Branch();
     network.Branches.Add(branch);
     branch.BranchFeatures.Add(new TestBranchFeature());
     var node = new Node();
     network.Nodes.Add(node);
     node.NodeFeatures.Add(new TestNodeFeature { Node = network.Nodes[0] });
     return network;
 }
Exemplo n.º 9
0
        public void ExpectIncomingOutGoingBranchesSet()
        {
            var node1 = new Node { Name = "node1" };
            var node2 = new Node { Name = "node2" };
            var branch1 = new Branch { Name = "branch1", Source = node1, Target = node2 };

            var network = new Network
            {
                Nodes = { node1, node2 },
                Branches = { branch1 }
            };
            node1.IncomingBranches.Count.Should().Be.EqualTo(0);
            node1.OutgoingBranches.Count.Should().Be.EqualTo(1);
            node2.IncomingBranches.Count.Should().Be.EqualTo(1);
            node2.OutgoingBranches.Count.Should().Be.EqualTo(0);
        }
        public void DelayRenderingWhenNetworkIsEditingIsTrue()
        {
            var network = new Network();
            network.BeginEdit(new DefaultEditAction("edit"));
            var layer = new NetworkCoverageSegmentLayer
                            {
                                DataSource = new NetworkCoverageFeatureCollection
                                                 {
                                                     NetworkCoverage =
                                                         new NetworkCoverage {Network = network}
                                                 }
                            };

            var renderer = new NetworkCoverageSegmentRenderer();
            var result = renderer.Render(null, null, layer);

            Assert.IsTrue(result); // True because rendering did not fail
            Assert.IsTrue(layer.RenderRequired); // True, to indicate rendering is delayed
        }
 private static Network CreateNetworkWithSingleBranch(double branchLength)
 {
     var network = new Network {Name = "network"};
     var sourceNode = new Node { Geometry = new Point(0, 0), Network = network, Name = "source"};
     var targetNode = new Node { Geometry = new Point(branchLength, 0), Network = network, Name = "target"};
     var branch = new Branch(sourceNode, targetNode, branchLength)
         {
             Name = "branch",
             Geometry = new LineString(new ICoordinate[]
                 {
                     new Coordinate(0, 0),
                     new Coordinate(branchLength, 0)
                 }),
             Network = network
         };
     network.Nodes.Add(sourceNode);
     network.Nodes.Add(targetNode);
     network.Branches.Add(branch);
     return network;
 }
Exemplo n.º 12
0
        public void NoUnnecessaryEventBubbling()
        {
            var node1 = new Node { Name = "node1" };
            var node2 = new Node { Name = "node2" };
            var branch = new Branch { Name = "branch1", Source = node1, Target = node2 };

            var network = new Network
            {
                Nodes = { node1, node2 },
                Branches = { branch }
            };

            var eventCount = 0;
            ((INotifyPropertyChanged) network).PropertyChanged += delegate { eventCount++; };

            node1.Name = "node1_";

            eventCount
                .Should().Be.EqualTo(1);
        }
        public void ThrowExceptionWhenBranchIdsAreNotUnique()
        {
            var network = new Network();

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

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

            var location = new NetworkLocation(network.Branches[0], 0);

            var typeConverter = new NetworkLocationTypeConverter(network);
            typeConverter.ConvertToStore(location); // throws exception since branch ids are not unique
        }
        public void NextValueOnSameBranch()
        {
            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);
            network.Branches.Add(branch1);
            
            // create network coverate
            var networkCoverage = new NetworkCoverage { Network = network };
            
            NetworkLocationNextValueGenerator networkLocationNextValueGenerator = new NetworkLocationNextValueGenerator(networkCoverage);
            
            INetworkLocation location = networkLocationNextValueGenerator.GetNextValue();
            Assert.AreEqual(new NetworkLocation(branch1, 0), location);
            networkCoverage.Locations.Values.Add(location);
            
            Assert.AreEqual(new NetworkLocation(branch1, 1), networkLocationNextValueGenerator.GetNextValue());
        }
Exemplo n.º 15
0
        /// <summary>
        /// Creates a simple test network of 1 branch amd 2 nodes. The branch has '3' parts, in the center of
        /// the first aand last is a cross section.
        ///                 n
        ///                /
        ///               /
        ///              cs
        ///             /
        ///     -------/
        ///    /
        ///   cs
        ///  /
        /// n
        /// </summary>
        /// <returns></returns>
        private static INetwork CreateTestNetwork()
        {
            var network = new Network();
            var branch1 = new Branch
            {
                Geometry = new LineString(new[]
                                                         {
                                                             new Coordinate(0, 0), new Coordinate(30, 40),
                                                             new Coordinate(70, 40), new Coordinate(100, 100)
                                                         })
            };

            var node1 = new Node { Network = network, Geometry = new Point(new Coordinate(0, 0)) ,Name = "StartNode"};
            var node2 = new Node { Network = network, Geometry = new Point(new Coordinate(100, 100)) ,Name = "EndNode"};

            branch1.Source = node1;
            branch1.Target = node2;

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

            return network;
        }
Exemplo n.º 16
0
        public void OutgoingIncomingBranchesShouldBeChangedWhenBranchIsRemoved()
        {
            var node1 = new Node { Name = "node1" };
            var node2 = new Node { Name = "node2" };
            var node3 = new Node { Name = "node3" };
            var branch1 = new Branch { Name = "branch1", Source = node1, Target = node2 };
            var branch2 = new Branch { Name = "branch2", Source = node2, Target = node3 };

            var network = new Network
            {
                Nodes = { node1, node2, node3 },
                Branches = { branch1, branch2 }
            };

            node1.IncomingBranches.Count.Should().Be.EqualTo(0);
            node1.OutgoingBranches.Count.Should().Be.EqualTo(1);
            node2.IncomingBranches.Count.Should().Be.EqualTo(1);
            node2.OutgoingBranches.Count.Should().Be.EqualTo(1);
            node3.IncomingBranches.Count.Should().Be.EqualTo(1);
            node3.OutgoingBranches.Count.Should().Be.EqualTo(0);

            network.Branches.Remove(branch2);

            node1.IncomingBranches.Count.Should().Be.EqualTo(0);
            node1.OutgoingBranches.Count.Should().Be.EqualTo(1);
            node2.IncomingBranches.Count.Should().Be.EqualTo(1);
            node2.OutgoingBranches.Count.Should().Be.EqualTo(0);
        }
Exemplo n.º 17
0
        public void IsBoundaryNodeShouldBeChangedWhenBranchIsRemoved()
        {
            var node1 = new Node { Name = "node1" };
            var node2 = new Node { Name = "node2" };
            var node3 = new Node { Name = "node3" };
            var branch1 = new Branch { Name = "branch1", Source = node1, Target = node2 };
            var branch2 = new Branch { Name = "branch2", Source = node2, Target = node3 };

            var network = new Network
            {
                Nodes = { node1, node2, node3 },
                Branches = { branch1, branch2 }
            };

            node2.IsBoundaryNode
                .Should().Be.False();

            network.Branches.Remove(branch2);

            node2.IsBoundaryNode
                .Should().Be.True();
        }
Exemplo n.º 18
0
        public void IsConnectedToMultipleBranchesIsChangedWhenBranchIsRemoved()
        {
            var node1 = new Node { Name = "node1" };
            var node2 = new Node { Name = "node2" };
            var node3 = new Node { Name = "node3" };
            var branch1 = new Branch { Name = "branch1", Source = node1, Target = node2 };
            var branch2 = new Branch { Name = "branch2", Source = node2, Target = node3 };
            var network = new Network
                              {
                                  Nodes = { node1, node2, node3 },
                                  Branches = { branch1, branch2 }
                              };

            Assert.IsTrue(node2.IsConnectedToMultipleBranches);

            network.Branches.Remove(branch2);

            Assert.IsFalse(node2.IsConnectedToMultipleBranches);
        }
Exemplo n.º 19
0
        public void CloneNetwork()
        {
            var node1 = new Node { Name = "node1" };
            var node2 = new Node { Name = "node2" };
            var branch = new Branch { Name = "branch1", Source = node1, Target = node2 };
            branch.BranchFeatures.Add(new SimpleBranchFeature() { Branch = branch });

            var network = new Network
            {
                Name = "network1",
                Nodes = { node1, node2 },
                Branches = { branch }
            };

            INetwork clonedNetwork = (INetwork) network.Clone();
            clonedNetwork.Name = "clone";

            clonedNetwork.Branches.Count.Should().Be.EqualTo(1);
            clonedNetwork.Nodes.Count.Should().Be.EqualTo(2);
            clonedNetwork.Branches[0].Name.Should().Be.EqualTo("branch1");
            clonedNetwork.Branches[0].Source.IncomingBranches.Count.Should().Be.EqualTo(0);
            clonedNetwork.Branches[0].Source.OutgoingBranches[0].Should().Be.EqualTo(clonedNetwork.Branches[0]);
            clonedNetwork.Branches[0].Target.IncomingBranches.Count.Should().Be.EqualTo(1);
            clonedNetwork.Branches[0].GetType().Should().Be.EqualTo(network.Branches[0].GetType());

            Assert.AreEqual(clonedNetwork, clonedNetwork.Branches[0].Network);
            Assert.AreEqual(clonedNetwork, clonedNetwork.Branches[0].BranchFeatures[0].Network);
        }
Exemplo n.º 20
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));
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
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
        }
Exemplo n.º 24
0
        public void ChangingBranchGeometryShouldBeFast()
        {
            const int length = 10000;
            var network = new Network();

            var fromNode = new Node {Geometry = new Point(0, 0)};
            var toNode = new Node {Geometry = new Point(length, 0)};

            var branch = new Branch(fromNode, toNode, length)
            {
                Geometry = new LineString(new ICoordinate[]
                {
                    new Coordinate(0,0),
                    new Coordinate(length, 0)
                })
            };

            network.Nodes.Add(fromNode);
            network.Nodes.Add(toNode);
            network.Branches.Add(branch);

            var networkLocations = Enumerable.Range(0, length/10).Select(n => new NetworkLocation(branch, n * 10));
            var coverage = new NetworkCoverage {Network = network};
            
            foreach (var networkLocation in networkLocations)
            {
                coverage[networkLocation] = networkLocation.Chainage;
            }
            
            TestHelper.AssertIsFasterThan(150, () =>
                {
                    branch.Geometry = new LineString(new ICoordinate[]
                        {
                            new Coordinate(0, 0),
                            new Coordinate(length*2, 0)
                        });
                });
        }
Exemplo n.º 25
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
        }
Exemplo n.º 26
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));
            }

        }
Exemplo n.º 27
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");
        }
Exemplo n.º 28
0
        public void CloneNetworkwithBranch()
        {
            var node1 = new Node { Name = "node1" };
            var node2 = new Node {Name = "node2"};
            var channel = new Branch {Name = "branch1", Source = node1, Target = node2};
            channel.BranchFeatures.Add(new SimpleBranchFeature() {Branch = channel});

            var network = new Network
                              {
                                  Name = "network1",
                                  Nodes = {node1, node2},
                                  Branches = {channel}
                              };

            INetwork clonedNetwork = (INetwork) network.Clone();
            clonedNetwork.Branches[0].GetType().Should().Be.EqualTo(network.Branches[0].GetType());

        }
Exemplo n.º 29
0
        public void AddingBranchToNetworkShouldNotResetName()
        {
            var startNode = new Node { Name = "start" };
            var endNode = new Node { Name = "end" };
            var name = "SomeName";

            var branch = new Branch(startNode, endNode) { Name = name };

            var network = new Network
                              {
                                  Name = "network1",
                                  Nodes = { startNode, endNode },
                              };

            network.Branches.Add(branch); // results in branche with name "Branche1"

            branch.Name.Should("Branch name was unexpectedly changed.").Be.EqualTo(name);
        }
Exemplo n.º 30
0
        private static Network GetNetworkForShortestPath()
        {
            var network = new Network();

            var nodeA = new Node {Name = "A"};
            var nodeB1 = new Node {Name = "B1_IAmShort"};
            var nodeB2 = new Node {Name = "B2_PleaseAvoidMeIAmLooooooooooooong"};
            var nodeC = new Node {Name = "C"};

            var edgeAB1 = new Branch(nodeA, nodeB1) { Name = "A->B1" };
            var edgeAB2 = new Branch(nodeA, nodeB2) { Name = "A->B2" };
            var edgeB1C = new Branch(nodeB1, nodeC) { Name = "B1->C" };
            var edgeB2C = new Branch(nodeB2, nodeC) { Name = "B2->C" };

            network.Nodes.Add(nodeA);
            network.Nodes.Add(nodeB1);
            network.Nodes.Add(nodeB2);
            network.Nodes.Add(nodeC);

            network.Branches.Add(edgeAB1);
            network.Branches.Add(edgeAB2);
            network.Branches.Add(edgeB1C);
            network.Branches.Add(edgeB2C);
            return network;
        }