Compare commits
1 Commits
master
...
refactor/c
| Author | SHA1 | Date | |
|---|---|---|---|
| 784914166c |
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::Undirected;
|
use petgraph::{Graph, Undirected};
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, BufRead};
|
use std::io::{self, BufRead};
|
||||||
@ -7,31 +7,30 @@ use std::path::Path;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let filename = String::from("src/nodes.txt");
|
let filename = String::from("src/nodes.txt");
|
||||||
let taxi_graph = build_graph_taxi(&filename);
|
let graph = build_graph(&filename);
|
||||||
let bus_graph = build_graph_bus(&filename);
|
|
||||||
let underground_graph = build_graph_underground(&filename);
|
|
||||||
let boat_graph = build_graph_boat(&filename);
|
|
||||||
|
|
||||||
loop {
|
println!("{:?}", graph);
|
||||||
let (current_nodes, transport_type) = parse_input();
|
|
||||||
let mut neighbors = Vec::<NodeIndex<usize>>::new();
|
// loop {
|
||||||
for node in current_nodes {
|
// let (current_nodes, transport_type) = parse_input();
|
||||||
match Some(&*transport_type.to_string()) {
|
// let mut neighbors = Vec::<NodeIndex<usize>>::new();
|
||||||
Some("Taxi") => neighbors.extend(taxi_graph.neighbors(NodeIndex::new(node))),
|
// for node in current_nodes {
|
||||||
Some("Bus") => neighbors.extend(bus_graph.neighbors(NodeIndex::new(node))),
|
// match Some(&*transport_type.to_string()) {
|
||||||
Some("Underground") => {
|
// Some("Taxi") => neighbors.extend(taxi_graph.neighbors(NodeIndex::new(node))),
|
||||||
neighbors.extend(underground_graph.neighbors(NodeIndex::new(node)))
|
// Some("Bus") => neighbors.extend(bus_graph.neighbors(NodeIndex::new(node))),
|
||||||
}
|
// Some("Underground") => {
|
||||||
Some("Boat") => neighbors.extend(boat_graph.neighbors(NodeIndex::new(node))),
|
// 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);
|
// let neighbors: Vec<usize> = neighbors.iter().map(|node| node.index()).collect();
|
||||||
}
|
// for neighbor in neighbors {
|
||||||
println!("");
|
// print!("{} ", neighbor);
|
||||||
}
|
// }
|
||||||
|
// println!("");
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_input() -> (Vec<usize>, String) {
|
fn parse_input() -> (Vec<usize>, String) {
|
||||||
@ -56,6 +55,26 @@ 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