public void TestAddition() { var p = new NodesList<Node>(); p.Add(new Node("1.1.1.1")); p.Add(new Node("1.1.1.1")); p.Add(new Node("1.1.1.2")); Assert.IsTrue(p.Count==2); }
public void TestAddition() { var p = new NodesList <Node>(); p.Add(new Node("1.1.1.1")); p.Add(new Node("1.1.1.1")); p.Add(new Node("1.1.1.2")); Assert.IsTrue(p.Count == 2); }
public void AddNode(Node node) { ValidateArgumentIsNotNull(node); NodesList.Add(node.NodeNumber, node); //SetTheConnectionAndStartArray(); }
public void LoadTestData(string path) { using (StreamReader stream = new StreamReader(path)) { numberOfNodes = Convert.ToInt32(stream.ReadLine()); string line = null; int inc = 0; do { line = stream.ReadLine(); if (line != null) { var data = line.Split(' '); NodesList.Add(new Node { Position = inc++, X = Double.Parse(data[0], System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture), Y = Double.Parse(data[1], System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture), Profit = Convert.ToDouble(data[2]), Visited = false }); } } while (line != null); } calcDistances(); }
public void TestMergeInto() { var p = new NodesList<Node>(); p.Add(new Node("1.1.1.1")); p.Add(new Node("1.1.1.1")); p.Add(new Node("1.1.1.2")); p.Add(new Node("1.1.1.4")); var p2 = new NodesList<Node>(); p2.Add(new Node("1.1.1.1")); p2.Add(new Node("1.1.1.1")); p2.Add(new Node("1.1.1.2")); p2.Add(new Node("1.1.1.3")); p.MergeInto(p2); Assert.IsTrue(p.Count==4); }
private void BindgingSettingNodeToNodeTlv(IXmlSetting currentXmlSetting, string strSelectedItemText) { if (SelectType != "") { NodesList.Clear(); foreach (IXmlSettingNode tempNode in currentXmlSetting.GetNodes) { tempNode.IdtAttributes = tempNode.identifier(); if (tempNode.compare_flag) { tempNode.Compare_flag = "1"; tempNode.CompareImage = System.IO.Directory.GetCurrentDirectory() + "\\Images\\compare_flag_true.png"; } else { tempNode.Compare_flag = "0"; tempNode.CompareImage = System.IO.Directory.GetCurrentDirectory() + "\\Images\\compare_flag_false.png"; } tempNode.NameImage = System.IO.Directory.GetCurrentDirectory() + "\\Images\\node.png"; NodesList.Add(tempNode); if (tempNode.name == strSelectedItemText) { // neoItem.Selected = true; } } } }
private void AddNode(string name) { var id = Guid.NewGuid(); var node = new Node(id, name); Ids.Add(name, id); NodesList.Add(node); }
public void TestMergeInto() { var p = new NodesList <Node>(); p.Add(new Node("1.1.1.1")); p.Add(new Node("1.1.1.1")); p.Add(new Node("1.1.1.2")); p.Add(new Node("1.1.1.4")); var p2 = new NodesList <Node>(); p2.Add(new Node("1.1.1.1")); p2.Add(new Node("1.1.1.1")); p2.Add(new Node("1.1.1.2")); p2.Add(new Node("1.1.1.3")); p.MergeInto(p2); Assert.IsTrue(p.Count == 4); }
private void AddNode() { int nodesCount = NodesList.Count; if (nodesCount < maxNodesCount) { NodesList.Add(new Node("node" + nodesCount, new NodePin[10] { new NodePin(), new NodePin(), new NodePin(), new NodePin(), new NodePin(), new NodePin(), new NodePin(), new NodePin(), new NodePin(), new NodePin() })); } }
private bool AddNodeUID(ulong nodeUid) { if (nodeUid == 0 || Sector.Mapper.Nodes.ContainsKey(nodeUid) == false) { Valid = false; return(false); } else { NodesList.Add(nodeUid, null); return(true); } }
public void LoadPolishRoadData(string path) { StreamReader streamCheck = new StreamReader(path); string[] lineCheck = streamCheck.ReadLine().Split(' '); numberOfNodes = Convert.ToInt32(lineCheck[0]); numberOfPaths = Convert.ToInt32(lineCheck[1]); //wczytywanie miast profitow i pozycji geograficznej for (int j = 0; j < numberOfNodes; j++) { string[] linee = streamCheck.ReadLine().Split(' '); NodesList.Add(new Node { Position = Convert.ToInt32(linee[0]) - 1, Profit = Convert.ToInt32(linee[1]), X = Convert.ToDouble(linee[2]), Y = Convert.ToDouble(linee[3]) }); } UnvisitedNodesList = new List <Node>(NodesList); //wczytywanie dystansow miedzy miastami NodeDistances = new double[NodesList.Count, NodesList.Count]; NodeDistancesDisjkstry = new double[NodesList.Count, NodesList.Count]; int i = 0; string[] line = null; try { for (i = 0; i < numberOfPaths - 1; i++) { if (i > 852) { } line = streamCheck.ReadLine().Split(' '); int from = Convert.ToInt32(line[0]); int to = Convert.ToInt32(line[1]); int distance = Convert.ToInt32(line[2]); NodeDistances[from - 1, to - 1] = distance; NodeDistances[to - 1, from - 1] = distance; NodeDistancesDisjkstry[from - 1, to - 1] = distance; NodeDistancesDisjkstry[to - 1, from - 1] = distance; } } catch (Exception e) { MessageBox.Show(e.ToString() + "\n i:" + i + "\n" + line.ToString()); } streamCheck.Close(); }
public void AddNode(int nodenumber) { bool found = false; foreach (Node node in NodesList.Values) { if (node.NodeNumber == nodenumber) { found = true; break; } } if (!found) { Node node = new Node(nodenumber); NodesList.Add(nodenumber, node); } //SetTheConnectionAndStartArray(); }
public void ConfigHCTREASJson() { try { using (StreamReader r = new StreamReader(@"C:\METROM\hctreasNodes.json")) { string json = r.ReadToEnd(); List <Node> items = JsonConvert.DeserializeObject <List <Node> >(json); foreach (Node n in items) { NodesList.Add(n); } } } catch (Exception e) { MessageBox.Show(e.Message); } }
public ViewNode AddNode(ViewNode viewNode) { NodesList.Add(viewNode); return(viewNode); }
static void Main(string[] args) { Console.WriteLine("Program starting .... reading nodes from JSON file input."); if (System.IO.File.Exists("nodestructure.json") == false) { ConsoleHelper.PrintError("File not found: nodestructure.json"); Environment.Exit(0); } if (new System.IO.FileInfo("nodestructure.json").Length == 0) { ConsoleHelper.PrintError("File is empty: nodestructure.json"); Environment.Exit(0); } //Serializer settings to handle any malformed json file input //Added more comments var serializerSettings = new JsonSerializerSettings(); serializerSettings.Error = (object sender, ErrorEventArgs errorArgs) => { if (errorArgs.ErrorContext.Member != null) { ConsoleHelper.PrintError($"Error occured when trying to parse JSON for member: {errorArgs.ErrorContext.Member}"); } ConsoleHelper.PrintError(errorArgs.ErrorContext.Error.Message); errorArgs.ErrorContext.Handled = true; Environment.Exit(0); }; var nodeInputText = System.IO.File.ReadAllText("nodestructure.json"); if (nodeInputText.Length == 0) { ConsoleHelper.PrintError("File is empty: nodestructure.json"); Environment.Exit(0); } var nodesInput = JsonConvert.DeserializeObject <NodeStructureInput>(nodeInputText, serializerSettings); //Successful deserialization of JSON input file NodesList nodesList = new NodesList(); if (nodesInput.Nodes.FindIndex(n => n.Id == nodesInput.Root) < 0) { ConsoleHelper.PrintError("Root node is not found in the list of noodes."); return; } foreach (var node in nodesInput.Nodes) { if (nodesList.ContainsKey(node.Id) == true) { ConsoleHelper.PrintError($"Multiple entries on node {node.Id} found."); } else { nodesList.Add(node.Id, new Node(node.Id, node.Id == nodesInput.Root)); } } foreach (var edge in nodesInput.Edges) { if (nodesList.ContainsKey(edge.From) && nodesList.ContainsKey(edge.To)) { nodesList[edge.From].Out.Add(new Link(edge.To)); nodesList[edge.To].In.Add(new Link(edge.From)); } else { ConsoleHelper.PrintError($"Invalid edge: From {edge.From} To {edge.To}."); } } //Traverse the nodes after initialization to make sure all the nodes are connected to root var disconnectedNodes = nodesList.ValidatePathToAllChildrenFromRoot(); if (disconnectedNodes.Length > 0) { ConsoleHelper.PrintError($"All nodes are not connected to root. Disconnected nodes: {String.Join(",", disconnectedNodes)}"); } while (true) { ConsoleHelper.PrintInput("Select starting node id to remove an edge: "); var fromNodeId = Console.ReadLine(); if (nodesList.ContainsKey(fromNodeId) == false) { ConsoleHelper.PrintError("Selected node is not found. Terminating...."); break; } else { var fromNode = nodesList[fromNodeId]; if (fromNode.Out.Count == 0) { ConsoleHelper.PrintInfo($"Selected node {fromNodeId} does not have any valid outgoing edge to remove. Select another starting node."); continue; } ConsoleHelper.PrintMessage($"Outgoing edge nodes: [{String.Join(", ", nodesList[fromNodeId].Out.Select(l => l.NodeId).ToArray())}]"); ConsoleHelper.PrintInput("Select one of the above nodeIds to remove the edge."); var toNodeId = Console.ReadLine(); if (String.IsNullOrEmpty(toNodeId) == true || nodesList.ContainsKey(toNodeId) == false || fromNode.Out.Where(l => l.NodeId == toNodeId).Count() == 0) { ConsoleHelper.PrintError($"Link not found from node {fromNodeId} to {toNodeId}"); } else { var toNode = nodesList[toNodeId]; ConsoleHelper.PrintInfo($"Removing edge from {fromNodeId} to {toNodeId}"); fromNode.RemoveOutEdge(toNodeId); toNode.RemoveInEdge(fromNodeId); var newlyDisconnectedNodesList = nodesList.ValidateNodesAfterRemovedEdge(fromNodeId); if (newlyDisconnectedNodesList.Count() > 0) { ConsoleHelper.PrintError($"Disconnected Array: [{String.Join(", ", newlyDisconnectedNodesList.ToArray())}]"); } } } } }