59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
use fapra_osm_2::utils::load_graph;
|
|
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 graph = load_graph(&args.graph);
|
|
|
|
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);
|
|
}
|
|
};
|
|
}
|