public MatrixRepresentation(int numberOfNodes)
 {
     Matrix = new Edge[numberOfNodes,numberOfNodes];
     Nodes = new Node[numberOfNodes];
     _numberOfNodes = numberOfNodes;
     _numberOfEdges = 0;
 }
Esempio n. 2
0
 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;
 }
 public void AddNode(int nodeId)
 {
     if (Nodes[nodeId] != null) return;
     Nodes[nodeId] = new Node(nodeId);
     _currentNumberOfNodes += 1;
 }
 public NeighborhoodRepresentation(int numberOfNodes)
 {
     Nodes = new Node[numberOfNodes];
     _currentNumberOfNodes = 0;
     _numberOfNodes = numberOfNodes;
 }
 public void AddNode(int nodeId)
 {
     Nodes[nodeId] = new Node(nodeId);
     _currentNumberOfNodes += 1;
 }
 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;
 }
        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;
        }