Example #1
0
 public void resetNodesWithoutReservation() {
   for (Node n : noRes) {
     List<Integer> THS = n.getTHS();
     for (int t : THS) {
       if (t != n.getID()) {
         Node removeFrom = nodes.get(t);
         removeFrom.removeNeighbour(n.getID());
       }
     }
     n.clearReservation();
   }
 }
Example #2
0
  public void reserveTimeSlots() {
    List<Integer> hasSlot = new ArrayList<Integer>();
    while (hasSlot.size() < this.numNodes) {
      int nodeToAttempt = r.nextInt(this.numNodes);
      while (hasSlot.contains(nodeToAttempt)) {
        nodeToAttempt = r.nextInt(this.numNodes);
      }

      Node toAttemptReservation = nodes.get(nodeToAttempt);
      if (toAttemptReservation.getReservation() == -1) // Node doesn't have a slot yet
      {
        boolean canAdd = true;
        int slotToReserve = r.nextInt(this.numSlots);
        List<Integer> THSToCheck = toAttemptReservation.getTHS();

        for (int n : THSToCheck) {
          Node toCheck = nodes.get(n);
          ReservationBean[] toCheckSlots = toCheck.getTimeSlots();
          if (toCheckSlots[slotToReserve].getHolder() != -1) {
            canAdd = false;
            break;
          }
        }
        if (canAdd) {
          toAttemptReservation.setReservation(slotToReserve);

          for (int n : THSToCheck) {
            Node toUpdate = nodes.get(n);
            // set reservation in all nodes in THS
            toUpdate.setTimeSlotReservation(
                slotToReserve,
                toAttemptReservation.getID(),
                toAttemptReservation.getRemainingReservationDuration());
            // Set initial FI in all nodes in THS
            toUpdate.setFI(
                slotToReserve,
                toAttemptReservation.getID(),
                toAttemptReservation.getRemainingReservationDuration());
          }
          hasSlot.add(toAttemptReservation.getID());
        }
      }
    }
  }
Example #3
0
  /**
   * Clears node reservations until b% of nodes do not have reservations
   *
   * @param b
   */
  public void setInitialNodesWithoutReservation(double b) {
    int numToConvert = (int) Math.ceil(b * this.numNodes);
    int converted = 0;
    while (converted < numToConvert) {
      int nodeToChange = r.nextInt(this.numNodes);
      Node n = nodes.get(nodeToChange);
      if (n.getReservation() != -1) {
        noRes.add(n);
        // -1 is the default value if have no reservation
        List<Integer> THS = n.getTHS();
        for (int t : THS) {
          Node removeFrom = nodes.get(t);
          removeFrom.removeNeighbour(nodeToChange);
        }

        // System.out.println(converted);
        n.clearReservation();
        converted++;
      }
    }
  }