Skip to content

Commit

Permalink
use pre partitioning
Browse files Browse the repository at this point in the history
  • Loading branch information
paulheinr committed Nov 28, 2024
1 parent f5ee0d3 commit b68e29d
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 33 deletions.
91 changes: 77 additions & 14 deletions assets/adhoc_routing/with_updates/network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,86 @@
<!DOCTYPE network SYSTEM "http://www.matsim.org/files/dtd/network_v2.dtd">
<network>
<nodes>
<node id="node0" x="-100.0" y="0.0"/>
<node id="node1" x="0.0" y="0.0"/>
<node id="node2" x="100.0" y="0.0"/>
<node id="node3" x="1100.0" y="0.0"/>
<node id="node4" x="1200.0" y="0.0" />
<node id="node5" x="1300.0" y="0.0" />
<node id="node6" x="600.0" y="300.0" />
<node id="node0" x="-100.0" y="0.0">
<attributes>
<attribute name="partition" class="java.lang.Integer">1</attribute>
</attributes>
</node>
<node id="node1" x="0.0" y="0.0">
<attributes>
<attribute name="partition" class="java.lang.Integer">1</attribute>
</attributes>
</node>
<node id="node2" x="100.0" y="0.0">
<attributes>
<attribute name="partition" class="java.lang.Integer">1</attribute>
</attributes>
</node>
<node id="node3" x="1100.0" y="0.0">
<attributes>
<attribute name="partition" class="java.lang.Integer">0</attribute>
</attributes>
</node>
<node id="node4" x="1200.0" y="0.0">
<attributes>
<attribute name="partition" class="java.lang.Integer">0</attribute>
</attributes>
</node>
<node id="node5" x="1300.0" y="0.0">
<attributes>
<attribute name="partition" class="java.lang.Integer">0</attribute>
</attributes>
</node>
<node id="node6" x="600.0" y="300.0">
<attributes>
<attribute name="partition" class="java.lang.Integer">1</attribute>
</attributes>
</node>
</nodes>
<links capperiod="01:00:00" effectivecellsize="7.5" effectivelanewidth="3.75">
<link id="0" from="node0" to="node1" length="100" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1" modes="bike,car" />
<link id="1" from="node1" to="node2" length="100" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1" modes="bike,car" />
<link id="2" from="node2" to="node3" length="1000" freespeed="10" capacity="3.0" permlanes="1.0" oneway="1" modes="bike,car" />
<link id="3" from="node3" to="node4" length="100" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1" modes="bike,car" />
<link id="4" from="node4" to="node5" length="100" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1" modes="bike,car"/>
<link id="0" from="node0" to="node1" length="100" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1"
modes="bike,car">
<attributes>
<attribute name="partition" class="java.lang.Integer">1</attribute>
</attributes>
</link>
<link id="1" from="node1" to="node2" length="100" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1"
modes="bike,car">
<attributes>
<attribute name="partition" class="java.lang.Integer">1</attribute>
</attributes>
</link>
<link id="2" from="node2" to="node3" length="1000" freespeed="10" capacity="3.0" permlanes="1.0" oneway="1"
modes="bike,car">
<attributes>
<attribute name="partition" class="java.lang.Integer">0</attribute>
</attributes>
</link>
<link id="3" from="node3" to="node4" length="100" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1"
modes="bike,car">
<attributes>
<attribute name="partition" class="java.lang.Integer">0</attribute>
</attributes>
</link>
<link id="4" from="node4" to="node5" length="100" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1"
modes="bike,car">
<attributes>
<attribute name="partition" class="java.lang.Integer">0</attribute>
</attributes>
</link>

<link id="5" from="node2" to="node6" length="1000" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1" modes="bike,car"/>
<link id="6" from="node6" to="node3" length="1000" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1" modes="bike,car"/>
<link id="5" from="node2" to="node6" length="1000" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1"
modes="bike,car">
<attributes>
<attribute name="partition" class="java.lang.Integer">1</attribute>
</attributes>
</link>
<link id="6" from="node6" to="node3" length="1000" freespeed="10" capacity="100.0" permlanes="1.0" oneway="1"
modes="bike,car">
<attributes>
<attribute name="partition" class="java.lang.Integer">0</attribute>
</attributes>
</link>

</links>
</network>
2 changes: 1 addition & 1 deletion src/simulation/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub fn get_numbered_output_filename(output_dir: &Path, input_file: &Path, part:
insert_number_in_proto_filename(&out, part)
}

fn create_output_filename(output_dir: &Path, input_file: &Path) -> PathBuf {
pub fn create_output_filename(output_dir: &Path, input_file: &Path) -> PathBuf {
let filename = input_file.file_name().unwrap();
output_dir.join(filename)
}
Expand Down
4 changes: 1 addition & 3 deletions tests/resources/adhoc_routing/no_updates/config-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ modules:
partitioning:
type: Partitioning
num_parts: 2
method: !Metis
vertex_weight:
- Constant
method: None
output:
type: Output
output_dir: ./test_output/simulation/adhoc_routing/no_updates/two_parts
Expand Down
4 changes: 1 addition & 3 deletions tests/resources/adhoc_routing/with_updates/config-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ modules:
partitioning:
type: Partitioning
num_parts: 2
method: !Metis
vertex_weight:
- Constant
method: None
output:
type: Output
output_dir: ./test_output/simulation/adhoc_routing/with_updates/two_parts
Expand Down
4 changes: 3 additions & 1 deletion tests/test_adhoc_routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ fn create_resources(in_dir: &PathBuf, out_dir: &PathBuf) {

#[test]
fn execute_adhoc_routing_one_part_no_updates() {
// init_std_out_logging();

create_resources(
&PathBuf::from("./assets/adhoc_routing/no_updates/"),
&PathBuf::from("./test_output/simulation/adhoc_routing/no_updates/one_part/"),
Expand Down Expand Up @@ -65,7 +67,7 @@ fn execute_adhoc_routing_two_parts_no_updates() {

#[test]
fn execute_adhoc_routing_one_part_with_updates() {
init_std_out_logging();
// init_std_out_logging();

create_resources(
&PathBuf::from("./assets/adhoc_routing/with_updates/"),
Expand Down
34 changes: 23 additions & 11 deletions tests/test_simulation.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use nohash_hasher::IntMap;
use std::any::Any;
use std::collections::HashSet;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::thread::JoinHandle;
use std::{fs, thread};

use nohash_hasher::IntMap;
use tracing::info;

use rust_q_sim::simulation::config::{CommandLineArgs, Config, RoutingMode};
use rust_q_sim::simulation::controller::{get_numbered_output_filename, partition_input};
use rust_q_sim::simulation::config::{CommandLineArgs, Config, PartitionMethod, RoutingMode};
use rust_q_sim::simulation::controller::{
create_output_filename, get_numbered_output_filename, partition_input,
};
use rust_q_sim::simulation::id;
use rust_q_sim::simulation::io::xml_events::XmlEventsWriter;
use rust_q_sim::simulation::messaging::communication::communicators::{
Expand Down Expand Up @@ -69,11 +71,16 @@ pub fn execute_sim<C: SimCommunicator + 'static>(
let output_path = PathBuf::from(&config.output().output_dir);
fs::create_dir_all(&output_path).expect("Failed to create output path");

let temp_network_file = get_numbered_output_filename(
&output_path,
&PathBuf::from(config.proto_files().network),
config.partitioning().num_parts,
);
let temp_network_file = match config.partitioning().method {
PartitionMethod::Metis(_) => get_numbered_output_filename(
&output_path,
&PathBuf::from(config.proto_files().network),
config.partitioning().num_parts,
),
PartitionMethod::None => {
create_output_filename(&output_path, &PathBuf::from(config.proto_files().network))
}
};

id::load_from_file(&PathBuf::from(config.proto_files().ids));

Expand Down Expand Up @@ -101,8 +108,13 @@ pub fn execute_sim<C: SimCommunicator + 'static>(
let sim_net = SimNetworkPartition::from_network(&network, rank, config.simulation());

info!(
"Partitioning: Rank {rank}; Links {:?}",
&sim_net.get_link_ids()
"Partitioning: Rank {rank}; Links {:?}; Nodes {:?}",
&sim_net.get_link_ids(),
&sim_net
.nodes
.iter()
.map(|(id, _)| *id)
.collect::<HashSet<u64>>()
);

let mut events = EventsPublisher::new();
Expand Down

0 comments on commit b68e29d

Please sign in to comment.