コード例 #1
0
        static void SiftDown(int i, worker[] arr)
        {
            int minIndex = i;
            int l        = LeftChild(i);

            if (l < arr.Length && (arr[l].nextFreeTime < arr[minIndex].nextFreeTime || (arr[l].nextFreeTime == arr[minIndex].nextFreeTime && arr[l].ID < arr[minIndex].ID)))
            {
                minIndex = l;
            }

            int r = RightChild(i);

            if (r < arr.Length && (arr[r].nextFreeTime < arr[minIndex].nextFreeTime || (arr[r].nextFreeTime == arr[minIndex].nextFreeTime && arr[r].ID < arr[minIndex].ID)))
            {
                minIndex = r;
            }


            if (i != minIndex)
            {
                worker buffer = arr[i];
                arr[i]        = arr[minIndex];
                arr[minIndex] = buffer;
                SiftDown(minIndex, arr);
            }
        }
コード例 #2
0
        static private void assignJobs()
        {
            assignedWorker = new int[jobs.Length];
            startTime      = new long[jobs.Length];
            worker[] workers = new worker[numWorkers];
            for (int i = 0; i < numWorkers; i++)
            {
                workers[i] = new worker(i);
            }

            for (int i = 0; i < jobs.Length; i++)
            {
                assignedWorker[i]        = workers[0].ID;
                startTime[i]             = workers[0].nextFreeTime;
                workers[0].nextFreeTime += jobs[i];
                SiftDown(0, workers);
            }
        }