-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding code to output the sharing demand * add service name to the output file * update version
- Loading branch information
Showing
7 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
76 changes: 76 additions & 0 deletions
76
src/main/java/org/matsim/contrib/sharing/analysis/SharingTeleportedControlerListener.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,76 @@ | ||
package org.matsim.contrib.sharing.analysis; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
import org.matsim.contrib.sharing.service.RentalInfo; | ||
import org.matsim.contrib.sharing.service.SharingTeleportedRentalsHandler; | ||
import org.matsim.core.api.experimental.events.EventsManager; | ||
import org.matsim.core.controler.events.IterationEndsEvent; | ||
import org.matsim.core.controler.events.StartupEvent; | ||
import org.matsim.core.controler.listener.IterationEndsListener; | ||
import org.matsim.core.controler.listener.StartupListener; | ||
import org.matsim.core.utils.io.IOUtils; | ||
|
||
import com.google.inject.Inject; | ||
|
||
public class SharingTeleportedControlerListener implements StartupListener, IterationEndsListener { | ||
|
||
private final SharingTeleportedRentalsHandler sharingHandler; | ||
private final EventsManager eventsManager; | ||
private String serviceid; | ||
|
||
@Inject | ||
public SharingTeleportedControlerListener(SharingTeleportedRentalsHandler sharingHandler, | ||
EventsManager eventsManager, String serviceid) { | ||
this.sharingHandler = sharingHandler; | ||
this.eventsManager = eventsManager; | ||
this.serviceid = serviceid; | ||
|
||
} | ||
|
||
@Override | ||
public void notifyStartup(StartupEvent event) { | ||
|
||
this.eventsManager.addHandler(this.sharingHandler); | ||
|
||
} | ||
|
||
public void notifyIterationEnds(IterationEndsEvent event) { | ||
|
||
if (event.getIteration() > 0) { | ||
// write all data gathered in csv files | ||
String path = event.getServices().getControlerIO().getIterationPath(event.getIteration()) | ||
+ "/sharingrentals_" + serviceid + ".csv"; | ||
|
||
Set<RentalInfo> rentals = this.sharingHandler.getRentals(); | ||
try { | ||
// Because we want to write to CSV we would use the generic bufferred writer and | ||
// specify the csv file name | ||
BufferedWriter writer = IOUtils.getBufferedWriter(path); | ||
writer.write( | ||
"personid;starttime;endtime;distancedriven;pickupstationid;pickupstationlinkid;dropoffstationid;dropoffstationlinkid;" | ||
+ "vehicleid;serviceid\n"); | ||
for (RentalInfo rental : rentals) { | ||
|
||
writer.write(String.join(";", rental.personId.toString(), Double.toString(rental.startTime), | ||
Double.toString(rental.endTime), Double.toString(rental.distance), rental.pickupStationId, | ||
rental.pickupLinkId.toString(), rental.dropoffStationId, rental.dropoffLinkId.toString(), | ||
rental.vehicleId, rental.serviceId.toString())); | ||
writer.newLine(); | ||
} | ||
// flush() tells the Writer to output the stream | ||
writer.flush(); | ||
|
||
// it is good practice to close the stream when no more output is expected | ||
writer.close(); | ||
|
||
} catch (IOException e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/org/matsim/contrib/sharing/service/RentalInfo.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,35 @@ | ||
package org.matsim.contrib.sharing.service; | ||
|
||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.network.Link; | ||
import org.matsim.api.core.v01.population.Person; | ||
|
||
public class RentalInfo { | ||
|
||
public double startTime; | ||
public double endTime; | ||
public double distance; | ||
public Id<SharingService> serviceId; | ||
public Id<Person> personId; | ||
public Id<Link> pickupLinkId; | ||
public Id<Link> dropoffLinkId; | ||
|
||
public String vehicleId; | ||
public String pickupStationId; | ||
public String dropoffStationId; | ||
|
||
public RentalInfo(double starttime, double endtime, Id<SharingService> serviceId, Id<Person> personId, Id<Link> pickupLinkId, | ||
Id<Link> dropoffLinkId, String vehicleId, String pickupstationId, | ||
String dropoffstationId, double distance) { | ||
this.startTime = starttime; | ||
this.endTime = endtime; | ||
this.distance = distance; | ||
this.serviceId = serviceId; | ||
this.personId = personId; | ||
this.pickupLinkId = pickupLinkId; | ||
this.dropoffLinkId = dropoffLinkId; | ||
this.vehicleId = vehicleId; | ||
this.pickupStationId = pickupstationId; | ||
this.dropoffStationId = dropoffstationId; | ||
} | ||
} |
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