⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpledispatchrule.java

📁 全球著名IT公司ILog的APS高级排产优化引擎
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.power.pipeengine.DispatchReport;

/**
 * <p>Title: PIPE Engine</p>
 * <p>Description: Global Planning Optimization Engine</p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: Paraster, Inc.</p>
 * @author not attributable
 * @version 1.0
 */

import java.util.*;
import java.io.*;
import com.power.pipeengine.Report.*;
import com.power.pipeengine.Entity.*;
import com.power.util.Message.*;
import com.power.util.urltools.*;
import com.power.pipeengine.DispatchReportMap.*;
import com.power.pipeengine.InputData.*;
import com.power.pipe.*;
import java.text.*;

public class SimpleDispatchRule {

  private static final SimpleDispatchRule INSTANCE =
      new SimpleDispatchRule();

  // Private constructor supresses
  // default public constructor
  private SimpleDispatchRule() {
  }

  public static SimpleDispatchRule getInstance() {
    return INSTANCE;
  }

  Hashtable distinctOperators = new Hashtable();
  int numOfOperatorsToBeAdded = 0;
  int cycleTime = 4;
  String planningMode = "";

  public int getAnExtraOperator() {
    numOfOperatorsToBeAdded++;
    return - numOfOperatorsToBeAdded;
  }

  public int getCycleTime() {
    return cycleTime;
  }

  public void createReport() {
    try {
      PlanInUse.getInstance().readData();
      OrderDetailsManHourMap.getInstance().readData();
      ProcessCapabilityTable.getInstance().readData();
      SewingOps.getInstance().readData();
      WIP.getInstance().readData();
      LastDayProduction.getInstance().readData();
    }
    catch (Exception e) {
      System.out.println("Reading error: " + e.getMessage());
    }

    if( PlanInUse.getInstance().getNumOfRecords() == 0 ) {
      planningMode = "NEW";
    } else if( PlanInUse.getInstance().getNumOfRecords() != 0 &&
      OrderDetailsManHourMap.getInstance().getStylesByOrderNew().size() != 0 ) {
      planningMode = "MIXED";
    } else {
      planningMode = "REPLAN";
    }

    if( !planningMode.equals( "NEW" ) ) {
      //modify current plan
System.out.println("regenerate a plan" );
      regeneratePlan();
      PlanInUse.getInstance().print();
      if( planningMode.equals( "MIXED" ) ) {
        //generate a new plan
        initStandardCurve();
        roughCapacityRqmtEstimate();
        assignLeftOverOperators();
        writeDispatchList();
      }
    } else {
      //generate a new plan
      initStandardCurve();
      roughCapacityRqmtEstimate();
      assignLeftOverOperators();
      writeDispatchList();
      computeNumOfGroups();
      System.out.println("total number of operators: " + totalOperators);
    }
  }

  public String getPlanningMode() {
    return planningMode;
  }

  double stdCurve[] = new double[60];

  private void regeneratePlan() {
    Vector wips = WIP.getInstance().getWIPs();

    for( int i=0; i<wips.size(); i++ ) {
      Object[] aWip = (Object[]) wips.elementAt( i );
      String orderID = (String) aWip[0];
      String styleID = (String) aWip[1];
      Integer procID = (Integer) aWip[2];
      Integer qty = (Integer) aWip[3];
      String key = orderID+ "&" + styleID + "&" + procID.toString();
      Plan aPlan = PlanInUse.getInstance().getPlan( key );
      if( null == aPlan ) continue;
      aPlan.replan( qty.intValue()  );
    }

    //allocate plan over employees
    PlanInUse.getInstance().genPlanByEmployee();
    schedules = PlanInUse.getInstance().getSchedules();
    writeDispatchList();
    //System.out.println( schedules.toString() );
  }

  private void initStandardCurve() {
    stdCurve[0] = 1.0;
    stdCurve[1] = 1.3;
    stdCurve[2] = 1.5;

    for( int i=3; i<14; i++ ) {
      stdCurve[i] = stdCurve[i-1] + 0.04;
    }

    for( int i=14; i<stdCurve.length; i++ ) {
      stdCurve[i] = 2.0;
    }
  }

  int grandDemand = 0;

  private void computeTotalDemand() {
    //get all big orders
    Hashtable stylesByOrder = OrderDetailsManHourMap.getInstance().getStylesByOrder();
    Enumeration orderIDs = stylesByOrder.keys();
    Date dueDate = null;

    //loop through all orders to get sum of max processing times
    while( orderIDs.hasMoreElements() ) {
      String anOrderID = (String) orderIDs.nextElement();
      Vector allStylesByOrder = OrderDetailsManHourMap.getInstance().
          getDistinctStyleByOrder(anOrderID);
      for (int i = 0; i < allStylesByOrder.size(); i++) {
        Style aStyle = (Style) allStylesByOrder.elementAt(i);
        grandDemand += aStyle.getQuantity();
      }
    }

    System.out.println("TotalDemand = " + grandDemand );
  }

  public void roughCapacityRqmtEstimate() {
    computeTotalDemand();
    OrderDetailsManHourMap.getInstance().computeStartTimeOffset();

    //get all big orders
    Hashtable stylesByOrder = OrderDetailsManHourMap.getInstance().getStylesByOrder();
    //Enumeration orderIDs = stylesByOrder.keys();
    Date dueDate = null;

    Vector orderIDs = OrderDetailsManHourMap.getInstance().getOrderIDByDueDate();

    //loop through all orders to get sum of max processing times
    //while( orderIDs.hasMoreElements() ) {
    for( int t=0; t<orderIDs.size(); t++ ) {
      //String anOrderID = (String) orderIDs.nextElement();
      String anOrderID = (String) orderIDs.elementAt( t );
      double sumMaxProcTime = 0;
      int totalNumOfPieces = 0;
      int numOfOperators = 0;
      double totalRqdMinutes = 0;
      Vector allStylesByOrder = OrderDetailsManHourMap.getInstance().
          getDistinctStyleByOrder(anOrderID);
 System.out.println( "number of distinct styles = " + allStylesByOrder.size() );
      for (int i = 0; i < allStylesByOrder.size(); i++) {
        System.out.println( "debug 2" );
        Style aStyle = (Style) allStylesByOrder.elementAt(i);
        totalNumOfPieces += aStyle.getQuantity();
        dueDate = aStyle.getDueDate();
        //get styles by orderID and styleID
        Vector styles = OrderDetailsManHourMap.getInstance().getStyles(
            anOrderID,
            aStyle.getStyleID());
        System.out.println( "debug 3 style size = " + styles.size() );

        double maxProcTime = 0;
        double operators = 0;
        int styleDmd = 0;
        double minRatio = 100000;
        for (int j = 0; j < styles.size(); j++) {
          Style tmpStyle = (Style) styles.elementAt(j);
          if( ! SewingOps.getInstance().isSewingOp( tmpStyle.getProcessID() ) ) continue;
          Vector capableOperators = ProcessCapabilityTable.getInstance().
              getCapableOperators(tmpStyle.getProcessID());

          double sumCapIdx = 0;
          for( int k=0; k<capableOperators.size(); k++ ) {
            ProcessCapability pc = (ProcessCapability) capableOperators.elementAt( k );
            sumCapIdx += pc.getCapability( tmpStyle.getProcessID() );
          }

          if (  tmpStyle.getProcessingTime() > maxProcTime ) {
            //if (  sumCapIdx / tmpStyle.getProcessingTime() < minRatio ) {
            minRatio = sumCapIdx / tmpStyle.getProcessingTime();
            operators = ProcessCapabilityTable.getInstance().
                getNumOfOperatorsForRoute( new Integer( tmpStyle.getProcessID() ) );
            styleDmd = tmpStyle.getQuantity();
            maxProcTime =  tmpStyle.getProcessingTime();
         }
        }
        System.out.println( "debug 4" );

        numOfOperators += operators;
        //sumMaxProcTime += maxProcTime;
        totalRqdMinutes += styleDmd * maxProcTime;

        Calendar due = Calendar.getInstance();
        due.setTime( dueDate );
        due.add( Calendar.DAY_OF_YEAR, - cycleTime );

        generateAScheduleForAStyle( due.getTime(),
                                    1, //numOfOperators,
                                    totalRqdMinutes,
                                    anOrderID,
                                    aStyle.getStyleID() );


        totalRqdMinutes = 0;

      }



    }



  }

  StringBuffer schedules = new StringBuffer();
  private void assignOperator( Style style, int operator, int[] qty, Date start, int numOfDaysRqd ) {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
    Calendar cal = Calendar.getInstance();
    cal.setTime( start );
    for( int i=0; i<numOfDaysRqd; i++ ) {
      schedules.append( "-1,"); //equipment
      schedules.append( style.getOrderID() + ","); //orderID
      schedules.append( style.getStyleID() + "," ); //style ID
      schedules.append( style.getProcessID() + "," ); //process ID
      schedules.append( operator + "," ); //employee ID
      schedules.append( qty[i] + ","); //qty
      schedules.append( "0," ); //finished qty
      cal.set( Calendar.HOUR_OF_DAY, 8 );
      cal.set( Calendar.MINUTE, 0 );
      cal.set( Calendar.SECOND, 0 );
      cal.add( Calendar.DAY_OF_MONTH, 1 );
      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
    }
  }

  int totalOperators = 0;
  private void computeNumOfGroups() {
    totalOperators = distinctOperators.size();
    int numOfGrps = (int) Math.floor( totalOperators / 25.0 + .5 );
    System.out.println( "Recommended number of groups = " + numOfGrps );
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -