?? style.java
字號:
package com.power.pipeengine.DispatchReportMap;
/**
* <p>Title: PIPE Engine</p>
* <p>Description: Global Planning Optimization Engine</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Paraster, Inc.</p>
* @author unascribed
* @version 1.0
*/
import java.util.*;
import java.text.*;
public class Style {
private Integer rteID;
private String orderID;
private String styleID;
private Integer pid;
private Integer pidNext;
private Integer qty;
private Double pTime;
private int qtyProcessed = 0;
private int bucketID;
private SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
private Date dueDate;
private double numOfOperatorsRqd = 0;
private int[] qtyArray;
private double[] curve;
private int numOfDaysRqd = 0;
private Date start;
private int startDateOffset = 0;
private Vector detailedStyleID = new Vector();
private Vector demandByDetailedStyle = new Vector();
public Style( Integer rID,
String odr,
String sid,
Integer procID,
Integer nextProcID,
Integer q,
Double t ) {
rteID = rID;
orderID = odr;
styleID = sid;
pid = procID;
pidNext = nextProcID;
qty = q;
pTime = t;
}
public void stStartDateOffset( int num ) {
startDateOffset = num;
}
public boolean equals( Style aStyle ) {
if( ! orderID.equals( aStyle.getOrderID() ) ) {
return false;
}
if( ! styleID.equals( aStyle.getStyleID() ) ) {
return false;
}
if( aStyle.getProcessID() != this.getProcessID() ) {
return false;
}
return true;
}
public void addDetailedStyleID( String anID ) {
detailedStyleID.add( anID );
}
public boolean isPartOfStyle( String detailedID ) {
for( int i=0; i<detailedStyleID.size(); i++ ) {
String anID= (String) detailedStyleID.elementAt( i );
if( anID.equals( detailedID ) ) return true;
}
return false;
}
public void accumDemand( Integer q ) {
qty = new Integer( qty.intValue() + q.intValue() );
demandByDetailedStyle.add( q );
}
public double getRequirement() {
return qty.intValue() * pTime.doubleValue();
}
public void setDueDate( Date aDate ) {
dueDate = aDate;
}
public Date getDueDate() {
return dueDate;
}
public Integer getRouteID() {
return rteID;
}
public String getOrderID() {
return orderID;
}
public String getStyleID() {
return styleID;
}
public int getProcessID() {
return pid.intValue();
}
public int getNextProcessID() {
return pidNext.intValue();
}
public int getQuantity() {
return qty.intValue();
}
public void reduceQty( int amt ) {
int newAmt = Math.max( 0, qty.intValue() - amt );
qty = new Integer( newAmt );
}
public double getProcessingTime() {
return pTime.doubleValue();
}
public void setProcessedQty( int anInt ) {
qtyProcessed = anInt;
}
public void incrementQtyProcessed( int anInt ) {
qtyProcessed += anInt;
}
public void setAssignedQty( int[] q ) {
qtyArray = q;
}
public void setSpeedCurve( double[] speedCurve ) {
curve = speedCurve;
}
public void setNumOfDaysRqd( int days ) {
numOfDaysRqd = days;
}
public void computeNumOfOperators() {
numOfOperatorsRqd = qtyArray[0] * pTime.doubleValue() / 60 / 8;
System.out.println( "PID = " + pid.doubleValue() + "operators rqd = " + numOfOperatorsRqd );
}
public double getNumOfOperators() {
return numOfOperatorsRqd;
}
public void setStartDate( Date aDate ) {
start = aDate;
}
public boolean metDemand() {
if( qtyProcessed == qty.intValue() ) {
return true;
}
return false;
}
public void setLastStartsBucket( int anID ) {
bucketID = anID;
}
public int getLastStartBucket() {
return bucketID;
}
private Vector operators = new Vector();
private Vector percentages = new Vector();
public void addOperator( ProcessCapability pc, Double percent ) {
operators.add( pc );
percentages.add( percent );
}
private double getTotalCapability() {
double total = 0;
for( int i=0; i<operators.size(); i++ ) {
ProcessCapability pc = (ProcessCapability) operators.elementAt( i );
total += pc.getCapability( this.getProcessID() );
}
return total;
}
public double getNumOfAssignedOperators() {
for( int i=0; i< percentages.size(); i++ ) {
Double percent = (Double) percentages.elementAt( i );
ProcessCapability pc = (ProcessCapability) operators.elementAt( i );
//total += percent.doubleValue() * pc.getCapability( this.getProcessID() );
}
return total;*/
return operators.size();
}
public void print( ) {
String str = orderID + ", " +
styleID + ", " +
qty + ", " +
pid;
System.out.println( str );
}
public void print( Date dueDate, int dmd, int cumStarts, Date catchUpDate ) {
String str = orderID + ", " +
styleID + ", " +
dmd + ", " +
sdf.format( dueDate ) + ", " +
cumStarts + ", " +
sdf.format( catchUpDate );
System.out.println( str );
}
public void generateSchedule() {
assignOperator( this,
operators,
qtyArray,
start,
numOfDaysRqd,
numOfOperatorsRqd,
curve );
}
public String getSchedules() {
return schedules.toString();
}
StringBuffer schedules = new StringBuffer();
private void assignOperator( Style style,
Vector procCap,
int[] qty,
Date start,
int numOfDaysRqd,
double numOfStdOperators,
double[] curveForThisOrder ) {
allocateDetailedStylesOverHorizon( qty );
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
Calendar cal = Calendar.getInstance();
cal.setTime( start );
cal.add( Calendar.DAY_OF_YEAR, startDateOffset );
for( int i=0; i<numOfDaysRqd; i++ ) {
int cumAllocatedQty = 0;
boolean finished = false;
Vector detailedAllocation = (Vector) styleQtyPairs.elementAt( i );
for( int j=0; j<procCap.size(); j++ ) {
if( finished ) break;
int allocatedQty = 0;
ProcessCapability pc = (ProcessCapability) procCap.elementAt( j );
//test if zero assignment
allocatedQty = (int) Math.floor(qty[i] *
pc.getCapability(style.getProcessID()) *
((Double) percentages.elementAt(j)).doubleValue() /
this.getTotalCapability() );
//numOfStdOperators);
if( j < procCap.size() - 1 && allocatedQty == 0 ) continue;
Vector allocated = new Vector();
if (j < procCap.size() - 1) {
allocatedQty = (int) Math.floor(qty[i] *
pc.getCapability(style.getProcessID()) *
((Double) percentages.elementAt(j)).doubleValue() /
this.getTotalCapability() );
//numOfStdOperators);
cumAllocatedQty += allocatedQty;
if( cumAllocatedQty > qty[i] ) {
int extra = cumAllocatedQty - qty[i];
allocatedQty -= extra;
finished = true;
cumAllocatedQty -= extra;
}
if( cumAllocatedQty == qty[i] ) {
finished = true;
}
//schedules.append(allocatedQty + ","); //qty
} else {
allocatedQty = (qty[i] - cumAllocatedQty);
//schedules.append( (qty[i] - cumAllocatedQty) + ","); //qty
finished = true;
cumAllocatedQty += allocatedQty;
}
int cumDetailed = 0;
for( int k=0; k<detailedAllocation.size(); k+=2 ) {
if( allocatedQty == 0 ) break;
int amt = ((Integer) detailedAllocation.elementAt( k+1 ) ).intValue();
if( amt == 0 ) continue;
if( allocatedQty >= amt ) {
allocated.add( (String) detailedAllocation.elementAt(k) );
allocated.add( new Integer( amt ) );
allocatedQty -= amt;
detailedAllocation.set( k+1, new Integer(0) );
} else {
allocated.add( (String) detailedAllocation.elementAt(k) );
allocated.add( new Integer( allocatedQty ) );
amt -= allocatedQty;
allocatedQty = 0;
detailedAllocation.set( k+1, new Integer(amt) );
}
}
for( int k=0; k<allocated.size(); k+=2 ) {
schedules.append("-1,"); //equipment
schedules.append(style.getOrderID() + ","); //orderID
schedules.append( (String) allocated.elementAt(k) + ","); //style ID
schedules.append(style.getProcessID() + ","); //process ID
schedules.append(pc.getEmployeeID() + ","); //employee ID
schedules.append( ( (Integer) allocated.elementAt(k+1)).intValue() +
",");
schedules.append("0,"); //finished qty
cal.set(Calendar.HOUR_OF_DAY, 8);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
Date startHours = cal.getTime();
schedules.append(sdf.format(startHours) + ",");
cal.set(Calendar.HOUR_OF_DAY, 17);
Date endHours = cal.getTime();
schedules.append(sdf.format(endHours) + ",");
schedules.append("null,"); //null value
schedules.append("1\n"); //line number
}
}
cal.add(Calendar.DAY_OF_MONTH, 1);
}
}
Vector styleQtyPairs = new Vector();
private void allocateDetailedStylesOverHorizon( int[] qty ) {
int[] qtyCopy = new int[qty.length];
for( int i=0; i<qty.length; i++ ) {
qtyCopy[i] = qty[i];
styleQtyPairs.add( new Vector() );
}
for( int i=0; i<demandByDetailedStyle.size(); i++ ) {
int dmdQty = ( (Integer) demandByDetailedStyle.elementAt( i ) ).intValue();
String aStyleID = (String) detailedStyleID.elementAt( i );
for( int j=0; j<qtyCopy.length; j++ ) {
//if( ((String) styleQtyPairs.elementAt( j )).equals( "" ) ) {
//styleQtyPairs.set(j, new Vector());
//}
Vector tmpVec = (Vector) styleQtyPairs.elementAt( j );
if( dmdQty == 0 ) break;
if( qtyCopy[j] == 0 ) continue;
if( dmdQty <= qtyCopy[j] ) {
tmpVec.add( aStyleID );
tmpVec.add( new Integer( dmdQty ) );
qtyCopy[j] -= dmdQty;
dmdQty = 0;
} else {
tmpVec.add( aStyleID );
tmpVec.add( new Integer( qtyCopy[j] ) );
dmdQty -= qtyCopy[j];
qtyCopy[j] = 0;
}
}
}
for( int k=0; k<styleQtyPairs.size(); k++ ) {
Vector tmpVec = (Vector) styleQtyPairs.elementAt( k );
for( int i=0; i<tmpVec.size(); i+=2 ) {
System.out.print( ((String) tmpVec.elementAt( i )) + "\t" );
System.out.print( ((Integer) tmpVec.elementAt( i+1 )).intValue() + "\t" );
System.out.println();
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -