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::stable_graph::{NodeIndex, StableGraph};
|
||||||
use petgraph::{Graph, Undirected};
|
use petgraph::Undirected;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, BufRead};
|
use std::io::{self, BufRead};
|
||||||
@ -7,30 +7,31 @@ use std::path::Path;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let filename = String::from("src/nodes.txt");
|
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();
|
||||||
// loop {
|
let mut neighbors = Vec::<NodeIndex<usize>>::new();
|
||||||
// let (current_nodes, transport_type) = parse_input();
|
for node in current_nodes {
|
||||||
// let mut neighbors = Vec::<NodeIndex<usize>>::new();
|
match Some(&*transport_type.to_string()) {
|
||||||
// for node in current_nodes {
|
Some("Taxi") => neighbors.extend(taxi_graph.neighbors(NodeIndex::new(node))),
|
||||||
// match Some(&*transport_type.to_string()) {
|
Some("Bus") => neighbors.extend(bus_graph.neighbors(NodeIndex::new(node))),
|
||||||
// Some("Taxi") => neighbors.extend(taxi_graph.neighbors(NodeIndex::new(node))),
|
Some("Underground") => {
|
||||||
// Some("Bus") => neighbors.extend(bus_graph.neighbors(NodeIndex::new(node))),
|
neighbors.extend(underground_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))),
|
||||||
// }
|
_ => {}
|
||||||
// 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 {
|
||||||
// let neighbors: Vec<usize> = neighbors.iter().map(|node| node.index()).collect();
|
print!("{} ", neighbor);
|
||||||
// for neighbor in neighbors {
|
}
|
||||||
// print!("{} ", neighbor);
|
println!("");
|
||||||
// }
|
}
|
||||||
// println!("");
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_input() -> (Vec<usize>, String) {
|
fn parse_input() -> (Vec<usize>, String) {
|
||||||
@ -55,26 +56,6 @@ fn parse_input() -> (Vec<usize>, String) {
|
|||||||
(numbers, String::from(transport_type))
|
(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> {
|
fn build_graph_taxi(filename: &String) -> StableGraph<(), (), Undirected, usize> {
|
||||||
let mut graph = StableGraph::<(), (), Undirected, usize>::with_capacity(199, 345);
|
let mut graph = StableGraph::<(), (), Undirected, usize>::with_capacity(199, 345);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user