-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simpler disutility function & JIBE disutility model
- Loading branch information
1 parent
959432d
commit bd9ed0a
Showing
19 changed files
with
536 additions
and
87 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
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,70 @@ | ||
package demand; | ||
|
||
import demand.volumes.HourlyVolumeEventHandler; | ||
import io.ioUtils; | ||
import network.CreateMatsimNetworkRoad; | ||
import network.NetworkUtils2; | ||
import org.apache.log4j.Logger; | ||
import org.matsim.api.core.v01.network.Link; | ||
import org.matsim.api.core.v01.network.Network; | ||
import org.matsim.core.api.experimental.events.EventsManager; | ||
import org.matsim.core.events.EventsManagerImpl; | ||
import org.matsim.core.events.EventsUtils; | ||
import resources.Properties; | ||
import resources.Resources; | ||
|
||
import java.io.File; | ||
import java.io.PrintWriter; | ||
|
||
public class WriteHourlyVolumes { | ||
|
||
private final static Logger log = Logger.getLogger(CreateMatsimNetworkRoad.class); | ||
|
||
public static void main(String[] args) { | ||
|
||
if(args.length != 2) { | ||
throw new RuntimeException("Program requires 2 arguments: \n" + | ||
"(0) Properties file \n" + | ||
"(1) Output csv file"); | ||
} | ||
|
||
Resources.initializeResources(args[0]); | ||
String outputCsv = args[1]; | ||
|
||
Network network = NetworkUtils2.readFullNetwork(); | ||
|
||
log.info("Estimating volumes from events..."); | ||
int scaleFactor = (int) (1 / Resources.instance.getDouble(Properties.MATSIM_TFGM_OUTPUT_SCALE_FACTOR)); | ||
log.info("Multiplying all volumes from events file by a factor of " + scaleFactor); | ||
|
||
EventsManager eventsManager = new EventsManagerImpl(); | ||
HourlyVolumeEventHandler hourlyVolumeEventHandler = new HourlyVolumeEventHandler(Resources.instance.getString(Properties.MATSIM_TFGM_OUTPUT_VEHICLES)); | ||
eventsManager.addHandler(hourlyVolumeEventHandler); | ||
EventsUtils.readEvents(eventsManager,Resources.instance.getString(Properties.MATSIM_TFGM_OUTPUT_EVENTS)); | ||
|
||
PrintWriter out = ioUtils.openFileForSequentialWriting(new File(outputCsv),false); | ||
assert out != null; | ||
|
||
log.info("Writing csv..."); | ||
// Write header | ||
out.println("linkId,edgeId,osmId,hour,cars,trucks"); | ||
|
||
// Write table | ||
for(Link link : network.getLinks().values()) { | ||
String linkId = link.getId().toString(); | ||
int edgeId = (int) link.getAttributes().getAttribute("edgeID"); | ||
int osmId = (int) link.getAttributes().getAttribute("osmID"); | ||
int[] carVolumes = hourlyVolumeEventHandler.getCarVolumes().getOrDefault(link.getId(),new int[24]); | ||
int[] truckVolumes = hourlyVolumeEventHandler.getTruckVolumes().getOrDefault(link.getId(),new int[24]); | ||
|
||
for(int i = 0 ; i < 24 ; i++) { | ||
out.println(linkId + "," + edgeId + "," + osmId + "," + i + "," + | ||
(carVolumes[i] * scaleFactor) + "," + (truckVolumes[i] * scaleFactor)); | ||
} | ||
} | ||
|
||
// Close | ||
out.close(); | ||
|
||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
src/main/java/demand/volumes/HourlyVolumeEventHandler.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,54 @@ | ||
package demand.volumes; | ||
|
||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.IdMap; | ||
import org.matsim.api.core.v01.events.LinkEnterEvent; | ||
import org.matsim.api.core.v01.events.handler.LinkEnterEventHandler; | ||
import org.matsim.api.core.v01.network.Link; | ||
import org.matsim.vehicles.MatsimVehicleReader; | ||
import org.matsim.vehicles.VehicleUtils; | ||
import org.matsim.vehicles.Vehicles; | ||
|
||
public class HourlyVolumeEventHandler implements LinkEnterEventHandler { | ||
|
||
Vehicles vehicles = VehicleUtils.createVehiclesContainer(); | ||
|
||
public HourlyVolumeEventHandler(String vehiclesFile) { | ||
MatsimVehicleReader.VehicleReader reader = new MatsimVehicleReader.VehicleReader(vehicles); | ||
reader.readFile(vehiclesFile); | ||
} | ||
|
||
private final IdMap<Link, int[]> carVolumes = new IdMap<>(Link.class); | ||
private final IdMap<Link, int[]> truckVolumes = new IdMap<>(Link.class); | ||
|
||
@Override | ||
public void handleEvent(LinkEnterEvent event) { | ||
Id<Link> linkId = event.getLinkId(); | ||
|
||
String vehicleType = vehicles.getVehicles().get(event.getVehicleId()).getType().getId().toString(); | ||
|
||
int hour = ((int) (event.getTime() / 3600.)) % 24; | ||
|
||
String mode = event.getAttributes().get("networkMode"); | ||
|
||
if(vehicleType.equals("car")) { | ||
int[] linkVolumes = carVolumes.getOrDefault(linkId,new int[24]); | ||
linkVolumes[hour]++; | ||
carVolumes.put(linkId,linkVolumes); | ||
} else if (vehicleType.equals("truck")) { | ||
int[] linkVolumes = truckVolumes.getOrDefault(linkId,new int[24]); | ||
linkVolumes[hour]++; | ||
truckVolumes.put(linkId, linkVolumes); | ||
} else { | ||
throw new RuntimeException("Unrecognised vehicle type " + mode); | ||
} | ||
} | ||
|
||
public IdMap<Link, int[]> getCarVolumes() { | ||
return carVolumes; | ||
} | ||
|
||
public IdMap<Link, int[]> getTruckVolumes() { | ||
return truckVolumes; | ||
} | ||
} |
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
Oops, something went wrong.