Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a third lane to this two lane assembly-line process code. import java.io.BufferedReader; import java.io.FileReader; import java.io.FileNotFoundException; public class assemblyScheduling { public static void main(String[]

Implement a third lane to this two lane assembly-line process code.

import java.io.BufferedReader; import java.io.FileReader; import java.io.FileNotFoundException; public class assemblyScheduling { public static void main(String[] args) { //format [line number][station] int[][] transTimes = new int[2][82]; //store transfer times, maximum stations is 80 int[][] processTimes = new int[2][82]; //store process times int stationCount = 0; //gets number of stations //transfer data from file data into arrays //everything in the try catch should work for any number of assembly lines try{ String[] files = {"src/transitionTimes.txt", "src/processTimes.txt"}; //I made this a 3d array so I wouldn't have to copy the same work int[][][] times = {transTimes, processTimes}; for(int f = 0; f < files.length; f++) { BufferedReader reader = new BufferedReader(new FileReader(files[f])); for(int i = 0; i < transTimes[0].length; i++) { String str = reader.readLine(); if(str != null) { String[] parts = str.split("\t", -1); //only want to increment station count when in processTimes if(f == 1) { stationCount++; } for(int p = 0; p < parts.length; p++) { times[f][p][i] = Integer.parseInt(parts[p]); } } } reader.close(); } } catch(Exception e) { e.printStackTrace(); } //Organized [path][totalCost] int[][] f1 = new int [stationCount][2]; //fastest routes and times to stops on line 1 int[][] f2 = new int [stationCount][2]; //fastest routes and times to stops on line 2 //initialize to entry cost f1[1][0] = processTimes[0][0] + processTimes[0][0]; f1[1][1] = 1; f2[1][0] = processTimes[1][0] + processTimes[1][0]; f2[1][1] = 2; int station = 2; //possibilities: faster come in from opposite stay, faster to switch while(processTimes[0][station + 1] != 0) { //making the assumption a cost will never be 0 int stay = 0; //stay on the same line int swap = 0; //come in from other line //f1 stay = f1[station - 1][0]; swap = f2[station - 1][0] + transTimes[1][station - 2]; //compare to decide if its better to stay on current route or use other route if(stay <= swap) { f1[station][0] = stay + processTimes[0][station]; f1[station][1] = (f1[station - 1][1] * 10) + 1; } else { f1[station][0] = swap + processTimes[0][station]; f1[station][1] = (f2[station - 1][1] * 10) + 1; } //repeat process with other line stay = f2[station - 1][0]; swap = f1[station - 1][0] + transTimes[0][station - 2]; if(stay <= swap) { //default is stay so thats less interruption in the factory f2[station][0] = stay + processTimes[1][station]; f2[station][1] = (f2[station - 1][1] * 10) + 2; } else { f2[station][0] = swap + processTimes[1][station]; f2[station][1] = (f1[station - 1][1] * 10) + 2; } station++; } //add on exit cost f1[station][0] = f1[station - 1][0] + processTimes[0][station]; f2[station][0] = f2[station - 1][0] + processTimes[1][station]; int path; if(f1[station][0] <= f2[station][0]) { //Line in path 1 is faster or tie path = f1[station -1][1]; } else { path = f2[station - 1][1]; } for(int i = station - 1; i > 0; i--) { System.out.println("Station " + i + ": Line " + (path % 10)); path /= 10; } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions