Problem description:
There are n Independent jobs which are processed by m identical machines. The processing time required for job I is t [I].
Any job can be processed on any machine, but it cannot be interrupted before it is completed. No job can be split into smaller jobs.
A job scheduling scheme should be provided to process the n jobs by m machines in the shortest time.
Algorithm analysis:
By adopting the greedy selection policy with the highest priority for jobs with the longest processing time, an approximate algorithm can be designed to solve the problem of multi-machine scheduling.
N <= m (the number of jobs is smaller than the number of machines), n> m (the number of jobs is greater than the number of machines.
Assume that there are 7 independent jobs, and the processing time is {, 14, 6, 5, 3} respectively, which are processed by three machines M1, M2, and M3. Shows the Job Scheduling Based on the greedy algorithm. The total processing time is 17.
[Cpp]
# Include <stdio. h>
# Define N 7 // number of jobs
# Define M 3 // number of machines
Int s [M] = {0, 0}; // The total time consumed for the currently allocated jobs on each machine
Int main (void)
{
Int time [N] = {16, 14, 6, 5, 4, 3, 2}; // the processing time is sorted in ascending order.
Int maxtime = 0;
If (M> = N)
{
Maxtime = setwork1 (time, N );
}
Else
{
Maxtime = setwork2 (time, N );
}
Printf ("the maximum time is % d. ", Maxtime );
System ("PAUSE ");
}
// The number of machines is greater than the number of jobs to be allocated
Int setwork1 (int t [], int n)
{
Int I;
For (I = 0; I <n; I ++)
{
S [I] = t [I];
}
Int ma = max (s, N );
Return ma;
}
// The number of machines is smaller than the number of jobs to be allocated
Int setwork2 (int t [], int n)
{
Int I;
Int mi = 0;
For (I = 0; I <n; I ++)
{
Mi = min (M );
Printf ("% d, the time and minimum machine number are % d. The time is % d: \ n", I, mi, s [mi]);
S [mi] = s [mi] + t [I];
}
Int ma = max (s, M );
Return ma;
}
// Obtain the current job processing time and the minimum machine number
Int min (int m)
{
Int min = 0;
Int I;
For (I = 1; I <m; I ++)
{
If (s [min]> s [I])
{
Min = I;
}
}
Return min;
}
// Obtain the final result (maximum processing time)
Int max (int s [], int num)
{
Int max = s [0];
Int I;
For (I = 1; I <num; I ++)
{
If (max <s [I])
{
Max = s [I];
}
}
Return max;
}