这是最简单的两条生产线的情况,
算出从每个工作站出厂的最小时间。
package zboDo;
public class ManufactoryLineOPT {
double [][] ToStationCost = new double [2][4];;
double [][] InStationCost = new double [2][4];;
double [][] OptMatrix = new double [2][4];
public ManufactoryLineOPT() {
double [] line1 = { 2, 2, 3, 1 };
double [] line2 = { 3, 3, 4, 5 };
ToStationCost [0] = line1;
ToStationCost [1] = line2;
double [] Inline1 = { 5, 5, 7, 10 };
double [] Inline2 = { 4, 6, 9, 4 };
InStationCost [0] = Inline1;
InStationCost [1] = Inline2;
for ( int i = 0; i < 2; i++)
for ( int j = 0; j < 4; j++) {
OptMatrix [i][j] = Integer. MAX_VALUE ;
}
OptMatrix [0][0] = ToStationCost [0][0] + InStationCost [0][0];
OptMatrix [1][0] = ToStationCost [1][0] + InStationCost [1][0];
}
public void test() {
BuildUpOptMatrix();
System. out .print( OptMatrix [0][3] < OptMatrix [1][3] ? OptMatrix [0][3]
: OptMatrix [1][3]);
}
private void BuildUpOptMatrix() {
for ( int stationNumber = 1; stationNumber < 4; stationNumber++) {
for ( int lineNumber = 0; lineNumber < 2; lineNumber++) {
double tempMin = Integer. MAX_VALUE ;
for ( int fromlineNumber = 0; fromlineNumber < 2; fromlineNumber++) {
double inStationCost = InStationCost [lineNumber][stationNumber];
double TransferCost = 0;
if (fromlineNumber != lineNumber) {
TransferCost = ToStationCost [lineNumber][stationNumber];
}
double tempTotalCost = inStationCost + TransferCost
+ OptMatrix [fromlineNumber][stationNumber - 1];
if (tempMin > tempTotalCost) {
tempMin = tempTotalCost;
}
}
OptMatrix [lineNumber][stationNumber] = tempMin;
}
}
}
}