0

I want to know the time inside the initRoadPDP method (inherited from the Depot class). Is this possible without inserting the Simulator object as a field on my class?

class MyDepot extends Depot {

  @Override
  public void initRoadPDP(RoadModel pRoadModel, PDPModel pPdpModel) {
    // how to know the current time?
  }
}
OrangeDog
  • 36,653
  • 12
  • 122
  • 207
entropitor
  • 11
  • 3
  • Could you please add more code – Stornu2 Apr 27 '16 at 10:12
  • Are you familiar with RinSim? Because this is a question specific for RinSim users. (Questions about [RinSim](https://github.com/rinde/rinsim) should be asked on stackoverflow, according to their github). I believe this question is plenty clear if you know RinSim. (I only tagged it with java because I had to tag it...) – entropitor Apr 27 '16 at 12:40

1 Answers1

0

The initRoadPDP(..) method is called during the initialisation phase of MyDepot. This happens at the time the Depot is added to the simulator, which, for depots, is typically before simulation time has started.

The standard way to get notified of time progress is to implement the TickListener interface. Besides keeping track of time, this interface allows you to use the received TimeLapse object to perform actions that cost time. However, since the first tick received will always be after any call to initRoadPDP this method may not be suitable for this case.

In any case, the code for using the TickListener looks like this:

class MyDepot extends Depot implements TickListener {
    public MyDepot(Point position) {
        super(position);
    }

    @Override
    public void initRoadPDP(RoadModel pRoadModel, PDPModel pPdpModel) {
        // how to know the current time?
    }

    @Override
    public void tick(TimeLapse timeLapse) {
        timeLapse.getTime(); // current time
    }

    @Override
    public void afterTick(TimeLapse timeLapse) {}
}
rinde
  • 1,181
  • 1
  • 8
  • 20