public void randomizedNodeTest() { Random randomGenerator = new Random (); int numNodes = 50; int numEdges = 200; Node[] nodes = new Node[numNodes]; for(int i = 0; i < numNodes; i++){ nodes[i] = new Node(i); } Dictionary<int, List<HashSet<Node>>> edgeMap = initializeEdgeMap(nodes); int id1 = 0; //id of nodes to connect int id2 = 0; int transport; for(int i = 0; i < numEdges; i++){ while(id1 == id2){ id1 = (int)(randomGenerator.NextDouble() * numNodes); id2 = (int)(randomGenerator.NextDouble() * numNodes); } transport = (int)(randomGenerator.NextDouble() * 3); if(transport == 0){ nodes[id1].addEdge(nodes[id2], TransportType.taxi); nodes[id2].addEdge(nodes[id1], TransportType.taxi); edgeMap[id1][transport].Add(nodes[id2]); edgeMap[id2][transport].Add(nodes[id1]); } else if(transport == 1){ nodes[id1].addEdge(nodes[id2], TransportType.bus); nodes[id2].addEdge(nodes[id1], TransportType.bus); edgeMap[id1][transport].Add(nodes[id2]); edgeMap[id2][transport].Add(nodes[id1]); } else if(transport == 2){ nodes[id1].addEdge(nodes[id2], TransportType.underground); nodes[id2].addEdge(nodes[id1], TransportType.underground); edgeMap[id1][transport].Add(nodes[id2]); edgeMap[id2][transport].Add(nodes[id1]); } id1 = 0; id2 = 0; } for(int i = 0; i < numNodes; i++){ Assert.AreEqual(edgeMap[i][0], nodes[i].getEdges(TransportType.taxi)); Assert.AreEqual(edgeMap[i][1], nodes[i].getEdges(TransportType.bus)); Assert.AreEqual(edgeMap[i][2], nodes[i].getEdges(TransportType.underground)); } }
public Node[] constructBasicBoard() { Node[] nodes = new Node[5]; for(int i = 0; i < nodes.GetLength(0); i++){ nodes[i] = new Node(i); } nodes[0].addEdge(nodes[2], TransportType.taxi); nodes[0].addEdge(nodes[3], TransportType.taxi); nodes[0].addEdge(nodes[4], TransportType.taxi); nodes[1].addEdge(nodes[2], TransportType.taxi); nodes[1].addEdge(nodes[4], TransportType.taxi); nodes[2].addEdge(nodes[0], TransportType.taxi); nodes[2].addEdge(nodes[1], TransportType.taxi); nodes[2].addEdge(nodes[4], TransportType.taxi); nodes[3].addEdge(nodes[0], TransportType.taxi); nodes[3].addEdge(nodes[4], TransportType.taxi); nodes[4].addEdge(nodes[0], TransportType.taxi); nodes[4].addEdge(nodes[1], TransportType.taxi); nodes[4].addEdge(nodes[2], TransportType.taxi); nodes[4].addEdge(nodes[3], TransportType.taxi); nodes[0].addEdge(nodes[1], TransportType.bus); nodes[1].addEdge(nodes[0], TransportType.bus); nodes[0].addEdge(nodes[3], TransportType.bus); nodes[3].addEdge(nodes[0], TransportType.bus); nodes[1].addEdge(nodes[3], TransportType.bus); nodes[3].addEdge(nodes[1], TransportType.bus); nodes[0].addEdge(nodes[2], TransportType.underground); nodes[2].addEdge(nodes[0], TransportType.underground); nodes[2].addEdge(nodes[3], TransportType.underground); nodes[3].addEdge(nodes[2], TransportType.underground); return nodes; }
public Dictionary<int, List<HashSet<Node>>> initializeEdgeMap(Node[] nodes) { Dictionary<int, List<HashSet<Node>>> edgeMap = new Dictionary<int, List<HashSet<Node>>>(); for(int i = 0; i < nodes.GetLength(0); i++){ HashSet<Node> edgeSet1 = new HashSet<Node>(); HashSet<Node> edgeSet2 = new HashSet<Node>(); HashSet<Node> edgeSet3 = new HashSet<Node>(); List<HashSet<Node>> edgeList = new List<HashSet<Node>>(); edgeList.Add(edgeSet1); //taxi edgeList.Add(edgeSet2); //bus edgeList.Add(edgeSet3); //underground edgeMap.Add(i, edgeList); } return edgeMap; }
public void AddChild(Node _child) { this.listChilds.Add(_child); _child.Parent = this; }