Skip to content

Commit

Permalink
make it possible to read and write effective cell size to/from files
Browse files Browse the repository at this point in the history
  • Loading branch information
janekdererste committed Oct 10, 2023
1 parent c3ca5dd commit b654dfe
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/simulation/io/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub struct Nodes {
pub struct Links {
#[serde(rename = "link", default)]
pub links: Vec<IOLink>,
#[serde(rename = "effectivecellsize")]
effective_cell_size: Option<f32>,
}

#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
Expand All @@ -84,7 +86,10 @@ pub struct IONetwork {
impl IONetwork {
pub fn new(name: Option<String>) -> IONetwork {
IONetwork {
links: Links { links: Vec::new() },
links: Links {
links: Vec::new(),
effective_cell_size: Some(7.5),
},
nodes: Nodes { nodes: Vec::new() },
name,
}
Expand All @@ -105,6 +110,13 @@ impl IONetwork {
&mut self.links.links
}

pub fn effective_cell_size(&self) -> f32 {
match self.links.effective_cell_size {
None => 7.5,
Some(ecs) => ecs,
}
}

pub fn from_file(file_path: &str) -> IONetwork {
let network: IONetwork = xml_reader::read(file_path);
info!(
Expand Down Expand Up @@ -179,7 +191,7 @@ mod tests {
<nodes>
<node id=\"1\" x=\"-20000\" y=\"0\"/>
</nodes>
<links>
<links effectivecellsize=\"385.3\">
<link id=\"23\" from=\"15\" to=\"1\" length=\"10000.00\" capacity=\"36000\" freespeed=\"27.78\" permlanes=\"1\" modes=\"car,bike\" />
</links>
</network>
Expand All @@ -205,7 +217,7 @@ mod tests {
</attributes>
</node>
</nodes>
<links>
<links effectivecellsize=\"42.0\">
<link id=\"23\" from=\"15\" to=\"1\" length=\"10000.00\" capacity=\"36000\" freespeed=\"27.78\" permlanes=\"1\" modes=\"car, bike\" />
</links>
</network>
Expand All @@ -217,6 +229,7 @@ mod tests {
assert_eq!("test network", result.name.as_ref().unwrap());
assert_eq!(1, result.nodes().len());
assert_eq!(1, result.links().len());
assert_eq!(42., result.effective_cell_size());

// test node structure
let node = result.nodes().first().unwrap();
Expand Down Expand Up @@ -275,8 +288,6 @@ mod tests {
}
}
}

println!("{network:#?}");
}

#[test]
Expand All @@ -288,6 +299,8 @@ mod tests {
assert_eq!("equil test network", network.name.as_ref().unwrap());
assert_eq!(15, network.nodes().len());
assert_eq!(23, network.links().len());
// this network doesn't have an effectivecellsize set so test, whether the default works
assert_eq!(7.5, network.effective_cell_size());
}

#[test]
Expand Down

0 comments on commit b654dfe

Please sign in to comment.