示例#1
0
  /*compute the initial Time outs for all equipments */
  private void computeInitialTimes() {
    System.out.println("t0 is" + t0);
    double timeDiff = 0;

    /*Times for available equipment will depend on the type and position in queue as it's FIFO */
    generateRandomOrderTimes();

    /*for equipment on rent, it's simply at the end of the rental period */
    for (Equipment e : rentEquipment) {
      e.timeIn = System.currentTimeMillis() - t0;
      timeDiff = nextRandomTime(RENTALFREQUENCY[e.type - 1]);
      e.timeOut = System.currentTimeMillis() + timeDiff - t0;
      System.out.println("I am in state " + e.state + " and order " + rentEquipment.indexOf(e));
      System.out.println(
          "My time in is "
              + e.timeIn
              + " And my time out is "
              + e.timeOut
              + " and the difference between the 2 is "
              + (e.timeOut - e.timeIn));
      /*System.out.println("and nextRandomTime returns" + nextRandomTime(e.timeIn,RENTALFREQUENCY[e.type-1]) +" for type "+e.type+" for RentalFrequency "+RENTALFREQUENCY[e.type-1]);
      System.out.println("For equipment in state "+e.state+" and order "+rentEquipment.indexOf(e)+" : inter-arrival is "+(e.timeOut-e.timeIn)); */
    }

    /*for equipment in the shop, it's simply at the end of the rental period */
    for (Equipment e : shopEquipment) {
      e.timeIn = System.currentTimeMillis() - t0;
      timeDiff = nextRandomTime(SHOPFREQUENCY[e.type - 1]);
      e.timeOut = System.currentTimeMillis() + timeDiff - t0;
      System.out.println("I am in state " + e.state + " and order " + shopEquipment.indexOf(e));
      System.out.println(
          "My time in is "
              + e.timeIn
              + " And my time out is "
              + e.timeOut
              + " and the difference between the 2 is "
              + (e.timeOut - e.timeIn));
      /*System.out.println("For equipment in state "+e.state+" and order "+shopEquipment.indexOf(e)+" : inter-arrival is "+(e.timeOut-e.timeIn)); */
    }
  }
示例#2
0
  /*Scans all equipments and identifies the ones that need to be moved */
  private void scanEquipments() {
    double timeDiff = 0;
    int orderToMove = -1;
    double[] arrivalFrequencies = {ARRIVAL1, ARRIVAL2, ARRIVAL3};

    /*In the available state, the scan should not happen on the equipment as it's external customer demand and we should record a "lost sale" when there is no equipment*/
    for (int counter = 0; counter < TYPES; counter++) {
      // System.out.println("I am computing for arrival frequency "+arrivalFrequencies[counter]+ "
      // and the corresponding time is "+orderTimes.get(counter));
      if (orderTimes.get(counter) < System.currentTimeMillis() - t0) {
        System.out.println("Time is " + System.currentTimeMillis());
        orderTimes.set(
            counter, System.currentTimeMillis() + nextRandomTime(arrivalFrequencies[counter]) - t0);
        System.out.println(
            "I have just computed a new exit time for state 1 and type "
                + counter
                + " = "
                + orderTimes.get(counter));
        orderToMove =
            checkOrder(
                1,
                counter + 1); // checks the order of the type being moved in the available arraylist
        if (orderToMove >= 0) {
          Equipment e = availEquipment.get(orderToMove);
          timeDiff =
              nextRandomTime(
                  RENTALFREQUENCY[
                      e.type
                          - 1]); // Equipment is moving to rent - so its next timeOut should be that
          // of rent
          e.timeOut = System.currentTimeMillis() + timeDiff - t0;
          moveEquip(1, orderToMove);
          sales = sales + RATES[counter];
          salesLabel.setLabel("SALES : $" + sales);
        } else {
          System.out.println("You just lost a sale");
          int ls = lostSales.get(counter);
          lostSales.set(counter, ls + 1);
          switch (counter) {
            case 0:
              lostSalesLabel1.setLabel("Lost Sales HR = " + ls + 1);
              break;
            case 1:
              lostSalesLabel2.setLabel("Lost Sales MR = " + ls + 1);
              break;
            case 2:
              lostSalesLabel3.setLabel("Lost Sales LR = " + ls + 1);
              break;
          }
        }
      }
    }

    for (Equipment e : rentEquipment) {
      orderToMove = scan(e);
      if (orderToMove >= 0) {
        /*Entering this loop means there is an equipment to move */
        timeDiff =
            nextRandomTime(
                SHOPFREQUENCY[
                    e.type - 1]); // Equipment is moving to shop so its next timeOut is that of shop
        // System.out.println("Rental frequency is "+RENTALFREQUENCY[e.type-1]+" and timeDiff is
        // "+timeDiff);
        e.timeOut = System.currentTimeMillis() + timeDiff - t0;
        System.out.println("the new timeOut is " + e.timeOut);
        break;
      }
    }
    if (orderToMove >= 0) {
      moveEquip(2, orderToMove);
      // System.out.println("I have just moved equipment from state 2 and of order "+orderToMove);
      // placeEquipments();
    }

    for (Equipment e : shopEquipment) {
      orderToMove = scan(e);
      if (orderToMove >= 0) {
        /*Entering this loop means there is an equipment to move */
        e.timeOut = 0; // Doesn't matter what the time-out is as it's not governed by the equipment
        break;
      }
    }
    if (orderToMove >= 0) {
      moveEquip(3, orderToMove);
      // placeEquipments();
    }
  }