added current code
This commit is contained in:
parent
557558acc6
commit
41e5e9b032
39 changed files with 2431 additions and 215 deletions
74
src/bin/generate_benchmark_targets.rs
Normal file
74
src/bin/generate_benchmark_targets.rs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
use fapra_osm_2::gridgraph::GridGraph;
|
||||
use std::fs::File;
|
||||
use clap::Parser;
|
||||
use std::process::exit;
|
||||
use rand::seq::SliceRandom;
|
||||
use fapra_osm_2::utils::RoutingQuery;
|
||||
use serde_json;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(author, version, about, long_about=None)]
|
||||
struct Args {
|
||||
/// name of the FMI file to read
|
||||
#[clap(short, long)]
|
||||
graph: String,
|
||||
|
||||
/// number of samples to generate
|
||||
#[clap(short, long, default_value_t = 1000)]
|
||||
samples: usize,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
let file = match File::open(args.graph.clone()) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
println!("Error while opening the file {}: {}", args.graph, e);
|
||||
exit(1)
|
||||
}
|
||||
};
|
||||
|
||||
let graph = match GridGraph::from_fmi_file(file) {
|
||||
Ok(g) => g,
|
||||
Err(e) => {
|
||||
println!("Error while reading the graph: {:?}", e);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let mut targets = graph.nodes.choose_multiple(&mut rng, args.samples * 2);
|
||||
|
||||
let mut queries: Vec<RoutingQuery> = Vec::new();
|
||||
|
||||
for i in (0..targets.len()).step_by(2) {
|
||||
|
||||
let source = match targets.next() {
|
||||
Some(t) => t.index as usize,
|
||||
None => {
|
||||
println!("Expected a source node with index {}, but there was None.", i);
|
||||
exit(2);
|
||||
},
|
||||
};
|
||||
|
||||
let destination = match targets.next() {
|
||||
Some(t) => t.index as usize,
|
||||
None => {
|
||||
println!("Expected a destination node with index {}, but there was None.", i+1);
|
||||
exit(2);
|
||||
},
|
||||
};
|
||||
|
||||
queries.push(RoutingQuery{ source, destination})
|
||||
}
|
||||
|
||||
match serde_json::to_string(&queries) {
|
||||
Ok(s) => println!("{}", s),
|
||||
Err(e) => {
|
||||
println!("Error while serializeing: {}", e);
|
||||
exit(2);
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue