コード例 #1
0
 public MatrixRepresentation(int numberOfNodes)
 {
     Matrix = new Edge[numberOfNodes,numberOfNodes];
     Nodes = new Node[numberOfNodes];
     _numberOfNodes = numberOfNodes;
     _numberOfEdges = 0;
 }
コード例 #2
0
ファイル: Weights.cs プロジェクト: wiesRaclawice/ZAiSDGraphs
 public static int SumWeightsTo(MyList<Edge> edges, Node node)
 {
     var sum = 0;
     foreach (var edge in edges)
     {
         if (edge.NodeTo.NodeId.Equals(node.NodeId)) sum += edge.Weight;
     }
     return sum;
 }
コード例 #3
0
 public void AddNode(int nodeId)
 {
     if (Nodes[nodeId] != null) return;
     Nodes[nodeId] = new Node(nodeId);
     _currentNumberOfNodes += 1;
 }
コード例 #4
0
 public NeighborhoodRepresentation(int numberOfNodes)
 {
     Nodes = new Node[numberOfNodes];
     _currentNumberOfNodes = 0;
     _numberOfNodes = numberOfNodes;
 }
コード例 #5
0
 public void AddNode(int nodeId)
 {
     Nodes[nodeId] = new Node(nodeId);
     _currentNumberOfNodes += 1;
 }
コード例 #6
0
 private MyList<Edge> GetPath(Node node)
 {
     var path = new MyList<Edge>();
     var current = node;
     while (current.ParentNode != null)
     {
         path.Add(_representation.GetEdge(current.ParentNode.NodeId, current.NodeId));
         current = current.ParentNode;
     }
     return path;
 }
コード例 #7
0
        private MyList<Edge> SearchPath(Node source, Node terminal)
        {
            var queue = new Queue<Node>();
            var parsed = new HashSet<Node>();
            queue.Enqueue(source);

            while (queue.Count > 0)
            {
                Node current = queue.Dequeue();
                parsed.Add(current);
                if (current.NodeId.Equals(terminal.NodeId))
                {
                    return GetPath(current);
                }

                //Duży narzut dla macierzowej!!!
                var nodeEdges = _representation.GetOutboundEdges(current.NodeId);
                foreach (var edge in nodeEdges)
                {
                    var next = edge.NodeTo;
                    var weight = edge.Weight;
                    var curr = weight - FlowMatrix[edge.NodeFrom.NodeId, edge.NodeTo.NodeId];
                    if (curr > 0 && !parsed.Contains(next))
                    {
                        next.ParentNode = current;
                        queue.Enqueue(next);
                    }
                }
            }

            return null;
        }