public void run() {
   Foodistan fdistan = Foodistan.getfoodistan();
   while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
     for (int l = 0; l < fdistan.getChefs().size(); l++) {
       Chef c = fdistan.chefs.get(l);
       if (c.getcStatus() == chefStatus.FREE) {
         fdistan.getChefs().get(l).cookItem(ItemType.BURGER);
       }
     }
   }
 }
 public void run() {
   Foodistan fdistan = Foodistan.getfoodistan();
   while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
     for (int n = 0; n < fdistan.getFoodies().size(); n++) {
       Foodie f = fdistan.foodies.get(n);
       if ((f.getfStatus() == foodieStatus.EATING)
           && (f.getEatStartTime() + f.getEatTime() < System.currentTimeMillis())) {
         f.setfStatus(foodieStatus.HUNGRY);
       }
     }
   }
 }
  public void run() {

    Foodistan fdistan = Foodistan.getfoodistan();
    while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
      for (int k = 0; k < fdistan.getChefs().size(); k++) {
        Chef c = fdistan.chefs.get(k);

        // decreasing speed
        if (fdistan.getInv().items.size() > fdistan.getBurgerNeeded()) {

          long changeUpTime = c.getBackUpCookTime() * 2;
          if (changeUpTime <= 3600000) {
            fdistan.chefs.get(k).setBackUpCookTime(changeUpTime);
          } else {

            fdistan.chefs.get(k).setBackUpCookTime(fdistan.chefs.get(k).getDefaultCookTime());
          }
        }

        // increasing speed
        if (fdistan.getInv().items.size() < fdistan.getBurgerNeeded()) {
          long changeDownTime = c.getBackUpCookTime() / 2;

          if (changeDownTime > 1) {

            fdistan.chefs.get(k).setBackUpCookTime(changeDownTime);
          }
        }
      }
    }
  }
  public void run() {

    Foodistan fdistan = Foodistan.getfoodistan();
    while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {

      for (int k = 0; k < fdistan.getChefs().size(); k++) {
        Chef c = fdistan.chefs.get(k);
        if (c.getcStatus() == chefStatus.SPEEDUPDATE) {

          fdistan.chefs.get(k).setCurrentCookTime(fdistan.chefs.get(k).getBackUpCookTime());
          fdistan.chefs.get(k).setcStatus(chefStatus.FREE);
        }
      }
    }
  }
 public void run() {
   Foodistan fdistan = Foodistan.getfoodistan();
   while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
     for (int m = 0; m < fdistan.getFoodies().size(); m++) {
       Foodie f = fdistan.foodies.get(m);
       if (f.getfStatus() == foodieStatus.HUNGRY) {
         Item item =
             f.requestOrder(fdistan.getSalesCounter(), f.getItmTyp(), 1, f.getFoodieDiscount());
         if (item == null) {
           fdistan.foodies.get(m).setWaitStartTime(System.currentTimeMillis());
           fdistan.foodies.get(m).setfStatus(foodieStatus.WAITING);
           Foodistan.getfoodistan().foodiesOnHold.add(f);
         } else f.consumeItem(item);
       }
     }
   }
 }
 public void run() {
   Foodistan fdistan = Foodistan.getfoodistan();
   while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
     for (int k = 0; k < fdistan.getChefs().size(); k++) {
       Chef c = fdistan.chefs.get(k);
       if (((c.getcStatus() == chefStatus.BUSY)
           && (c.getCookStartTime() + (c.getCurrentCookTime())) < System.currentTimeMillis())) {
         Item itm = new Item(ItemType.BURGER);
         fdistan.getMg().refillInventory(itm);
         fdistan.chefs.get(k).setcStatus(chefStatus.SPEEDUPDATE);
         fdistan
             .chefs
             .get(k)
             .setCurrentCookTime(fdistan.chefs.get(k).getCurrentCookTime() * fdistan.getSpeedUp());
       }
     }
   }
 }
  public void run() {
    Foodistan fdistan = Foodistan.getfoodistan();

    while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
      // System.out.println(fdistan.getInv().items.isEmpty());

      long waitTime = 180000L;
      if (!fdistan.getInv().items.isEmpty()) {

        if (System.currentTimeMillis()
            > (180000L + fdistan.getInv().items.peek().getItemStartTime())) {
          fdistan.getInv().items.poll();
          fdistan.setBurgersWasted(fdistan.getBurgersWasted() + 1);
          fdistan.setAvgItemLifeTime(fdistan.getAvgItemLifeTime() + ItemType.BURGER.getLifeTime());
        }
        waitTime =
            (fdistan.getInv().items.peek().getItemStartTime() + 180000L)
                - System.currentTimeMillis();
      }
      System.out.println("Stale burgers it ");
      if (waitTime < 0) continue;
      try {

        Thread.currentThread().sleep(waitTime);
      } catch (Exception e) {
        e.printStackTrace();
      }

      /*
      while(!(fdistan.getInv().items.isEmpty())){
          System.out.println(fdistan.getInv().items.isEmpty());
      	System.out.println("System time update " + System.currentTimeMillis());
      	System.out.println("System time update " + fdistan.getInv().items.peek().getItemStartTime());
      	System.out.println("System time update " + (System.currentTimeMillis() - fdistan.getInv().items.peek().getItemStartTime()));

      	//System.out.println("Outside it ");
      	if (System.currentTimeMillis() > (180000L + fdistan.getInv().items.peek().getItemStartTime())){
      		fdistan.getInv().items.poll();
      		System.out.println("inside it ");
      		//jjSystem.exit(1);

      		fdistan.setBurgersWasted(fdistan.getBurgersWasted()+1);
      		fdistan.setAvgItemLifeTime(fdistan.getAvgItemLifeTime()+ItemType.BURGER.getLifeTime());
      	}else
      		System.out.println("outside it ");
      }  */
    }
  }
  public void run() {
    while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {

      // System.out.println("Thread E");
      // Thread 5: To display the output
      /*  Output Specifications
      •	For the time being, you need to use Logging Messages as your output
      •	Following stats must be clearly indicated at every step of your algorithm
      •	Total Number of Orders Received (Maximize)
      •	Total Number of Orders Delivered (Maximize)
      •	Total Numbers of Burgers Wasted (Minimize)
      •	Average Waiting Time / Order Delivered (Minimize)
      •	Maximum Waiting Time (Minimize)
      •	Average life of Burgers / Order Delivered (Minimize)
      •	I will assign weights to above parameters and share a definitive formula to decide the best solution*/

      System.out.println(
          "Orders Received -------> " + Foodistan.getfoodistan().getOrdersReceived());
      System.out.println(
          "Orders Delivered ------> " + Foodistan.getfoodistan().getOrdersDelivered());
      System.out.println("Burgers Wasted --------> " + Foodistan.getfoodistan().getBurgersWasted());
      System.out.println("Foodies Died ----------> " + Foodistan.getfoodistan().getDeathPenalty());
      System.out.println("Speed Factor ----------> " + Foodistan.getfoodistan().getSpeedFactor());
      System.out.println(
          "Orders on Hold -------->" + Foodistan.getfoodistan().getOdrsOnHold().size());
      System.out.println(
          "Foodies on Hold ------->" + Foodistan.getfoodistan().getFoodiesOnHold().size());
      System.out.println(
          "Current Inventory ----->" + Foodistan.getfoodistan().getInv().countItem());
      // System.out.println("Burgers Needed -------->" +
      // Foodistan.getfoodistan().getBurgerNeeded());
      System.out.println(
          "Current Discount ------>" + Foodistan.getfoodistan().getMg().calculateDiscount());
      if (Foodistan.getfoodistan().getDeathPenalty() > 1) {
        System.out.println("Max. Wait Time(ms) ----> 600000");
      } else {
        System.out.println(
            "Max. Wait Time(ms) ----> " + Foodistan.getfoodistan().getMaxWaitingTime());
      }
      try {
        System.out.println(
            "Avg. Waiting Time(ms) -> "
                + (Foodistan.getfoodistan().getAvgWaitingTime()
                    / (Foodistan.getfoodistan().getOrdersReceived())));
      } catch (ArithmeticException a) {
        System.out.println("Avg. Waiting Time(ms) -> 0");
      }
      try {
        System.out.println(
            "Avg. Burger Life(ms) --> "
                + (Foodistan.getfoodistan().getAvgItemLifeTime()
                    / (Foodistan.getfoodistan().getOrdersDelivered()
                        + Foodistan.getfoodistan().getBurgersWasted())));
      } catch (ArithmeticException a) {
        System.out.println("Avg. Burger Life(ms) --> 0");
      }
      System.out.println("                          ");
      // System.out.println(Foodistan.getfoodistan().getMg().calculateDiscount() + " Discount");
    }
  }
  public void run() {
    Foodistan fdistan = Foodistan.getfoodistan();
    while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
      for (int z = 0; z < fdistan.getFoodies().size(); z++) {
        Foodie f = fdistan.foodies.get(z);
        if (f.getfStatus() == foodieStatus.WAITING) {
          /*	if((f.getMaxWaitTime() + f.getWaitStartTime()) - System.currentTimeMillis() < 10000l)
          {
          	if(fdistan.getMg().hasInventory(fdistan.getInv(), 1)){
          		fdistan.setAvgWaitingTime(fdistan.getAvgWaitingTime()+(System.currentTimeMillis()-f.getWaitStartTime()));
          		fdistan.getFoodies().get(z).consumeItem(fdistan.getMg().getItem(fdistan.getInv(), 1));
          		fdistan.getOdrsOnHold().remove(0).setOrdrStatus(orderStatus.COMPLETE);
          		fdistan.getFoodiesOnHold().remove(0);
          		fdistan.setBurgerNeeded(fdistan.getBurgerNeeded()-1);
          		fdistan.setOrdersDelivered(Foodistan.getfoodistan().getOrdersDelivered()+1);

          	}

          }*/
          if ((f.getMaxWaitTime() + f.getWaitStartTime()) < System.currentTimeMillis()) {
            fdistan.foodies.get(z).setfStatus(foodieStatus.DEAD);
            fdistan.getFoodiesOnHold().remove(0);
            fdistan.getOdrsOnHold().remove(0);
            fdistan.setBurgerNeeded(fdistan.getBurgerNeeded() - 1);
            fdistan.setAvgWaitingTime(fdistan.getAvgWaitingTime() + (f.getMaxWaitTime()));
            fdistan.setDeathPenalty(fdistan.getDeathPenalty() + 1);
          }
        }
      }
    }
  }
Esempio n. 10
0
  public void run() {
    Foodistan fdistan = Foodistan.getfoodistan();
    long waitTime = 0l;
    while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
      for (int x = 0; x < fdistan.getFoodies().size(); x++) {
        Foodie f = fdistan.getFoodies().get(x);
        if (f.getfStatus() == foodieStatus.WAITING) {

          if ((fdistan.getMg().hasInventory(Foodistan.getfoodistan().getInv(), 1) == false)
              || (fdistan.getMg().calculateDiscount() < f.getFoodieDiscount())) {
          } else {
            waitTime = System.currentTimeMillis() - f.getWaitStartTime();
            if (waitTime > fdistan.getMaxWaitingTime()) fdistan.setMaxWaitingTime(waitTime);
            fdistan.setAvgWaitingTime(fdistan.getAvgWaitingTime() + waitTime);
            Item itm = fdistan.getMg().getItem(fdistan.getInv());
            fdistan.getFoodies().get(x).consumeItem(itm);
            fdistan.setAvgItemLifeTime(
                fdistan.getAvgItemLifeTime()
                    + (System.currentTimeMillis() - itm.getItemStartTime()));
            fdistan.getOdrsOnHold().remove(0).setOrdrStatus(orderStatus.COMPLETE);
            fdistan.getFoodiesOnHold().remove(0);
            fdistan.setBurgerNeeded(fdistan.getBurgerNeeded() - 1);
            fdistan.setOrdersDelivered(Foodistan.getfoodistan().getOrdersDelivered() + 1);
          }
        }
      }
    }
  }
Esempio n. 11
0
  /** @param args */
  public static void main(String[] args) {
    // to parse the input with validation checks
    Foodistan fdistan = getfoodistan();
    // java fs {F1, F2, F3 ...} {C1, C2, C3 .....} n
    // ;
    int curl = 0;
    int curlC = 0;
    String delimiter = ",";

    try {
      for (String s : args) {
        String[] temp = s.split(delimiter);

        if (temp[0].equalsIgnoreCase("{")) {
          curl++;
        }
        if (temp[0].equalsIgnoreCase("}")) {
          curlC++;
        }
        if (((!temp[0].equalsIgnoreCase("{"))) && curl == 1 && curlC != 1) {
          // System.out.println(s);
          if (Integer.parseInt(temp[0]) < 0 || Integer.parseInt(temp[0]) > 100) {
            System.out.println("Invalid Foodie Discount" + temp[0]);
            System.exit(1);
          }
          Foodie fd1 = new Foodie(Integer.parseInt(temp[0]), ItemType.BURGER, 300000l);
          fdistan.foodies.add(fd1);
        }
        if (((!temp[0].equalsIgnoreCase("}")) && (!s.equalsIgnoreCase("{")))
            && curl == 2
            && curlC != 2) {
          // System.out.println(s+"hello");

          if (Long.parseLong(temp[0]) <= 0) {
            System.out.println("Invalid chef cooking speed " + temp[0]);
            System.exit(1);
          }

          long cookTime = 3600000l / Long.parseLong(temp[0]);
          Chef cf = new Chef(ItemType.BURGER, cookTime);
          fdistan.chefs.add(cf);
        }
        if (curlC == 2 && !temp[0].equalsIgnoreCase("}")) {
          if (temp[0] == "" || Long.parseLong(temp[0]) <= 0) {
            System.out.println("Please enter correct time");
            System.exit(1);
          }
          Foodistan.getfoodistan()
              .setFoodistanEndTime(Long.parseLong(temp[0]) * 60000l + System.currentTimeMillis());
          // System.out.println(s+"heelo");

        }
      }
    } catch (NumberFormatException e) {
      System.out.println(" please check the imput format");
      System.exit(1);
    }

    if (fdistan.getFoodies().size() == 0 || fdistan.getChefs().size() == 0) {
      System.out.println(" Either chef or foodies not present");
      System.exit(1);
    }

    SalesCounter s1 = new SalesCounter(1);
    fdistan.salesCounters.add(s1);
    int j;
    for (j = 0; j < fdistan.getChefs().size(); j++) {
      fdistan.chefs.get(j).cookItem(ItemType.BURGER);
    }
    int f = 0;

    for (f = 0; f < fdistan.getFoodies().size(); f++) {
      fdistan.setAvgDiscount(
          fdistan.getAvgDiscount() + fdistan.getFoodies().get(f).getFoodieDiscount());
    }
    fdistan.setAvgDiscount((int) (fdistan.getAvgDiscount() / fdistan.getFoodies().size()));

    if (fdistan.getAvgDiscount() > 50 && fdistan.getAvgDiscount() < 70) {
      fdistan.setSpeedFactor(75);

    } else if (fdistan.getAvgDiscount() > 70) {

      fdistan.setSpeedFactor(95);
    }

    ThreadA ta = new ThreadA();
    ThreadB tb = new ThreadB();
    ThreadC tc = new ThreadC();
    ThreadD td = new ThreadD();
    ThreadE te = new ThreadE();
    ThreadF tf = new ThreadF();
    ThreadG tg = new ThreadG();
    ThreadN tn = new ThreadN();
    ThreadO to = new ThreadO();
    ThreadK tk = new ThreadK();
    // Thread 1 - to order
    to.start();
    ta.start();
    tb.start();
    tc.start();
    td.start();
    te.start();
    tf.start();
    tg.start();
    tn.start();
    tk.start();
  }