MPR (1) Merged

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

THADOMAL SHAHANI ENGINEERING COLLEGE

MPR PRESENTATION
Develop a Java GUI Program to
Process 'N' Jobs through two machines
sequencing problem
INTRODUCTION

● The short-term schedules show an optimal order


(sequence) and time in which jobs are processed as
well as show timetables for jobs, equipment, people,
materials, facilities and all other resources that are
needed to support the production plan. The schedules
should use resources efficiently to give low costs and
high utilisations.
Explanation of the
problem statement
● The general scheduling or sequencing problem may be described
as:
1. Let there be n jobs to be performed one at a time on each of 2
machines.
2. The sequence (order) of the machines in which each job should
be performed is given. The actual or expected time required by
the jobs on each of the machines is also given.
3. The general sequencing problem, therefore, is to find the
sequence out of possible sequences which minimise the total
elapsed time between the start of the job in the first machine and
the completion of the last job on the second machine.
Important Points
Terminology

Number of machines Processing Time


The number of machines refer to the It is the time required by a job on
number of service facilities through each machine.
which a job must pass before it is
assumed to be completed

Processing order Idle Time on Machine


It refers to the order(sequence) in It is the time for which a machine
which machines are required for does not have a job to process, i.e.
completing the job. idle time from the end of a job (i-1) to
the start of job i
Terminology

Total Elapsed Time No Passing Rule


It is the time interval between starting It refers to the rule of maintaining the
the first job and completing the last job order in which jobs are to be processed
including the idle time (if any) in a on given machines. For example, if n
particular order by the given set of jobs are to be processed on two
machines machines
Algorithm: Johnson’s Algorithm
Step 1:-
List the jobs along with their processing
times on each machine in a table as
shown below

Step 2:-
The smallest processing time between the two
machines is 2 which corresponds to task A on
machine.
Thus, task A is scheduled as early as possible to
give the sequence as shown below
Johnson’s Algorithm:
Step 3:-
The minimum processing time in this reduced problem is 3 which corresponds to task
E and G both on machine II. Since the corresponding time of task E on machine I is
less than corresponding time of task G on machine I, therefore, task E will be
scheduled in the last and task G shall be scheduled before it. Tasks E and G will not
be considered further. thus , current partial sequence of scheduling tasks becomes

A set of processing times now gets reduced to:


Johnson’s Algorithm:
Step 4:-
The smallest processing time in this reduced problem is 4, which
corresponds to task C and I on machine I and to task D on machine II. Thus
task C will be placed in the second sequence cell and task I in the third
sequence cell and task D in the sequence cell before task G. The entries of
the partial sequence are niow

The set of processing time now gets


reduced as follows
Johnson’s Algorithm
Step 5:-
The smallest processing time in this reduced problem is 5, which corresponds
to tasks B and H both on machine I. Since the corresponding processing times
of B and H on machine II is same, therefore, either of these two tasks can be
placed in fourth and fifth sequence cells. Thus, it indicates an alternative
optimal sequence. The optimal sequences are, therefore, given below
SUMMARY

The program prompts the user for the number of jobs and their
respective processing times on two machines.

It calculates the optimal job sequence using Johnson’s Algorithm


and display the result in a text area with GUI
THANKS!
AWT:

import java.awt.*;

import java.awt.event.*;

import java.util.Arrays;

import java.util.Comparator;

public class SimpleJobSequencingGUI extends Frame implements ActionListener {

private TextField numJobsField;

private Button calculateButton;

private TextArea resultArea;

public SimpleJobSequencingGUI() {

// Basic GUI setup

setTitle("Job Sequencing for Two Machines");

setSize(300, 300);

setLayout(new BorderLayout());

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent we) {

System.exit(0);

});

// Input for number of jobs

Panel inputPanel = new Panel();

inputPanel.add(new Label("Number of Jobs:"));

numJobsField = new TextField(5);

inputPanel.add(numJobsField);

// Button to trigger calculation


calculateButton = new Button("Calculate");

calculateButton.addActionListener(this);

inputPanel.add(calculateButton);

// Area to display the results

resultArea = new TextArea(10, 25);

resultArea.setEditable(false);

// Layout the components

add(inputPanel, BorderLayout.NORTH);

add(resultArea, BorderLayout.CENTER);

@Override

public void actionPerformed(ActionEvent e) {

try {

int numJobs = Integer.parseInt(numJobsField.getText().trim());

// Input processing times for each job

int[][] jobs = new int[numJobs][3]; // jobs[i][0] -> job number, jobs[i][1] -> Machine 1 time,
jobs[i][2] -> Machine 2 time

for (int i = 0; i < numJobs; i++) {

jobs[i][0] = i + 1; // Job number

String m1 = showInputDialog("Enter Machine 1 time for Job " + (i + 1));

String m2 = showInputDialog("Enter Machine 2 time for Job " + (i + 1));

jobs[i][1] = Integer.parseInt(m1);

jobs[i][2] = Integer.parseInt(m2);

// Calculate the optimal sequence using Johnson's Algorithm

int[] sequence = johnsonAlgorithm(jobs);


// Display the results

resultArea.setText("Optimal Job Sequence:\n");

for (int job : sequence) {

resultArea.append("Job " + job + "\n");

} catch (NumberFormatException ex) {

showErrorDialog("Please enter valid numbers.");

// Johnson's Algorithm to calculate the optimal sequence

private int[] johnsonAlgorithm(int[][] jobs) {

int numJobs = jobs.length;

int[] sequence = new int[numJobs];

int front = 0, back = numJobs - 1;

Arrays.sort(jobs, Comparator.comparingInt(job -> Math.min(job[1], job[2])));

for (int[] job : jobs) {

if (job[1] < job[2]) {

sequence[front++] = job[0];

} else {

sequence[back--] = job[0];

return sequence;

}
// Method to show input dialog

private String showInputDialog(String message) {

// Create a simple input dialog using a dialog window

Dialog dialog = new Dialog(this, "Input", true);

dialog.setLayout(new FlowLayout());

dialog.add(new Label(message));

TextField inputField = new TextField(10);

dialog.add(inputField);

Button okButton = new Button("OK");

okButton.addActionListener(event -> {

dialog.setVisible(false);

});

dialog.add(okButton);

dialog.setSize(200, 100);

dialog.setVisible(true);

return inputField.getText();

// Method to show error dialog

private void showErrorDialog(String message) {

Dialog errorDialog = new Dialog(this, "Error", true);

errorDialog.setLayout(new FlowLayout());

errorDialog.add(new Label(message));

Button okButton = new Button("OK");

okButton.addActionListener(event -> {

errorDialog.setVisible(false);
});

errorDialog.add(okButton);

errorDialog.setSize(200, 100);

errorDialog.setVisible(true);

public static void main(String[] args) {

SimpleJobSequencingGUI gui = new SimpleJobSequencingGUI();

gui.setVisible(true);

OUTPUT:

You might also like