Sei sulla pagina 1di 7

JOB SCHEDULING ALGORITHM

In this project input values to programmer are:


- Number of jobs
- Number of processors
- Possible processors for each job
- Capacity of each processor.

Algorithm returns a possible schedule for given inputs.

A. ALGORITHM

My algorithm examines input in two major parts:

1. Assign certain values


2. Assign processors randomly if it could be necessary.

I would like to explain my program with examples.

Example – 1 (Only One Possible Solution):

input.txt :
10 4
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
4 4 1 2
Before program examines jobs variables and matrix:

1 2 3 4 5 6 7 8 9 10
P1 0 0 0 0 0 0 0 1 1 1 4
P2 0 0 0 1 1 1 1 0 0 0 4
P3 0 1 1 0 0 1 1 0 0 1 1
P4 1 0 1 0 1 0 1 0 1 0 2
1 1 2 1 2 2 3 1 2 2
0 0 0 0 0 0 0 0 0 0

Result Array (0 by default)


Capacities for each processor
j array (total possible processors for each job)

Processors

Jobs

1. Scan j array for all 1 values. That means that job can only be done by
only one processor:

1 2 3 4 5 6 7 8 9 10
P1 0 0 0 0 0 0 0 1 1 1 4
P2 0 0 0 1 1 1 1 0 0 0 4
P3 0 1 1 0 0 1 1 0 0 1 1
P4 1 0 1 0 1 0 1 0 1 0 2
1 1 2 1 2 2 3 1 2 2
0 0 0 0 0 0 0 0 0 0

2. Find specific processor:

1 2 3 4 5 6 7 8 9 10
P1 0 0 0 0 0 0 0 1 1 1 4
P2 0 0 0 1 1 1 1 0 0 0 4
P3 0 1 1 0 0 1 1 0 0 1 1
P4 1 0 1 0 1 0 1 0 1 0 2
1 1 2 1 2 2 3 1 2 2
0 0 0 0 0 0 0 0 0 0
3. Write that processor to result array and decrease processor’s capacity:

1 2 3 4 5 6 7 8 9 10
P1 0 0 0 0 0 0 0 1 1 1 4
P2 0 0 0 1 1 1 1 0 0 0 4
P3 0 1 1 0 0 1 1 0 0 1 1
P4 1 0 1 0 1 0 1 0 1 0 1
1 1 2 1 2 2 3 1 2 2
4 0 0 0 0 0 0 0 0 0
allSet = 1

 Scan other node of the array:

1 2 3 4 5 6 7 8 9 10
P1 0 0 0 0 0 0 0 1 1 1 4
P2 0 0 0 1 1 1 1 0 0 0 4
P3 0 1 1 0 0 1 1 0 0 1 1
P4 1 0 1 0 1 0 1 0 1 0 1
1 1 2 1 2 2 3 1 2 2
4 0 0 0 0 0 0 0 0 0

.
.
.

1 2 3 4 5 6 7 8 9 10
P1 0 0 0 0 0 0 0 1 1 1 4
P2 0 0 0 1 1 1 1 0 0 0 4
P3 0 1 1 0 0 1 1 0 0 1 0
P4 1 0 1 0 1 0 1 0 1 0 2
1 1 2 1 2 2 3 1 2 2
4 3 0 0 0 0 0 0 0 0
allSet = 2
 Capacity of processor-3 is full now. If there is a job that can be done by
processor-3, now cannot be done by processor-3:

1 2 3 4 5 6 7 8 9 10
P1 0 0 0 0 0 0 0 1 1 1 4
P2 0 0 0 1 1 1 1 0 0 0 4
P3 0 1 1 0 0 1 1 0 0 1 0
P4 1 0 1 0 1 0 1 0 1 0 2
1 1 2 1 2 2 3 1 2 2
4 3 0 0 0 0 0 0 0 0

 The number of possible processors of these jobs decreased because of new


matrix:

1 2 3 4 5 6 7 8 9 10
P1 0 0 0 0 0 0 0 1 1 1 4
P2 0 0 0 1 1 1 1 0 0 0 4
P3 0 1 0 0 0 0 0 0 0 0 0
P4 1 0 1 0 1 0 1 0 1 0 2
1 1 1 1 2 1 2 1 2 1
4 3 0 0 0 0 0 0 0 0

.
.
.

 At the end of the first loop of the program our result will be:

1 2 3 4 5 6 7 8 9 10
P1 0 0 0 0 0 0 0 1 1 1 1
P2 0 0 0 1 1 1 1 0 0 0 0
P3 0 1 0 0 0 0 0 0 0 0 0
P4 1 0 1 0 1 0 1 0 1 0 0
1 1 1 1 2 1 2 1 2 1
4 3 4 2 2 2 2 1 1 1
allSet = 10
 Because of allSet value reached to number of jobs. Program will not enter to
second loop. Program writes output file and ends.

Example – 2 (A Group Of Jobs May Exchange Their Processors) :

input.txt
4 4
0 0 0 1
0 0 1 0
1 1 0 0
1 1 0 0
1 1 1 1

1 2 3 4
P1 0 0 1 1 1
P2 0 0 1 1 1
P3 0 1 0 0 1
P4 1 0 0 0 1
1 1 2 2
0 0 0 0

 After the first loop:

1 2 3 4
P1 0 0 1 1 1
P2 0 0 1 1 1
P3 0 1 0 0 0
P4 1 0 0 0 0
1 1 2 2
4 3 0 0
allSet = 2

 Because of allSet value did not reach to number of jobs. It means number of
conflict jobs is equal to (jobs value – allSet value) . So a variable (g in the
program) is assigned to this value and second loop will be started:
1. Take the first 1 value of the first conflict job:

1 2 3 4
P1 0 0 1 1 1
P2 0 0 1 1 1
P3 0 1 0 0 0
P4 1 0 0 0 0
1 1 2 2
4 3 0 0

2. Make other 1 values: 0. :

1 2 3 4
P1 0 0 1 1 1
P2 0 0 0 1 1
P3 0 1 0 0 0
P4 1 0 0 0 0
1 1 2 2
4 3 1 0

3. Because of capacity of that is full now:

1 2 3 4
P1 0 0 1 0 0
P2 0 0 0 1 1
P3 0 1 0 0 0
P4 1 0 0 0 0
1 1 2 1
4 3 1 0
4. At the end of the program:

1 2 3 4
P1 0 0 1 0 0
P2 0 0 0 1 0
P3 0 1 0 0 0
P4 1 0 0 0 0
1 1 1 1
4 3 1 2

B. TIME COMPLEXITY

As I described in detail, my algorithm finds solution to given jobs and processors values in a time
complexity of:

O(Number Of Jobs x Number Of Processors)

Potrebbero piacerti anche