This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add two EventsHandler to build connections between driver - vehicle -…
… carrier
- Loading branch information
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/main/java/org/matsim/freight/logistics/analysis/Driver2VehicleEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
*********************************************************************** * | ||
* project: org.matsim.* | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* copyright : (C) 2024 by the members listed in the COPYING, * | ||
* LICENSE and WARRANTY file. * | ||
* email : info at matsim dot org * | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* See also COPYING, LICENSE and WARRANTY file * | ||
* * | ||
* *********************************************************************** | ||
*/ | ||
|
||
package org.matsim.freight.logistics.analysis; | ||
|
||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.events.VehicleEntersTrafficEvent; | ||
import org.matsim.api.core.v01.events.VehicleLeavesTrafficEvent; | ||
import org.matsim.api.core.v01.events.handler.VehicleEntersTrafficEventHandler; | ||
import org.matsim.api.core.v01.events.handler.VehicleLeavesTrafficEventHandler; | ||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.vehicles.Vehicle; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class Driver2VehicleEventHandler implements VehicleEntersTrafficEventHandler, VehicleLeavesTrafficEventHandler { | ||
|
||
private final Map<Id<Person>, Id<Vehicle>> driversVehicles = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public void reset(int iteration) { | ||
driversVehicles.clear(); | ||
} | ||
|
||
@Override | ||
public void handleEvent(VehicleEntersTrafficEvent event) { | ||
driversVehicles.put(event.getPersonId(), event.getVehicleId()); | ||
} | ||
|
||
@Override | ||
public void handleEvent(VehicleLeavesTrafficEvent event) { | ||
driversVehicles.remove(event.getPersonId()); | ||
} | ||
|
||
/** | ||
* @param personId the unique driver identifier. | ||
* @return vehicle id of the driver's vehicle | ||
*/ | ||
public Id<Vehicle> getVehicleOfDriver(Id<Person> personId) { | ||
return driversVehicles.get(personId); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/org/matsim/freight/logistics/analysis/Vehicle2CarrierEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
*********************************************************************** * | ||
* project: org.matsim.* | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* copyright : (C) 2024 by the members listed in the COPYING, * | ||
* LICENSE and WARRANTY file. * | ||
* email : info at matsim dot org * | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* See also COPYING, LICENSE and WARRANTY file * | ||
* * | ||
* *********************************************************************** | ||
*/ | ||
|
||
package org.matsim.freight.logistics.analysis; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.events.VehicleEntersTrafficEvent; | ||
import org.matsim.api.core.v01.events.VehicleLeavesTrafficEvent; | ||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.freight.carriers.Carrier; | ||
import org.matsim.freight.carriers.events.CarrierTourEndEvent; | ||
import org.matsim.freight.carriers.events.CarrierTourStartEvent; | ||
import org.matsim.freight.carriers.events.eventhandler.CarrierTourEndEventHandler; | ||
import org.matsim.freight.carriers.events.eventhandler.CarrierTourStartEventHandler; | ||
import org.matsim.vehicles.Vehicle; | ||
|
||
public class Vehicle2CarrierEventHandler implements CarrierTourStartEventHandler, CarrierTourEndEventHandler { | ||
|
||
private final Map<Id<Vehicle>, Id<Carrier>> vehicle2carrier = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public void reset(int iteration) { | ||
vehicle2carrier.clear(); | ||
} | ||
|
||
@Override | ||
public void handleEvent(CarrierTourStartEvent event) { | ||
vehicle2carrier.put(event.getVehicleId(), event.getCarrierId()); | ||
} | ||
|
||
@Override | ||
public void handleEvent(CarrierTourEndEvent event) { | ||
vehicle2carrier.remove(event.getVehicleId()); | ||
} | ||
|
||
/** | ||
* @param vehicleId the unique vehicle Id | ||
* @return id of the vehicle's carrier | ||
*/ | ||
public Id<Carrier> getCarrierOfVehicle(Id<Vehicle> vehicleId) { | ||
return vehicle2carrier.get(vehicleId); | ||
} | ||
|
||
} |