Skip to content

Commit 158ef8d

Browse files
Merge pull request #77 from Janekdererste/clean_up_network
Clean up network
2 parents a70b1c3 + 3a2cbed commit 158ef8d

File tree

10 files changed

+247
-113
lines changed

10 files changed

+247
-113
lines changed

src/simulation/controller.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::simulation::io::proto_events::ProtoEventsWriter;
66
use crate::simulation::io::vehicle_definitions::{IOVehicleDefinitions, VehicleDefinitions};
77
use crate::simulation::messaging::events::EventsPublisher;
88
use crate::simulation::messaging::message_broker::MpiMessageBroker;
9-
use crate::simulation::messaging::messages::proto::Vehicle;
109
use crate::simulation::messaging::travel_time_collector::TravelTimeCollector;
1110
use crate::simulation::network::network::Network;
1211
use crate::simulation::partition_info::PartitionInfo;
@@ -38,7 +37,7 @@ pub fn run(world: SystemCommunicator, config: Config) {
3837
let io_population = IOPopulation::from_file(config.population_file.as_ref());
3938
let id_mappings = MatsimIdMappings::from_io(&io_network, &io_population);
4039
let partition_info = PartitionInfo::from_io_network(&io_network, &id_mappings, size as usize);
41-
let mut network: Network<Vehicle> = Network::from_io(
40+
let mut network: Network = Network::from_io(
4241
&io_network,
4342
size as usize,
4443
config.sample_size,

src/simulation/io/network.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::simulation::id_mapping::MatsimIdMapping;
22
use crate::simulation::io::matsim_id::MatsimId;
33
use crate::simulation::io::xml_reader;
44
use crate::simulation::network::network::Network;
5-
use crate::simulation::network::node::NodeVehicle;
65
use flate2::Compression;
76
use log::info;
87
use quick_xml::se::to_writer;
@@ -154,9 +153,9 @@ impl IONetwork {
154153
info!("IONetwork: Finished writing network.");
155154
}
156155

157-
pub fn clone_with_internal_ids<V: NodeVehicle>(
156+
pub fn clone_with_internal_ids(
158157
&self,
159-
network: &Network<V>,
158+
network: &Network,
160159
link_id_mapping: &MatsimIdMapping,
161160
node_id_mapping: &MatsimIdMapping,
162161
) -> IONetwork {

src/simulation/messaging/messages.rs

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
use std::cmp::Ordering;
2+
use std::collections::HashMap;
3+
use std::io::Cursor;
4+
5+
use prost::Message;
6+
17
use crate::simulation::config::RoutingMode;
28
use crate::simulation::id_mapping::{MatsimIdMapping, MatsimIdMappings};
39
use crate::simulation::io::matsim_id::MatsimId;
@@ -11,10 +17,6 @@ use crate::simulation::messaging::messages::proto::{
1117
};
1218
use crate::simulation::network::node::NodeVehicle;
1319
use crate::simulation::time_queue::EndTime;
14-
use prost::Message;
15-
use std::cmp::Ordering;
16-
use std::collections::HashMap;
17-
use std::io::Cursor;
1820

1921
// Include the `messages` module, which is generated from messages.proto.
2022
pub mod proto {
@@ -181,6 +183,14 @@ impl Agent {
181183
}
182184
}
183185

186+
pub fn new(id: u64, plan: Plan) -> Self {
187+
Agent {
188+
id,
189+
curr_plan_elem: 0,
190+
plan: Some(plan),
191+
}
192+
}
193+
184194
pub fn id(&self) -> usize {
185195
self.id as usize
186196
}
@@ -368,7 +378,7 @@ impl EndTime for Agent {
368378
impl Plan {
369379
pub const DEFAULT_ROUTING_MODE: &'static str = "car";
370380

371-
fn new() -> Plan {
381+
pub fn new() -> Plan {
372382
Plan {
373383
acts: Vec::new(),
374384
legs: Vec::new(),
@@ -492,6 +502,14 @@ impl Plan {
492502
result
493503
}
494504

505+
pub fn add_leg(&mut self, leg: Leg) {
506+
self.legs.push(leg);
507+
}
508+
509+
pub fn add_act(&mut self, activity: Activity) {
510+
self.acts.push(activity);
511+
}
512+
495513
fn get_plan_type(io_plan: &IOPlan) -> PlanType {
496514
if let IOPlanElement::Activity(_) = io_plan.elements.get(1).unwrap() {
497515
return PlanType::ActivitiesOnly;
@@ -584,6 +602,26 @@ impl Activity {
584602
}
585603
}
586604

605+
pub fn new(
606+
x: f32,
607+
y: f32,
608+
act_type: String,
609+
link_id: u64,
610+
start_time: Option<u32>,
611+
end_time: Option<u32>,
612+
max_dur: Option<u32>,
613+
) -> Self {
614+
Activity {
615+
x,
616+
y,
617+
act_type,
618+
link_id,
619+
start_time,
620+
end_time,
621+
max_dur,
622+
}
623+
}
624+
587625
fn cmp_end_time(&self, now: u32) -> u32 {
588626
if let Some(end_time) = self.end_time {
589627
end_time
@@ -611,6 +649,15 @@ impl Leg {
611649
}
612650
}
613651

652+
pub fn new(route: Route, mode: &str, trav_time: Option<u32>, dep_time: Option<u32>) -> Self {
653+
Self {
654+
route: Some(route),
655+
mode: String::from(mode),
656+
trav_time,
657+
dep_time,
658+
}
659+
}
660+
614661
fn only_with_mode(mode: &str) -> Self {
615662
Self {
616663
mode: mode.to_string(),
@@ -686,6 +733,13 @@ impl NetworkRoute {
686733
vehicle_id: *veh_id as u64,
687734
}
688735
}
736+
737+
pub fn new(vehicle_id: u64, link_ids: Vec<u64>) -> Self {
738+
Self {
739+
vehicle_id,
740+
route: link_ids,
741+
}
742+
}
689743
}
690744

691745
fn parse_time_opt(value: &Option<String>) -> Option<u32> {

0 commit comments

Comments
 (0)