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.º 2
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.º 3
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.º 4
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;
        }
Exemplo n.º 5
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.º 6
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.º 7
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);
        }
Exemplo n.º 8
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);
        }
 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;
 }
        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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
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;
        }
Exemplo n.º 19
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.º 20
0
        public void TestAddSelection()
        {
            var mapControl = new MapControl();
            var layerData = new FeatureCollection();

            var layer = new VectorLayer {Visible = false, DataSource = layerData};
            var feature = new Node {Geometry = new Point(0, 0)};
            layerData.FeatureType = typeof(Node);
            layerData.Add(feature);

            mapControl.Map.Layers.Add(layer);

            Assert.AreEqual(0, mapControl.SelectTool.SelectedTrackersCount);

            mapControl.SelectTool.AddSelection(new IFeature[0]);

            Assert.AreEqual(0, mapControl.SelectTool.SelectedTrackersCount, "No features should be added as none are passed");

            mapControl.SelectTool.AddSelection(new[] { feature });

            Assert.AreEqual(0, mapControl.SelectTool.SelectedTrackersCount, "No features should be added as none are visible");

            layer.Visible = true;
            mapControl.SelectTool.AddSelection(new[] { feature });

            Assert.AreEqual(1, mapControl.SelectTool.SelectedTrackersCount);
        }
Exemplo n.º 21
0
 public static void Validate(Node node)
 {
     if(node.IncomingBranches.Count == 0 && node.OutgoingBranches.Count == 0)
     {
         throw new ValidationException("Lists of incoming and outgoing branches are empty");
     }
 }
Exemplo n.º 22
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.º 23
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.º 24
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.º 25
0
        public void CloneNetworkWithManyCrossSectionWithProcessedData()
        {
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var network = new HydroNetwork();
            var fromNode = new Node();
            var toNode = new Node();
            var branch = new Channel(fromNode, toNode, 5000);
            network.Nodes.Add(fromNode);
            network.Nodes.Add(toNode);
            network.Branches.Add(branch);

            for (var i = 0.0; i <= 5000; i++)
            {
                var crossSection = new CrossSection { Offset = i };
                var processedData = crossSection.ConveyanceData; // makes sure it is created
                branch.BranchFeatures.Add(crossSection);
            }
            stopwatch.Stop();

            log.DebugFormat("It took {0} ms to create network containing 5000 cross-sections", stopwatch.ElapsedMilliseconds);

            stopwatch = new Stopwatch();
            stopwatch.Start();
            var networkClone = network.Clone();
            stopwatch.Stop();

            log.DebugFormat("It took {0} ms to clone network containing 5000 cross-sections", stopwatch.ElapsedMilliseconds);

            stopwatch.ElapsedMilliseconds
                .Should("Clone of network containing many cross-sections with processed data should be reasonable")
                    .Be.LessThan(13000);
        }
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 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));
        }
Exemplo n.º 28
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.º 29
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.º 30
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);
        }