예제 #1
0
        static ICollection<Node> PrimAlgorithm(Node startNode)
        {
            var mst = new List<Node>();
            PriorityQueue queue = new PriorityQueue();
            startNode.Used = true;

            mst.Add(startNode);
            foreach (var connection in neighbourhood[startNode])
            {
                queue.Enqueue(connection);
            }

            while (mst.Count != houses.Count)
            {
                var current = queue.Dequeue();

                current.ToNode.Used = true;
                mst.Add(current.ToNode);

                foreach (var connection in neighbourhood[current.ToNode])
                {
                    if (!connection.ToNode.Used)
                    {
                        queue.Enqueue(connection);
                    }
                }
            }

            return mst;
        }
예제 #2
0
 public Connection(Node to, int dist)
 {
     this.ToNode = to;
     this.Distance = dist;
 }