Skip to content

Commit f5e757b

Browse files
committed
remove generic parameter in link
WIP: Tests are not fixed yet
1 parent a70b1c3 commit f5e757b

File tree

9 files changed

+55
-57
lines changed

9 files changed

+55
-57
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/network/link.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
use crate::simulation::io::network::IOLink;
22
use crate::simulation::io::vehicle_definitions::VehicleDefinitions;
3+
use crate::simulation::messaging::messages::proto::Vehicle;
34
use crate::simulation::network::flow_cap::Flowcap;
45
use crate::simulation::network::node::NodeVehicle;
56
use log::warn;
67
use std::collections::VecDeque;
78
use std::fmt::Debug;
89

910
#[derive(Debug, Clone)]
10-
pub enum Link<V: Debug> {
11-
LocalLink(LocalLink<V>),
12-
SplitInLink(SplitInLink<V>),
11+
pub enum Link {
12+
LocalLink(LocalLink),
13+
SplitInLink(SplitInLink),
1314
SplitOutLink(SplitOutLink),
1415
}
1516

16-
impl<V: NodeVehicle> Link<V> {
17+
impl Link {
1718
pub fn from_to_id(&self) -> (usize, usize) {
1819
(self.from_id(), self.to_id())
1920
}
@@ -40,9 +41,9 @@ impl<V: NodeVehicle> Link<V> {
4041
}
4142

4243
#[derive(Debug, Clone)]
43-
pub struct LocalLink<V: Debug> {
44+
pub struct LocalLink {
4445
id: usize,
45-
q: VecDeque<VehicleQEntry<V>>,
46+
q: VecDeque<VehicleQEntry<Vehicle>>,
4647
length: f32,
4748
freespeed: f32,
4849
flowcap: Flowcap,
@@ -57,7 +58,7 @@ struct VehicleQEntry<V> {
5758
earliest_exit_time: u32,
5859
}
5960

60-
impl<V: Debug + NodeVehicle> LocalLink<V> {
61+
impl LocalLink {
6162
pub fn from_io_link(
6263
id: usize,
6364
link: &IOLink,
@@ -101,7 +102,7 @@ impl<V: Debug + NodeVehicle> LocalLink<V> {
101102

102103
pub fn push_vehicle(
103104
&mut self,
104-
vehicle: V,
105+
vehicle: Vehicle,
105106
now: u32,
106107
vehicle_definitions: Option<&VehicleDefinitions>,
107108
) {
@@ -114,7 +115,7 @@ impl<V: Debug + NodeVehicle> LocalLink<V> {
114115
});
115116
}
116117

117-
pub fn pop_front(&mut self, now: u32) -> Vec<V> {
118+
pub fn pop_front(&mut self, now: u32) -> Vec<Vehicle> {
118119
self.flowcap.update_capacity(now);
119120

120121
let mut popped_veh = Vec::new();
@@ -146,7 +147,7 @@ impl<V: Debug + NodeVehicle> LocalLink<V> {
146147

147148
fn get_speed_for_vehicle(
148149
&self,
149-
vehicle: &V,
150+
vehicle: &Vehicle,
150151
vehicle_definitions: Option<&VehicleDefinitions>,
151152
) -> f32 {
152153
if vehicle_definitions.is_none() {
@@ -190,13 +191,13 @@ impl SplitOutLink {
190191
}
191192

192193
#[derive(Debug, Clone)]
193-
pub struct SplitInLink<V: Debug> {
194+
pub struct SplitInLink {
194195
from_part: usize,
195-
local_link: LocalLink<V>,
196+
local_link: LocalLink,
196197
}
197198

198-
impl<V: Debug> SplitInLink<V> {
199-
pub fn new(from_part: usize, local_link: LocalLink<V>) -> Self {
199+
impl SplitInLink {
200+
pub fn new(from_part: usize, local_link: LocalLink) -> Self {
200201
SplitInLink {
201202
from_part,
202203
local_link,
@@ -207,11 +208,11 @@ impl<V: Debug> SplitInLink<V> {
207208
self.from_part
208209
}
209210

210-
pub fn local_link_mut(&mut self) -> &mut LocalLink<V> {
211+
pub fn local_link_mut(&mut self) -> &mut LocalLink {
211212
&mut self.local_link
212213
}
213214

214-
pub fn local_link(&self) -> &LocalLink<V> {
215+
pub fn local_link(&self) -> &LocalLink {
215216
&self.local_link
216217
}
217218
}

src/simulation/network/network.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@ use crate::simulation::id_mapping::MatsimIdMappings;
22
use crate::simulation::io::matsim_id::MatsimId;
33
use crate::simulation::io::network::{IOLink, IONetwork, IONode};
44
use crate::simulation::network::network_partition::NetworkPartition;
5-
use crate::simulation::network::node::NodeVehicle;
65
use std::collections::HashMap;
76
use std::fmt::Debug;
87
use std::sync::Arc;
98

109
#[derive(Debug)]
11-
pub struct Network<V: NodeVehicle> {
12-
pub partitions: Vec<NetworkPartition<V>>,
10+
pub struct Network {
11+
pub partitions: Vec<NetworkPartition>,
1312
pub nodes_2_partition: Arc<HashMap<usize, usize>>,
1413
pub links_2_partition: Arc<HashMap<usize, usize>>,
1514
}
1615

17-
pub struct MutNetwork<V: NodeVehicle> {
18-
pub partitions: Vec<NetworkPartition<V>>,
16+
pub struct MutNetwork {
17+
pub partitions: Vec<NetworkPartition>,
1918
pub nodes_2_partition: HashMap<usize, usize>,
2019
pub links_2_partition: HashMap<usize, usize>,
2120
}
2221

23-
impl<V: NodeVehicle> Network<V> {
24-
fn from_mut_network(network: MutNetwork<V>) -> Self {
22+
impl Network {
23+
fn from_mut_network(network: MutNetwork) -> Self {
2524
Network {
2625
partitions: network.partitions,
2726
nodes_2_partition: Arc::new(network.nodes_2_partition),
@@ -61,7 +60,7 @@ impl<V: NodeVehicle> Network<V> {
6160
}
6261
}
6362

64-
impl<V: NodeVehicle> MutNetwork<V> {
63+
impl MutNetwork {
6564
fn new(num_parts: usize) -> Self {
6665
let mut partitions = Vec::with_capacity(num_parts);
6766
for _ in 0..num_parts {

src/simulation/network/network_partition.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use crate::simulation::io::network::IOLink;
22
use crate::simulation::network::link::{Link, LocalLink, SplitInLink, SplitOutLink};
3-
use crate::simulation::network::node::{Node, NodeVehicle};
3+
use crate::simulation::network::node::{Node};
44
use std::collections::btree_map::Values;
55
use std::collections::{BTreeMap, HashSet};
66
use std::fmt::Debug;
77

88
#[derive(Debug, Clone)]
9-
pub struct NetworkPartition<V: NodeVehicle> {
10-
pub links: BTreeMap<usize, Link<V>>,
9+
pub struct NetworkPartition {
10+
pub links: BTreeMap<usize, Link>,
1111
pub nodes: BTreeMap<usize, Node>,
1212
}
1313

14-
impl<V: NodeVehicle> NetworkPartition<V> {
14+
impl NetworkPartition {
1515
pub fn new() -> Self {
1616
Self {
1717
links: BTreeMap::new(),

src/simulation/network/node.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::simulation::io::vehicle_definitions::VehicleDefinitions;
22
use crate::simulation::messaging::events::proto::Event;
33
use crate::simulation::messaging::events::EventsPublisher;
4+
use crate::simulation::messaging::messages::proto::Vehicle;
45
use crate::simulation::network::link::Link;
56
use crate::simulation::network::node::Node::{LocalNode, NeighbourNode};
67
use std::collections::BTreeMap;
@@ -61,13 +62,13 @@ impl Node {
6162
}
6263
}
6364

64-
pub fn move_vehicles<V: NodeVehicle>(
65+
pub fn move_vehicles(
6566
&self,
66-
links: &mut BTreeMap<usize, Link<V>>,
67+
links: &mut BTreeMap<usize, Link>,
6768
now: u32,
6869
events: &mut EventsPublisher,
6970
vehicle_definitions: Option<&VehicleDefinitions>,
70-
) -> Vec<ExitReason<V>> {
71+
) -> Vec<ExitReason> {
7172
match self {
7273
LocalNode(n) => n.move_vehicles(links, now, events, vehicle_definitions),
7374
NeighbourNode(_) => {
@@ -102,9 +103,9 @@ pub struct NodeImpl {
102103
pub y: f32,
103104
}
104105

105-
pub enum ExitReason<V> {
106-
FinishRoute(V),
107-
ReachedBoundary(V),
106+
pub enum ExitReason {
107+
FinishRoute(Vehicle),
108+
ReachedBoundary(Vehicle),
108109
}
109110

110111
impl NodeImpl {
@@ -126,17 +127,17 @@ impl NodeImpl {
126127
self.out_links.push(id);
127128
}
128129

129-
pub fn move_vehicles<V: NodeVehicle>(
130+
pub fn move_vehicles(
130131
&self,
131-
links: &mut BTreeMap<usize, Link<V>>,
132+
links: &mut BTreeMap<usize, Link>,
132133
now: u32,
133134
events: &mut EventsPublisher,
134135
vehicle_definitions: Option<&VehicleDefinitions>,
135-
) -> Vec<ExitReason<V>> {
136+
) -> Vec<ExitReason> {
136137
let mut exited_vehicles = Vec::new();
137138

138139
for in_link_index in &self.in_links {
139-
let vehicles: Vec<V> = match links.get_mut(in_link_index).unwrap() {
140+
let vehicles: Vec<Vehicle> = match links.get_mut(in_link_index).unwrap() {
140141
Link::LocalLink(link) => link.pop_front(now),
141142
Link::SplitInLink(split_link) => split_link.local_link_mut().pop_front(now),
142143
Link::SplitOutLink(_) => panic!("No split out link expected as in link of a node."),
@@ -170,12 +171,12 @@ impl NodeImpl {
170171
exited_vehicles
171172
}
172173

173-
fn move_vehicle<V: NodeVehicle>(
174+
fn move_vehicle(
174175
&self,
175-
links: &mut BTreeMap<usize, Link<V>>,
176+
links: &mut BTreeMap<usize, Link>,
176177
out_link_id: usize,
177-
vehicle: V,
178-
exited_vehicles: &mut Vec<ExitReason<V>>,
178+
vehicle: Vehicle,
179+
exited_vehicles: &mut Vec<ExitReason>,
179180
now: u32,
180181
events: &mut EventsPublisher,
181182
vehicle_definitions: Option<&VehicleDefinitions>,

src/simulation/population.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::simulation::id_mapping::{MatsimIdMapping, MatsimIdMappings};
33
use crate::simulation::io::population::{IOPerson, IOPlanElement, IOPopulation};
44
use crate::simulation::messaging::messages::proto::Agent;
55
use crate::simulation::network::network::Network;
6-
use crate::simulation::network::node::NodeVehicle;
76
use std::collections::btree_map::BTreeMap;
87

98
#[derive(Debug)]
@@ -20,11 +19,11 @@ impl Population {
2019
}
2120
}
2221

23-
pub fn from_io<V: NodeVehicle>(
22+
pub fn from_io(
2423
io_population: &IOPopulation,
2524
id_mappings: &MatsimIdMappings,
2625
partition: usize,
27-
network: &Network<V>,
26+
network: &Network,
2827
routing_mode: RoutingMode,
2928
) -> Population {
3029
let mut result = Population::new();

src/simulation/routing/walk_leg_updater.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::simulation::messaging::messages::proto::{Activity, Agent, Vehicle};
1+
use crate::simulation::messaging::messages::proto::{Activity, Agent};
22
use crate::simulation::network::network_partition::NetworkPartition;
33
use geo::{Closest, ClosestPoint, EuclideanDistance, Line, Point};
44

55
pub trait WalkLegUpdater {
6-
fn update_walk_leg(&self, agent: &mut Agent, network: &NetworkPartition<Vehicle>);
6+
fn update_walk_leg(&self, agent: &mut Agent, network: &NetworkPartition);
77
}
88

99
pub struct EuclideanWalkLegUpdater {
@@ -17,7 +17,7 @@ impl EuclideanWalkLegUpdater {
1717
}
1818
}
1919

20-
fn get_walk_distance(&self, curr_act: &Activity, network: &NetworkPartition<Vehicle>) -> f32 {
20+
fn get_walk_distance(&self, curr_act: &Activity, network: &NetworkPartition) -> f32 {
2121
let curr_act_point = Point::new(curr_act.x, curr_act.y);
2222
let (from_node_id, to_node_id) = network
2323
.links
@@ -47,7 +47,7 @@ impl EuclideanWalkLegUpdater {
4747
}
4848

4949
impl WalkLegUpdater for EuclideanWalkLegUpdater {
50-
fn update_walk_leg(&self, agent: &mut Agent, network: &NetworkPartition<Vehicle>) {
50+
fn update_walk_leg(&self, agent: &mut Agent, network: &NetworkPartition) {
5151
let curr_act = agent.curr_act();
5252
let next_act = agent.next_act();
5353

src/simulation/simulation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use log::{debug, info};
2020
pub struct Simulation<'sim> {
2121
activity_q: TimeQueue<Agent>,
2222
teleportation_q: TimeQueue<Vehicle>,
23-
network: NetworkPartition<Vehicle>,
23+
network: NetworkPartition,
2424
message_broker: MpiMessageBroker,
2525
events: EventsPublisher,
2626
router: Option<Box<dyn Router>>,
@@ -33,7 +33,7 @@ impl<'sim> Simulation<'sim> {
3333
pub fn new(
3434
config: &Config,
3535
id_mappings: &'sim MatsimIdMappings,
36-
network: NetworkPartition<Vehicle>,
36+
network: NetworkPartition,
3737
population: Population,
3838
message_broker: MpiMessageBroker,
3939
events: EventsPublisher,
@@ -263,7 +263,7 @@ impl<'sim> Simulation<'sim> {
263263
}
264264

265265
fn move_nodes(&mut self, now: u32) {
266-
for node in NetworkPartition::<Vehicle>::get_local_nodes(self.network.nodes.values()) {
266+
for node in NetworkPartition::get_local_nodes(self.network.nodes.values()) {
267267
let exited_vehicles = node.move_vehicles(
268268
&mut self.network.links,
269269
now,

0 commit comments

Comments
 (0)