Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Vehicles in Simulation #99

Merged
merged 21 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a5e477b
Remove vehicle definitions from code as first step towards vehicle types
Sep 11, 2023
cccfcc8
replicate crazy vehicles file structure for serde, remove loading of …
Sep 12, 2023
de942b5
* add default implementations for vehicles, so that creation in garag…
Sep 14, 2023
620b0f8
place vehicles into garage when reading in scenario
Sep 14, 2023
d5d982a
remove vehicle ids from garage
Sep 14, 2023
abecd70
move attributes relevant for qsim into vehicle to make calculation of…
Sep 14, 2023
b843e09
add speed from vehicle again
Sep 14, 2023
e62fb51
Remove vehicle definitions from code as first step towards vehicle types
Sep 11, 2023
e9aa74c
replicate crazy vehicles file structure for serde, remove loading of …
Sep 12, 2023
c8ba918
* add default implementations for vehicles, so that creation in garag…
Sep 14, 2023
c85fb94
place vehicles into garage when reading in scenario
Sep 14, 2023
b045e8a
remove vehicle ids from garage
Sep 14, 2023
6ea3069
move attributes relevant for qsim into vehicle to make calculation of…
Sep 14, 2023
2a4dc87
add speed from vehicle again
Sep 14, 2023
06f3365
Merge remote-tracking branch 'origin/#91-replace-mode-strings' into #…
Sep 22, 2023
88a01fd
Add Level of detail proerty to vehicle types. This is represented in …
Oct 4, 2023
573f021
WIP: Add vehicles and vehicle ids to population creation.
Oct 4, 2023
4d51212
Add test for population with vehicles creation
Oct 5, 2023
0d75615
WIP: put new vehicle definition into simulation as well
Oct 5, 2023
7882c35
put new vehicle definition into simulation, project compiles all (uni…
Oct 6, 2023
b4d70cd
use veh type id when fetching the vehicle type. Prdouce output networ…
Oct 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
682 changes: 341 additions & 341 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions assets/3-links/3-agent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@
<population desc="single agent on three links network">
<person id="100">
<plan score="92.61490939414003" selected="yes">
<activity type="home_28800.0" link="link1" x="0" y="0.0" end_time="9:00:00"/>
<activity type="home" link="link1" x="0" y="0.0" end_time="9:00:00"/>
<leg mode="car" dep_time="9:00:00" trav_time="">
<route type="links" start_link="link1" end_link="link3" trav_time=""
distance="1200" vehicleRefId="100_car">link1 link2 link3
</route>
</leg>
<activity type="errands_2400.0" link="link3" x="1100.0" y="0.0" start_time="15:51:00" />
<activity type="errands" link="link3" x="1100.0" y="0.0" start_time="15:51:00"/>
</plan>
</person>
<person id="200">
<plan score="92.61490939414003" selected="yes">
<activity type="home_28800.0" link="link1" x="0" y="0.0" end_time="9:10:00"/>
<activity type="home" link="link1" x="0" y="0.0" end_time="9:10:00"/>
<leg mode="bike" dep_time="9:00:00" trav_time="">
<route type="links" start_link="link1" end_link="link3" trav_time=""
distance="1200" vehicleRefId="200_car">link1 link2 link3
distance="1200" vehicleRefId="200_bike">link1 link2 link3
</route>
</leg>
<activity type="errands_2400.0" link="link3" x="1100.0" y="0.0" start_time="15:51:00" />
<activity type="errands" link="link3" x="1100.0" y="0.0" start_time="15:51:00"/>
</plan>
</person>
<person id="300">
<plan score="92.61490939414003" selected="yes">
<activity type="home_28800.0" link="link1" x="0" y="0.0" end_time="9:20:00"/>
<activity type="home" link="link1" x="0" y="0.0" end_time="9:20:00"/>
<leg mode="car" dep_time="9:00:00" trav_time="">
<route type="links" start_link="link1" end_link="link3" trav_time=""
distance="1200" vehicleRefId="300_car">link1 link2 link3
</route>
</leg>
<activity type="errands_2400.0" link="link3" x="1100.0" y="0.0" start_time="15:51:00" />
<activity type="errands" link="link3" x="1100.0" y="0.0" start_time="15:51:00"/>
</plan>
</person>
</population>
9 changes: 0 additions & 9 deletions assets/3-links/vehicle_definitions.xml

This file was deleted.

38 changes: 38 additions & 0 deletions assets/3-links/vehicles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<vehicleDefinitions xmlns="http://www.matsim.org/files/dtd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.matsim.org/files/dtd http://www.matsim.org/files/dtd/vehicleDefinitions_v1.0.xsd">
<vehicleType id="car">
<attributes>
</attributes>
<description>abc</description>
<length meter="9.5"/>
<width meter="3.0"/>
<maximumVelocity meterPerSecond="42.0"/>
<passengerCarEquivalents pce="2.0"/>
<networkMode networkMode="car"/>
<flowEfficiencyFactor factor="1.5"/>
</vehicleType>
<vehicleType id="bike">
<attributes>
</attributes>
<description>This is a bike</description>
<length meter="2.0"/>
<width meter="1.0"/>
<maximumVelocity meterPerSecond="4.0"/>
<passengerCarEquivalents pce="0.25"/>
<networkMode networkMode="bike"/>
<flowEfficiencyFactor factor="1.5"/>
</vehicleType>
<vehicleType id="walk">
<attributes>
<attribute name="lod" class="java.lang.String">teleported</attribute>
</attributes>
<description>This is a pair of shoes</description>
<length meter="0.5"/>
<width meter="1.0"/>
<maximumVelocity meterPerSecond="0.85"/>
<passengerCarEquivalents pce="0.1"/>
<networkMode networkMode="walk"/>
<flowEfficiencyFactor factor="10.0"/>
</vehicleType>
</vehicleDefinitions>
142 changes: 77 additions & 65 deletions assets/equil/equil-1-plan.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,87 @@

<population>

<attributes>
<attribute name="coordinateReferenceSystem" class="java.lang.String">Atlantis</attribute>
</attributes>
<attributes>
<attribute name="coordinateReferenceSystem" class="java.lang.String">Atlantis</attribute>
</attributes>


<!-- ====================================================================== -->
<!-- ====================================================================== -->

<person id="1">
<attributes>
<attribute name="vehicles" class="org.matsim.vehicles.PersonVehicles">{"car":"1"}</attribute>
</attributes>
<plan score="53.10347962692449" selected="yes">
<activity type="h" link="1" x="-25000.0" y="0.0" end_time="06:00:00" >
</activity>
<leg mode="car">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="1" end_link="20" trav_time="undefined" distance="25000.0" vehicleRefId="1">1 6 15 20</route>
</leg>
<activity type="w" link="20" x="10000.0" y="0.0" max_dur="00:10:00" >
</activity>
<leg mode="car">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="20" end_link="20" trav_time="undefined" distance="0.0" vehicleRefId="1">20</route>
</leg>
<activity type="w" link="20" x="10000.0" y="0.0" max_dur="03:30:00" >
</activity>
<leg mode="car">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="20" end_link="1" trav_time="undefined" distance="65000.0" vehicleRefId="1">20 21 22 23 1</route>
</leg>
<activity type="h" link="1" x="-25000.0" y="0.0" >
</activity>
</plan>
<person id="1">
<attributes>
<attribute name="vehicles" class="org.matsim.vehicles.PersonVehicles">{"car":"1"}</attribute>
</attributes>
<plan score="53.10347962692449" selected="yes">
<activity type="h" link="1" x="-25000.0" y="0.0" end_time="06:00:00">
</activity>
<leg mode="car">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="1" end_link="20" trav_time="undefined" distance="25000.0"
vehicleRefId="1_car">1 6 15 20
</route>
</leg>
<activity type="w" link="20" x="10000.0" y="0.0" max_dur="00:10:00">
</activity>
<leg mode="car">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="20" end_link="20" trav_time="undefined" distance="0.0"
vehicleRefId="1_car">20
</route>
</leg>
<activity type="w" link="20" x="10000.0" y="0.0" max_dur="03:30:00">
</activity>
<leg mode="car">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="20" end_link="1" trav_time="undefined" distance="65000.0"
vehicleRefId="1_car">20 21 22 23 1
</route>
</leg>
<activity type="h" link="1" x="-25000.0" y="0.0">
</activity>
</plan>

<plan score="52.9312834015057" selected="no">
<activity type="h" link="1" x="-25000.0" y="0.0" end_time="06:00:00" >
</activity>
<leg mode="car" dep_time="06:00:00" trav_time="00:08:59">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="1" end_link="20" trav_time="00:08:59" distance="25000.0" vehicleRefId="1">1 8 17 20</route>
</leg>
<activity type="w" link="20" x="10000.0" y="0.0" max_dur="00:10:00" >
</activity>
<leg mode="car" dep_time="06:18:59" trav_time="00:00:00">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="20" end_link="20" trav_time="00:00:00" distance="0.0" vehicleRefId="1">20</route>
</leg>
<activity type="w" link="20" x="10000.0" y="0.0" max_dur="03:30:00" >
</activity>
<leg mode="car" dep_time="09:48:59" trav_time="00:32:59">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="20" end_link="1" trav_time="00:32:59" distance="65000.0" vehicleRefId="1">20 21 22 23 1</route>
</leg>
<activity type="h" link="1" x="-25000.0" y="0.0" >
</activity>
</plan>
<plan score="52.9312834015057" selected="no">
<activity type="h" link="1" x="-25000.0" y="0.0" end_time="06:00:00">
</activity>
<leg mode="car" dep_time="06:00:00" trav_time="00:08:59">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="1" end_link="20" trav_time="00:08:59" distance="25000.0"
vehicleRefId="1_car">1 8 17 20
</route>
</leg>
<activity type="w" link="20" x="10000.0" y="0.0" max_dur="00:10:00">
</activity>
<leg mode="car" dep_time="06:18:59" trav_time="00:00:00">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="20" end_link="20" trav_time="00:00:00" distance="0.0"
vehicleRefId="1_car">20
</route>
</leg>
<activity type="w" link="20" x="10000.0" y="0.0" max_dur="03:30:00">
</activity>
<leg mode="car" dep_time="09:48:59" trav_time="00:32:59">
<attributes>
<attribute name="routingMode" class="java.lang.String">car</attribute>
</attributes>
<route type="links" start_link="20" end_link="1" trav_time="00:32:59" distance="65000.0"
vehicleRefId="1_car">20 21 22 23 1
</route>
</leg>
<activity type="h" link="1" x="-25000.0" y="0.0">
</activity>
</plan>

</person>
</person>

</population>
Binary file modified assets/equil/equil-plans.xml.gz
Binary file not shown.
27 changes: 27 additions & 0 deletions assets/equil/equil-vehicles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<vehicleDefinitions xmlns="http://www.matsim.org/files/dtd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.matsim.org/files/dtd http://www.matsim.org/files/dtd/vehicleDefinitions_v1.0.xsd">
<vehicleType id="car">
<attributes>
</attributes>
<description>abc</description>
<length meter="9.5"/>
<width meter="3.0"/>
<maximumVelocity meterPerSecond="42.0"/>
<passengerCarEquivalents pce="2.0"/>
<networkMode networkMode="car"/>
<flowEfficiencyFactor factor="1.5"/>
</vehicleType>
<vehicleType id="walk">
<attributes>
<attribute name="lod" class="java.lang.String">teleported</attribute>
</attributes>
<description>This is a pair of shoes</description>
<length meter="0.5"/>
<width meter="1.0"/>
<maximumVelocity meterPerSecond="0.85"/>
<passengerCarEquivalents pce="0.1"/>
<networkMode networkMode="walk"/>
<flowEfficiencyFactor factor="10.0"/>
</vehicleType>
</vehicleDefinitions>
10 changes: 10 additions & 0 deletions src/simulation/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct Config {
#[arg(long)]
pub population_file: String,
#[arg(long)]
pub vehicles_file: String,
#[arg(long)]
pub vehicle_definitions_file: Option<String>,
#[arg(long, default_value = "./")]
pub output_dir: String,
Expand All @@ -35,6 +37,7 @@ pub struct ConfigBuilder {
num_parts: usize,
network_file: String,
population_file: String,
vehicles_file: String,
vehicle_definitions_file: Option<String>,
output_dir: String,
events_mode: String,
Expand All @@ -46,6 +49,7 @@ impl ConfigBuilder {
ConfigBuilder {
network_file: String::from(""),
population_file: String::from(""),
vehicles_file: String::from(""),
vehicle_definitions_file: None,
output_dir: String::from("./"),
events_mode: String::from("file"),
Expand Down Expand Up @@ -81,6 +85,11 @@ impl ConfigBuilder {
self
}

pub fn vehicles_file(mut self, file: String) -> Self {
self.vehicles_file = file;
self
}

pub fn output_dir(mut self, dir: String) -> Self {
self.output_dir = dir;
self
Expand Down Expand Up @@ -111,6 +120,7 @@ impl ConfigBuilder {
num_parts: self.num_parts,
network_file: self.network_file,
population_file: self.population_file,
vehicles_file: self.vehicles_file,
vehicle_definitions_file: self.vehicle_definitions_file,
output_dir: self.output_dir,
events_mode: self.events_mode,
Expand Down
22 changes: 11 additions & 11 deletions src/simulation/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use tracing::info;

use crate::simulation::config::Config;
use crate::simulation::io::proto_events::ProtoEventsWriter;
use crate::simulation::io::vehicle_definitions::{IOVehicleDefinitions, VehicleDefinitions};
use crate::simulation::messaging::events::EventsPublisher;
use crate::simulation::messaging::message_broker::MpiMessageBroker;
use crate::simulation::network::sim_network::SimNetworkPartition;
use crate::simulation::population::population::Population;
use crate::simulation::simulation::Simulation;
use crate::simulation::vehicles::garage::Garage;

pub fn run(world: SystemCommunicator, config: Config) {
let rank = world.rank();
Expand All @@ -25,18 +25,25 @@ pub fn run(world: SystemCommunicator, config: Config) {
let output_path = PathBuf::from(&config.output_dir);
fs::create_dir_all(&output_path).expect("Failed to create output path");

let mut garage = Garage::from_file(config.vehicles_file.as_ref());

let network = crate::simulation::network::global_network::Network::from_file(
config.network_file.as_ref(),
config.num_parts,
&mut garage,
);

// write network with new ids to output but only once.
if rank == 0 {
network.to_file(&output_path.join("output_network.xml.gz"));
}

let population =
Population::from_file(config.population_file.as_ref(), &network, rank as usize);
let population = Population::from_file(
config.population_file.as_ref(),
&network,
&mut garage,
rank as usize,
);
let network_partition = SimNetworkPartition::from_network(&network, rank as usize);
info!(
"Partition #{rank} network has: {} nodes and {} links. Population has {} agents",
Expand All @@ -55,20 +62,13 @@ pub fn run(world: SystemCommunicator, config: Config) {
//events.add_subscriber(travel_time_collector);
//events.add_subscriber(Box::new(EventsLogger {}));

let mut vehicle_definitions: Option<VehicleDefinitions> = None;
if let Some(vehicle_definitions_file_path) = &config.vehicle_definitions_file {
let io_vehicle_definitions =
IOVehicleDefinitions::from_file(vehicle_definitions_file_path.as_ref());
vehicle_definitions = Some(VehicleDefinitions::from_io(io_vehicle_definitions));
}

let mut simulation = Simulation::new(
&config,
network_partition,
garage,
population,
message_broker,
events,
vehicle_definitions,
);

let start = Instant::now();
Expand Down
Loading