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

📄 simpledispatchrule.java

📁 简介: 今天为网友提供的是JAVA源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  private void assignOperator( Style style,
                               Vector procCap,
                               int[] qty,
                               Date start,
                               int numOfDaysRqd,
                               int numOfStdOperators,
                               boolean overtime,
                               double[] curveForThisOrder ) {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
    Calendar cal = Calendar.getInstance();
    cal.setTime( start );
    totalOperators += procCap.size();
    for( int i=0; i<numOfDaysRqd; i++ ) {
      int cumAllocatedQty = 0;
      for( int j=0; j<procCap.size(); j++ ) {
        ProcessCapability pc = (ProcessCapability) procCap.elementAt( j );
        pc.setAssigned();
        schedules.append("-1,"); //equipment
        schedules.append(style.getOrderID() + ","); //orderID
        schedules.append(style.getStyleID() + ","); //style ID
        schedules.append(style.getProcessID() + ","); //process ID
        schedules.append(pc.getEmployeeID() + ","); //employee ID
         if (j < procCap.size() - 1) {
          int allocatedQty = (int) Math.floor(qty[i] *
                                              pc.getCapability(style.getProcessID()) /
                                              numOfStdOperators);
          schedules.append(allocatedQty + ","); //qty
          cumAllocatedQty += allocatedQty;
        } else {
          schedules.append( (qty[i] - cumAllocatedQty) + ","); //qty
        }
        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);
    }
  }

  private String urlAddr = GlobalConfig.getInstance().getLPServerURL() +
    "com.power.pipeengine.LP_ReadWriteFile";

  private void writeDispatchList() {
    URLFileWriter.getInstance().write(urlAddr,
                                      GlobalConfig.getInstance().
                                      getDirectOutputDir() + "dispatchlist.csv",
                                      "WriteModel",
                                      schedules.toString());

  }

  public int compareDates( Calendar from, Calendar to ) {
    Calendar tmp = (Calendar) from.clone();
    int diff = 0;
    for( int i=0; i<365; i++) {
      if( tmp.after( to ) ) break;
      tmp.add(Calendar.DAY_OF_YEAR, 1);
      diff++;
    }

    return diff;
  }

  private void generateAScheduleForAStyle( Date dueDate,
                                           int numOfOperators,
                                           double totalRqdMinutes,
                                           String anOrderID,
                                           String aStyleID ) {
    //get total minutes required for key processes

    //assume an 8-hour day, see if we can finish by the due date
    //get number of working days before due date

    Calendar today = Calendar.getInstance();
    today.add( Calendar.DAY_OF_MONTH, 1);
    Date startDate = today.getTime();
    System.out.println("due date = " + dueDate.toString());
    System.out.println("start date = " + startDate.toString());
    Calendar due = Calendar.getInstance();
    due.setTime( dueDate );
    int numOfDaysBeforeDue = compareDates( today, due ) + 1;

    System.out.println("numOfDaysBeforeDue = " + numOfDaysBeforeDue);

    double totalAvailMinutes = 0;

    for (int k = 0; k < numOfDaysBeforeDue; k++) {
      totalAvailMinutes += 8 * 60 * stdCurve[k] * numOfOperators;
    }

    double tmp = totalRqdMinutes;
    System.out.println("totalRqdMinutes = " + totalRqdMinutes);
    int numOfDaysRqd = 0;
    for (int k = 0; k < stdCurve.length; k++) {
      tmp -= 8 * 60 * stdCurve[k] * numOfOperators;
      if (tmp <= 0) {
        numOfDaysRqd = k + 1;
        break;
      }
    }
    if( numOfDaysRqd == 0 ) {
      numOfDaysRqd = stdCurve.length;
    }

    System.out.println("debug 6 numOfDaysRqd = " + numOfDaysRqd);

    //totalAvailMinutes *= numOfOperators;
    double speedUpCoeff = 0.0;
    System.out.println("totalAvailMin = " + totalAvailMinutes +
                       "\tnum of operators = " + numOfOperators);
    //capacity test
    if (totalAvailMinutes >= totalRqdMinutes) {
      System.out.println("sufficient capacity");
    }
    else {
      speedUpCoeff = (totalRqdMinutes - totalAvailMinutes) / totalAvailMinutes;
      System.out.println("speed up %=" + speedUpCoeff);
    }
    System.out.println("debug 7");

    double[] curveForThisOrder = new double[numOfDaysBeforeDue];

    for (int k = 0; k < numOfDaysBeforeDue; k++) {
      curveForThisOrder[k] = stdCurve[k] * (1 + speedUpCoeff);
    }

    numOfDaysRqd = Math.min( numOfDaysRqd, numOfDaysBeforeDue );

    //generate schedule by style
    Vector styles = OrderDetailsManHourMap.getInstance().getStyles(
        anOrderID,
        aStyleID);

    double maxProcTime = 0;
      int operators = 0;
      int demand = 0;
      double minRatio = 10000;
      int keyProcessID = 0;
      String styleID = null;
      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();
          maxProcTime = tmpStyle.getProcessingTime();
          operators = ProcessCapabilityTable.getInstance().
              getNumOfOperatorsForRoute(new Integer(tmpStyle.getProcessID()));
          demand = tmpStyle.getQuantity();
          keyProcessID = tmpStyle.getProcessID();
          styleID = tmpStyle.getStyleID();
        }
      }
      System.out.println("styleID = " + styleID + "key process = " + keyProcessID );

      int[] qty = new int[numOfDaysRqd];

      int totalQty = 0;
      int m;
      boolean finished = false;

      //get denominator
      double denominator = 0;
      for (m = 0; m < numOfDaysRqd ; m++) {
        denominator += curveForThisOrder[m];
      }

      int dmd = demand;

      for (m = 0; m < numOfDaysRqd - 1; m++) {
        qty[m] = (int) Math.ceil( demand * curveForThisOrder[m] / denominator );
        if( dmd - qty[m]  < 0 ) {
          qty[m] += dmd - qty[m];
          dmd = 0;
          break;
        }
        dmd -= qty[m];
        totalQty += qty[m];
      }
      if( dmd > 0 ) {
        qty[m] = demand - totalQty;
      }

      //print out planned quantities
      System.out.println();
      for( int k=0; k<numOfDaysRqd; k++ ) {
        System.out.print( curveForThisOrder[k] + ", " );
      }
      System.out.println();
      for( int k=0; k<numOfDaysRqd; k++ ) {
        System.out.print( qty[k] + ", " );
      }
      System.out.println();

      //for each day and then loop thru all styles
      for (int j = 0; j < styles.size(); j++) {
        Style tmpStyle = (Style) styles.elementAt(j);

        tmpStyle.setAssignedQty(qty);
        tmpStyle.setSpeedCurve(curveForThisOrder);
        tmpStyle.setNumOfDaysRqd(numOfDaysRqd);
        tmpStyle.computeNumOfOperators();
        tmpStyle.setStartDate(startDate);
        totalOperators += tmpStyle.getNumOfOperators();

        Vector capableOperators = ProcessCapabilityTable.getInstance().
            getCapableOperators(tmpStyle.getProcessID());
        double sumCapIdx = 0;
        Vector pcs = new Vector();
        double totalProcCap = 0;
        for (int k = 0; k < capableOperators.size(); k++) {
          ProcessCapability pc = (ProcessCapability) capableOperators.elementAt(
              k);
            //if (pc.isAssigned())
              //continue;
            totalProcCap ++;
        }

        int baseCount = OrderDetailsManHourMap.getInstance().getNumOfStylesByProcID( tmpStyle.getProcessID() );
        double base = Math.floor( totalProcCap / baseCount );
        double remainder = totalProcCap - baseCount*base;
        int numAssigned = 0;
        for (int k = 0; k < capableOperators.size(); k++) {
          if( SewingOps.getInstance().isSewingOp( tmpStyle.getProcessID() ) &&
              numAssigned == base ) {
            break;
          }
          ProcessCapability pc = (ProcessCapability) capableOperators.elementAt(
              k);
          if (pc.isAssigned())
            continue;
          if (pc.getAssignedPID() != 0 &&
              pc.getAssignedPID() != tmpStyle.getProcessID()) {
            continue;
          }
          //sumCapIdx += pc.getCapability(tmpStyle.getProcessID()) *
              //pc.getAvailPercentage();
          sumCapIdx += pc.getCapability(tmpStyle.getProcessID()) *
              pc.getAvailPercentage() *
              ProcessRequirement.getInstance().getAvgRqmtByOperator( new Integer( tmpStyle.getProcessID()) );
          pcs.add(pc);
          pc.setAssignedPID(tmpStyle.getProcessID());
          ProcessRequirement.getInstance().updateLastAssigned( new Integer( tmpStyle.getProcessID() ),
              pc );
          //if (sumCapIdx >= tmpStyle.getNumOfOperators()) {
          if (sumCapIdx >= tmpStyle.getRequirement() ) {
            if( SewingOps.getInstance().isSewingOp( tmpStyle.getProcessID() ) ) {
              tmpStyle.addOperator(pc, new Double(pc.getAvailPercentage()));
              pc.setAssignedPercentage(1.0);
              numAssigned++;
             break;
            }
            /*double stdRemained = pc.getCapability(tmpStyle.getProcessID()) *
                pc.getAvailPercentage();
            double stdUsedThisTime = stdRemained -
                (sumCapIdx - tmpStyle.getNumOfOperators());
            stdRemained = stdRemained - stdUsedThisTime;

            double percentRemained = stdRemained /
                pc.getCapability(tmpStyle.getProcessID());*/

            double stdRemained = pc.getCapability(tmpStyle.getProcessID()) *
                pc.getAvailPercentage() *

⌨️ 快捷键说明

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