private Node BuildNodesTree(List<Link> links, string rootNodeName) { Node rootNode = new Node(rootNodeName); rootNode.Relations = GetNodeRelations(links, rootNodeName); return rootNode; }
private void CalculatePosiblePaths(Node nodeTree, string startNodeName, string endNodeName) { foreach (var item in nodeTree.Relations) { if (_currentPath.Path.Count == 0) { _currentPath.Path.Add(endNodeName); } _currentPath.Path.Add(item.TargetNode.Name); _currentPath.TotalWeights += item.Weitgh; if (item.TargetNode.Name == startNodeName) { _posiblePaths.Add(_currentPath.Clone()); _currentPath.Clear(); continue; } CalculatePosiblePaths(item.TargetNode, startNodeName, endNodeName); _currentPath.Clone(); } }
private List<NodeRelation> GetNodeRelations(List<Link> links, string nodeName) { var realations = new List<NodeRelation>(); var relateNodes = links.Where(link => link.SecondNode == nodeName).ToList(); if (relateNodes == null) { return realations; } foreach (var link in relateNodes) { Node adjacentNode = new Node(link.FirtsNode); adjacentNode.Relations = GetNodeRelations(links, link.FirtsNode); NodeRelation relation = new NodeRelation(adjacentNode, link.Weight); realations.Add(relation); } return realations; }
public NodeRelation(Node targetNode, int weitgh) { this.TargetNode = targetNode; this.Weitgh = weitgh; }