Esempio n. 1
0
 public static void Print(NodeJob node)
 {
     Console.WriteLine(node.C);
     while (node.P != null)
     {
         Console.WriteLine(node.Worker + " : " + node.Job);
         node = node.P;
     }
 }
Esempio n. 2
0
        public static double GetBound(NodeJob n)
        {
            double b = n.C;

            for (int i = n.Worker + 1; i < N; i++)
            {
                double min = double.MaxValue;
                for (int j = 0; j < N; j++)
                {
                    if (n.available[j] && G[i][j] < min)
                    {
                        min = G[i][j];
                    }
                }
                b += min;
            }

            return(b);
        }
Esempio n. 3
0
        public static void Start(double[][] jobs)
        {
            N = jobs.GetLength(0);
            G = jobs;

            NodeJob root = new NodeJob(0, -1);

            bool[] avs = new bool[N];
            for (int i = 0; i < N; i++)
            {
                avs[i] = true;
            }
            root.available = avs;
            root.P         = null;

            PriorityQueue <NodeJob> queue = new PriorityQueue <NodeJob>();

            queue.Enqueue(root);
            while (queue.Count() > 0)
            {
                var min = queue.Dequeue();
                if (min.Worker == N - 1)
                {
                    Print(min);
                    return;
                }

                for (int i = 0; i < N; i++)
                {
                    if (min.available[i])
                    {
                        var child = min.Clone();
                        child.P            = min;
                        child.available[i] = false;
                        child.Job          = i;
                        child.C            = min.C + G[child.Worker][i];
                        child.Bound        = GetBound(child);
                        queue.Enqueue(child);
                    }
                }
            }
        }