private int getOccupationTime() { double sample = realDistribution.sample(); if (sample > longestParkingTime) { sample = longestParkingTime; } if (sample < 0) { sample = 0; } return (int) sample + parkingSlotProvider.getObject(parkingSlot).getDistance() * 2; }
@Override public int decide(ParkingSlot parkingSlot, ParkingSlot peek) { boolean decision = heuristic.decide(parkingSlot, peek); if (decision) { LOG.debug( "Car {} chooses {} with distance {}", id, parkingSlot.getId(), parkingSlot.getDistance()); putData = true; this.parkingSlot = parkingSlot.getId(); parkingSlotProvider.getObject(this.parkingSlot).occupy(this); parkingTime = getOccupationTime(); return parkingTime; } return -1; }
@Override public void update(Observable o, Object arg) { parkingTime--; if (parkingTime == 0 && parkingSlot != null) { LOG.debug("Car {} leaves {}", id, parkingSlot); parkingSlotProvider.getObject(parkingSlot).clear(); parkingSlot = null; o.deleteObserver(this); putData = false; parkingTime = -1; heuristic = heuristic.copy(); setChanged(); notifyObservers(CarState.Free); } if ((o instanceof Street) && (arg instanceof Long)) { if (putData) { Integer distance = parkingSlot == null ? -1 : parkingSlotProvider.getObject(parkingSlot).getDistance(); // Write the data set to the database. -1 since the decision is made in the previous click simulationDataCollector.putCarData(id, distance, (Long) arg - 1); putData = false; } } }