排产系统

源代码在线查看: resourceusage.java

软件大小: 4136 K
上传用户: zhou28
关键词:
下载地址: 免注册下载 普通下载 VIP

相关代码

				package com.power.pipeengine.Report;
				
				import java.util.*;
				import java.io.*;
				import java.text.*;
				
				import com.power.pipeengine.Variable.*;
				import com.power.pipeengine.Constraint.*;
				import com.power.pipeengine.InputData.*;
				import com.power.pipeengine.LPModel.*;
				import com.power.pipeengine.Entity.*;
				import com.power.pipe.*;
				import com.power.pipeengine.*;
				import com.power.util.Message.*;
				import com.power.pipeengine.DispatchReportMap.*;
				
				public class ResourceUsage
				    extends Report {
				  private static final ResourceUsage INSTANCE =
				      new ResourceUsage();
				
				  // Private constructor supresses
				  // default public constructor
				  private ResourceUsage() {
				    _fileName = "ResourceUsage";
				    //initFileWriter();
				  }
				
				  public static ResourceUsage getInstance() {
				    return INSTANCE;
				  }
				
				  private StringBuffer content = new StringBuffer();
				  static ResourceBundle res = ResourceBundle.getBundle("com.power.pipeengine.Res",
				                                                        EngineConfig.getInstance().getLocale() );
				
				  public void createReport() throws IOException {
				    DataModel dataModel = DataModel.getInstance();
				    Vector buckets = dataModel.getCalendar().getBuckets();
				    Resources rscs = dataModel.getResources();
				    RscSlackVariable rscSlackVar = RscSlackVariable.getInstance();
				    Solution sol = Solution.getInstance();
				
				    Enumeration allRscs = rscs.getResources().elements();
				    String separator = GlobalConfig.getInstance().getSeparator();
				
				    try {
				      EquipmentMap.getInstance().readData();
				    }
				    catch (Exception e) {
				    }
				
				
				    while (allRscs.hasMoreElements()) {
				      Resource rsc = (Resource) allRscs.nextElement();
				      if (dataModel.getResourceUses().getResourceUse(rsc.getResourceID()) == null) {
				        continue;
				      }
				      Facility f = rsc.getFacility();
				
				      for (int i = 0; i < buckets.size(); i++) {
				        Bucket b = (Bucket) buckets.elementAt(i);
				        String rscVar = rscSlackVar.getVariable(rsc, f, b);
				        double slackValue = sol.getValue(rscVar);
				        double rscAvail = rsc.getResourceHours(b) *
				            f.getNumWorkingDaysForBucket(b.getBucketID());
				        int hoursUsed = (int) ( (double) ( (rscAvail - slackValue) * 100.0));
				        hoursUsed = (int) ( ( (double) hoursUsed) / 100.0);
				
				        double ratio = (double) (int) ( (hoursUsed / rscAvail) * 10000.0) / 100;
				
				        if (hoursUsed == 0.0)
				          continue;
				
				        if( ratio >= 95 ) {
				          reportBottleNeck( rsc.getResourceID(), ratio, b.getBucketID() );
				        }
				
				        String lineOut = rsc.getResourceID() + separator +
				            f.getFacilityID() + separator +
				            b.getBucketID() + separator +
				            b.getFormatedDate() + separator +
				            hoursUsed + separator +
				            ratio + "\n";
				        content.append(lineOut);
				      }
				    }
				
				    //_myFileWriter.close();
				    super.flush(content.toString());
				    content = null;
				    System.gc();
				  }
				
				  SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
				  private void reportBottleNeck( String rscID, double loadRatio, int bucketID ) {
				    String equipmentName = EquipmentMap.getInstance().getEquipmentName( rscID );
				    Date aDate = PeriodDateMap.getInstance().getDateBucketBelongsTo( bucketID );
				    if( null == equipmentName ) {
				      equipmentName = rscID;
				    }
				
				    MessageArea.getInstance().addMessage( "\t**" + res.getString( "BottleNeckRsc" ) + ": " +
				                                          equipmentName + ", " + loadRatio +
				                                          ", " + sdf.format( aDate ) + "\n" );
				  }
				
				  public void reset() {
				    content = new StringBuffer();
				  }
				
				}			

相关资源