Compare commits
No commits in common. "refactor/consolidate-graphs" and "master" have entirely different histories.
refactor/c
...
master
69
src/main.rs
69
src/main.rs
@ -1,5 +1,5 @@
|
||||
use petgraph::stable_graph::{NodeIndex, StableGraph};
|
||||
use petgraph::{Graph, Undirected};
|
||||
use petgraph::Undirected;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufRead};
|
||||
@ -7,30 +7,31 @@ use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let filename = String::from("src/nodes.txt");
|
||||
let graph = build_graph(&filename);
|
||||
let taxi_graph = build_graph_taxi(&filename);
|
||||
let bus_graph = build_graph_bus(&filename);
|
||||
let underground_graph = build_graph_underground(&filename);
|
||||
let boat_graph = build_graph_boat(&filename);
|
||||
|
||||
println!("{:?}", graph);
|
||||
|
||||
// loop {
|
||||
// let (current_nodes, transport_type) = parse_input();
|
||||
// let mut neighbors = Vec::<NodeIndex<usize>>::new();
|
||||
// for node in current_nodes {
|
||||
// match Some(&*transport_type.to_string()) {
|
||||
// Some("Taxi") => neighbors.extend(taxi_graph.neighbors(NodeIndex::new(node))),
|
||||
// Some("Bus") => neighbors.extend(bus_graph.neighbors(NodeIndex::new(node))),
|
||||
// Some("Underground") => {
|
||||
// neighbors.extend(underground_graph.neighbors(NodeIndex::new(node)))
|
||||
// }
|
||||
// Some("Boat") => neighbors.extend(boat_graph.neighbors(NodeIndex::new(node))),
|
||||
// _ => {}
|
||||
// }
|
||||
// }
|
||||
// let neighbors: Vec<usize> = neighbors.iter().map(|node| node.index()).collect();
|
||||
// for neighbor in neighbors {
|
||||
// print!("{} ", neighbor);
|
||||
// }
|
||||
// println!("");
|
||||
// }
|
||||
loop {
|
||||
let (current_nodes, transport_type) = parse_input();
|
||||
let mut neighbors = Vec::<NodeIndex<usize>>::new();
|
||||
for node in current_nodes {
|
||||
match Some(&*transport_type.to_string()) {
|
||||
Some("Taxi") => neighbors.extend(taxi_graph.neighbors(NodeIndex::new(node))),
|
||||
Some("Bus") => neighbors.extend(bus_graph.neighbors(NodeIndex::new(node))),
|
||||
Some("Underground") => {
|
||||
neighbors.extend(underground_graph.neighbors(NodeIndex::new(node)))
|
||||
}
|
||||
Some("Boat") => neighbors.extend(boat_graph.neighbors(NodeIndex::new(node))),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let neighbors: Vec<usize> = neighbors.iter().map(|node| node.index()).collect();
|
||||
for neighbor in neighbors {
|
||||
print!("{} ", neighbor);
|
||||
}
|
||||
println!("");
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_input() -> (Vec<usize>, String) {
|
||||
@ -55,26 +56,6 @@ fn parse_input() -> (Vec<usize>, String) {
|
||||
(numbers, String::from(transport_type))
|
||||
}
|
||||
|
||||
fn build_graph(filename: &String) -> Graph<i32, String, Undirected> {
|
||||
let mut graph = Graph::<i32, String, Undirected>::with_capacity(199, 468);
|
||||
for i in 0..200 {
|
||||
graph.add_node(i);
|
||||
}
|
||||
|
||||
if let Ok(lines) = read_lines(filename) {
|
||||
for line in lines {
|
||||
if let Ok(edge) = line {
|
||||
// (1, 2, "Taxi")
|
||||
let mut edge = edge.split_whitespace();
|
||||
let a = NodeIndex::new(edge.next().unwrap().parse().unwrap());
|
||||
let b = NodeIndex::new(edge.next().unwrap().parse().unwrap());
|
||||
graph.add_edge(a, b, String::from(edge.next().unwrap()));
|
||||
}
|
||||
}
|
||||
}
|
||||
graph
|
||||
}
|
||||
|
||||
fn build_graph_taxi(filename: &String) -> StableGraph<(), (), Undirected, usize> {
|
||||
let mut graph = StableGraph::<(), (), Undirected, usize>::with_capacity(199, 345);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user