当前位置: 首页>>代码示例>>C#>>正文


C# BasicAdjList.CreateNode方法代码示例

本文整理汇总了C#中BlueSpider.Blob.Basic.Network.AdjList.BasicAdjList.CreateNode方法的典型用法代码示例。如果您正苦于以下问题:C# BasicAdjList.CreateNode方法的具体用法?C# BasicAdjList.CreateNode怎么用?C# BasicAdjList.CreateNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BlueSpider.Blob.Basic.Network.AdjList.BasicAdjList的用法示例。


在下文中一共展示了BasicAdjList.CreateNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ContainsSelfLoops

        public void ContainsSelfLoops()
        {
            var net =new BasicAdjList(Guid.NewGuid());
            BasicNode nodeA = net.CreateNode() as BasicNode;
            BasicNode nodeB = net.CreateNode() as BasicNode;
            BasicNode nodeC = net.CreateNode() as BasicNode;
            BasicNode nodeD = net.CreateNode() as BasicNode;

            net.CreateEdge(nodeA, nodeB);
            net.CreateEdge(nodeA, nodeA);
            net.CreateEdge(nodeA, nodeD);
            net.CreateEdge(nodeD, nodeD);
            net.CreateEdge(nodeD, nodeD);

            bool result = nodeA.ContainsSelfLoops();
            Assert.True(result);

            result = nodeB.ContainsSelfLoops();
            Assert.False(result);

            result = nodeC.ContainsSelfLoops();
            Assert.False(result);

            result = nodeD.ContainsSelfLoops();
            Assert.True(result);
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:26,代码来源:BasicNodeFixture.cs

示例2: Contains_ReturnsTrueWhenAnEdgeExists

 public void Contains_ReturnsTrueWhenAnEdgeExists()
 {
     //Arrange
     var net = new BasicAdjList(Guid.NewGuid());
     INode nodeA = net.CreateNode();
     INode nodeB = net.CreateNode();
     IEdge edge = net.CreateEdge(nodeA, nodeB);
     bool result = net.Contains(edge);
     Assert.True(result);
 }
开发者ID:BgRva,项目名称:Blob1,代码行数:10,代码来源:BasicAdjListFixture.cs

示例3: CreateEdge_Assigns_Edge_Index

 public void CreateEdge_Assigns_Edge_Index()
 {
     //Arrange
     var net = new BasicAdjList(Guid.NewGuid());
     INode nodeA = net.CreateNode();
     INode nodeB = net.CreateNode();
     INode nodeC = net.CreateNode();
     BasicEdge edgeA = net.CreateEdge(nodeA, nodeB) as BasicEdge;
     BasicEdge edgeB = net.CreateEdge(nodeC, nodeB) as BasicEdge;
     Assert.Equal(0, edgeA.Index);
     Assert.Equal(1, edgeB.Index);
 }
开发者ID:BgRva,项目名称:Blob1,代码行数:12,代码来源:BasicAdjListFixture.cs

示例4: ChangeEventsEnabled_When_False_Prevents_NetworkChanged_Fired_When_RemoveEdge_Is_Called

        public void ChangeEventsEnabled_When_False_Prevents_NetworkChanged_Fired_When_RemoveEdge_Is_Called(int nodeCount, int edgeCount, int edgesToRemove)
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            Random rand = new Random();
            for (int i = 0; i < nodeCount; i++)
                net.CreateNode();

            INode nodeA = null;
            INode nodeB = null;

            IEdge[] edges = new IEdge[edgeCount];
            for (int i = 0; i < edgeCount; i++)
            {
                nodeA = net.Nodes[rand.Next(nodeCount)];
                nodeB = net.Nodes[rand.Next(nodeCount)];
                edges[i] = net.CreateEdge(nodeA, nodeB);
            }
            //---------------------

            var helper = new NetworkChangedEventsTestHelper();
            net.NetworkChanged += new NetworkChangedEventHandler<INetwork, NetworkChangedEventArgs>(helper.NetworkChanged_DummyHandler);

            net.ChangeEventsEnabled = false;
            for (int i = 0; i < edges.Length; i++)
            {
                net.RemoveEdge(edges[i]);
            }

            Assert.Equal(0, helper.NetworkChanged_TimesCalled);
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:31,代码来源:BasicAdjList_As_INetworkChangeEventsFixture.cs

示例5: AddingEdges_Adds_Row_With_Matching_Key_In_EdgeData

        public void AddingEdges_Adds_Row_With_Matching_Key_In_EdgeData(int nodeCount, int edgeCount)
        {
            Random rand = new Random();
            var net = new BasicAdjList(Guid.NewGuid());
            var table = new DataAttributeTable<IEdge>();
            table.Network = net;
            net.EdgeData = table;

            for (int i = 0; i < nodeCount; i++)
            {
                var node = net.CreateNode();
            }

            INode nodeA = null;
            INode nodeB = null;
            IEdge edge = null;
            for (int i = 0; i < edgeCount; i++)
            {
                nodeA = net.Nodes[rand.Next(nodeCount)];
                nodeB = net.Nodes[rand.Next(nodeCount)];
                edge = net.CreateEdge(nodeA, nodeB);
                Assert.Equal((i + 1), net.EdgeCount);
                Assert.Equal((i + 1), table.RowCount);
                Assert.True(table.RowOwnerMap.ContainsKey(edge));
            }
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:26,代码来源:BasicAdjList_DataAttributes_Fixture.cs

示例6: Contains_ReturnsTrueWhenANodeExists

 public void Contains_ReturnsTrueWhenANodeExists()
 {
     //Arrange
     var net = new BasicAdjList(Guid.NewGuid());
     INode node = net.CreateNode();
     bool result = net.Contains(node);
     Assert.True(result);
 }
开发者ID:BgRva,项目名称:Blob1,代码行数:8,代码来源:BasicAdjListFixture.cs

示例7: AddRow

        public void AddRow(int testId, Type[] dataTypes)
        {
            BasicAdjList net = new BasicAdjList(Guid.NewGuid());
            DataAttributeMgr mgr = new DataAttributeMgr(NODE_ATTRIB_LIST, net);

            IAttributeList list = null;

            CreateLists(dataTypes, mgr);

            // add a node --------------
            int expected = 1;
            net.CreateNode();
            Assert.AreEqual(expected, net.NodeCount, "net.NodeCount should match expected");

            // add a row
            mgr.AddRow();

            // check
            Assert.AreEqual(expected, mgr.Depth, "mgr.Depth should match expected");
            list = mgr[0];
            Assert.AreEqual(expected, list.Count, "list Count should match expected");
            list = mgr[1];
            Assert.AreEqual(expected, list.Count, "list Count should match expected");

            // add a node --------------
            expected = 2;
            net.CreateNode();
            Assert.AreEqual(expected, net.NodeCount, "net.NodeCount should match expected");

            // add a row
            mgr.AddRow();

            // check
            Assert.AreEqual(expected, mgr.Depth, "mgr.Depth should match expected");
            list = mgr[0];
            Assert.AreEqual(expected, list.Count, "list Count should match expected");
            list = mgr[1];
            Assert.AreEqual(expected, list.Count, "list Count should match expected");
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:39,代码来源:AttributeListMgrFixture.cs

示例8: ChangeEventsEnabled_When_False_Prevents_NetworkChanged_Fired_When_CreateNode_Is_Called

        public void ChangeEventsEnabled_When_False_Prevents_NetworkChanged_Fired_When_CreateNode_Is_Called(int nodeCount)
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());
            var helper = new NetworkChangedEventsTestHelper();
            net.NetworkChanged += new NetworkChangedEventHandler<INetwork, NetworkChangedEventArgs>(helper.NetworkChanged_DummyHandler);

            net.ChangeEventsEnabled = false;
            for (int i = 0; i < nodeCount; i++)
                net.CreateNode();

            Assert.Equal(0, helper.NetworkChanged_TimesCalled);
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:13,代码来源:BasicAdjList_As_INetworkChangeEventsFixture.cs

示例9: AddingNodes_Adds_Row_With_Matching_Key_In_NodeData

        public void AddingNodes_Adds_Row_With_Matching_Key_In_NodeData(int nodeCount)
        {
            var net = new BasicAdjList(Guid.NewGuid());
            var table = new DataAttributeTable<INode>();
            table.Network = net;
            net.NodeData = table;

            for(int i=0; i<nodeCount; i++)
            {
                var node = net.CreateNode();
                Assert.Equal((i+1), net.NodeCount);
                Assert.Equal((i+1), table.RowCount);
                Assert.True(table.RowOwnerMap.ContainsKey(node));
            }
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:15,代码来源:BasicAdjList_DataAttributes_Fixture.cs

示例10: ParseToNetwork

        /// <summary>
        /// Parses a particular string format to a network.  Format is
        /// "n,e,d|pair;pair;pair" where n = node count, e = edge count, d = true/false for directedness and
        /// pair is a number pair of node indices indicating an edges.  Ex:  "5,3,false|0,1;1,2;3,5"  *note that the
        /// number of pairs should match the number of edges
        /// </summary>
        public static IBasicAdjList ParseToNetwork(string input, bool enableNodeData, bool enableEdgeData)
        {
            // n,e,directed|pair;
            // 7,23,false|0,3;0,2;0,4;1,4;1,2;1,3;2,5;2,4;2,4;3,5;3,1;3,6;3,0;4,4;4,5;4,3;5,1;5,1;5,4;5,6;5,0;6,3;6,1;
            IBasicAdjList network = null;
            var split1 = input.Split(new[] {'|'});
            var split2 = split1[0].Split(new[] { ',' });

            int n = int.Parse(split2[0]);
            int m = int.Parse(split2[1]);
            bool directed = bool.Parse(split2[2]);

            var split3 = split1[1].Split(new[] { ';' }); // pairs

            if(split3.Length != m)
                throw new ArgumentException(string.Format("The number of pairs {0} did not match the number of edges {1} in {2}", split3.Length, m, input));
            INode a = null;
            INode b = null;

            using (var fac = new BasicAdjListFactory())
            {
                network = new BasicAdjList(Guid.NewGuid(), directed);
                for(int i=0; i<n; i++)
                    network.CreateNode();
            }

            string[] pair = null;
            int indexA = -1;
            int indexB = -1;
            for (int i = 0; i < split3.Length; i++ )
            {
                pair = split3[i].Split(new[] { ',' });
                indexA = int.Parse(pair[0]);
                indexB = int.Parse(pair[1]);
                a = network.Nodes[indexA];
                b = network.Nodes[indexB];
                network.CreateEdge(a, b);
            }

            using (var fac = new DataAttributeTableFactory(network))
            {
                if (enableNodeData)
                    fac.CreateNodeDataTable();
                if (enableEdgeData)
                    fac.CreateEdgeDataTable();
            }
            return network;
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:54,代码来源:BasicAdjListParser.cs

示例11: SetValue_Of_T_Assigns_Object_To_Cell_Val_By_Owner_And_ColIndex

        public void SetValue_Of_T_Assigns_Object_To_Cell_Val_By_Owner_And_ColIndex()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());

            var table = new DataAttributeTable<IEdge>();
            table.Network = net;

            table.Columns.Add(new DataColumn("X", typeof (string)));

            var nodeA = net.CreateNode();
            var nodeB = net.CreateNode();
            var nodeC = net.CreateNode();

            var edgeA = net.CreateEdge(nodeB, nodeC);
            var edgeB = net.CreateEdge(nodeA, nodeC);

            table.AddRow(edgeA);
            table.AddRow(edgeB);

            //Act
            table.SetValue<string>(edgeA, 0, "valA");
            table.SetValue<string>(edgeB, 0, "valB");

            string val0 = (string)table.Rows[0][0];
            string val1 = (string)table.Rows[1][0];
            // verify primary keys

            //Assert
            Assert.Equal(val0, "valA");
            Assert.Equal(val1, "valB");
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:32,代码来源:DataAttributeTable_Of_IEdge_Fixture.cs

示例12: ItemGetter_Returns_Cell_Val_By_RowIndex_And_ColIndex

        public void ItemGetter_Returns_Cell_Val_By_RowIndex_And_ColIndex()
        {
            //Arrange
            var net = new BasicAdjList(Guid.NewGuid());

            var table = new DataAttributeTable<IEdge>();
            table.Network = net;

            table.Columns.Add(new DataColumn("X", typeof(string)));

            var nodeA = net.CreateNode();
            var nodeB = net.CreateNode();
            var nodeC = net.CreateNode();

            var edgeA = net.CreateEdge(nodeB, nodeC);
            var edgeB = net.CreateEdge(nodeA, nodeC);

            table.AddRow(edgeA);
            table.AddRow(edgeB);

            table.SetValue<string>(edgeA, 0, "valA");
            table.SetValue<string>(edgeB, 0, "valB");

            //Act
            string val0 = (string)table[0, 0];
            string val1 = (string)table[1, 0];
            // verify primary keys

            //Assert
            Assert.Equal(val0, "valA");
            Assert.Equal(val1, "valB");
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:32,代码来源:DataAttributeTable_Of_IEdge_Fixture.cs

示例13: AdjustToCapacity

        public void AdjustToCapacity(int nodeCount, int padToCount, int expectedCount)
        {
            string defaultVal = "";
            _Net = new BasicAdjList(Guid.NewGuid());
            for (int i = 0; i < nodeCount; i++)     // set capacity
                _Net.CreateNode();

            _Mgr = new DataAttributeMgr(AttributeListMgrFixture.NODE_ATTRIB_LIST, _Net);

            AttributeList<string> list = new AttributeList<string>(_Mgr, defaultVal, "test list");

            Assert.AreEqual(nodeCount, list.Count, "list.Count should be nodeCount");

            list.AdjustToCapacity(padToCount);

            Assert.AreEqual(expectedCount, list.Count, "list.Count should match expected");

            for (int i = 0; i < list.Count; i++)
            {
                Assert.AreEqual(defaultVal, list[i], string.Format("list[{0}] should match expected", i));
            }
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:22,代码来源:AttributeListFixture.cs

示例14: GenerateAdjListWithDataAttribs

        public static IBasicAdjList GenerateAdjListWithDataAttribs(List<Point> edgeList, bool directed, bool enableNodeDataAttribs, bool enableEdgeDataAttribs)
        {
            var q = ((from p in edgeList
                      select p.X)
                .Union((from p in edgeList
                        select p.Y))).Distinct();

            var nodeIndices = q.ToList();
            nodeIndices.Sort();

            var net = new BasicAdjList(Guid.NewGuid(), directed);
            for (int i = 0; i < nodeIndices.Count; i++)
                net.CreateNode();

            INode srcNode = null;
            INode targNode = null;
            for (int i = 0; i < edgeList.Count; i++)
            {
                srcNode = net.Nodes[edgeList[i].X];
                targNode = net.Nodes[edgeList[i].Y];
                net.CreateEdge(srcNode, targNode);
            }

            using (var fac = new DataAttributeTableFactory(net))
            {
                if (enableNodeDataAttribs)
                    fac.CreateNodeDataTable();
                if (enableEdgeDataAttribs)
                    fac.CreateEdgeDataTable();
            }

            return net;
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:33,代码来源:BasicAdjListGenerator.cs

示例15: SetValue_Of_T_Assigns_Object_To_Cell_Val_By_ColIndex

        public void SetValue_Of_T_Assigns_Object_To_Cell_Val_By_ColIndex(string[] colNames, Type[] colTypes)
        {
            var net = new BasicAdjList(Guid.NewGuid());
            var nodeA = net.CreateNode();
            var nodeB = net.CreateNode();
            var nodeC = net.CreateNode();

            _table = _fac.CreateNodeDataTable(net, colNames, colTypes);

            _table.SetValue<string>(nodeB, 1, "val1");
            _table.SetValue<double>(nodeB, 2, -22.2);

            Assert.AreEqual(_table.Rows.Count, 3, "Rowcount should match expected");

            string val1 = (string)_table.Rows[1][1];
            double val2 = (double)_table.Rows[1][2];
            // verify primary keys

            Assert.AreEqual(val1, "val1", "[1][1] should match expected");
            Assert.AreEqual(val2, -22.2, "[1][2] should match expected");
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:21,代码来源:Copy+of+DataAttributeTableFixture.cs


注:本文中的BlueSpider.Blob.Basic.Network.AdjList.BasicAdjList.CreateNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。