Skip to content

Commit

Permalink
fix: peer in the up FIFO order to garantee not ciclic paths
Browse files Browse the repository at this point in the history
  • Loading branch information
guissalustiano committed Jan 19, 2024
1 parent d852ee9 commit bbdd906
Show file tree
Hide file tree
Showing 8 changed files with 1,072,022 additions and 125 deletions.
498,017 changes: 498,017 additions & 0 deletions 20231201.as-rel.txt

Large diffs are not rendered by default.

573,826 changes: 573,826 additions & 0 deletions 20231201.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ readme = "README.md"

[dependencies]
petgraph = "0.6.4"

[dev-dependencies]
rayon = "1.8.1"
bzip2 = "0.4.4"
reqwest = { version = "0.11", features = ["blocking"] }
36 changes: 1 addition & 35 deletions examples/all_paths.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use petgraph::graph::NodeIndex;
use valley_free::{RelType, Topology};

type GraphPath = Vec<NodeIndex>;

fn main() {
let topo = Topology::from_edges(vec![
(1, 2, RelType::ProviderToCustomer),
Expand All @@ -15,38 +12,7 @@ fn main() {
let start = 4;
let topo = topo.paths_graph(start);

let start_idx = topo.index_of(start).unwrap(); // Node index
let mut stack: Vec<(NodeIndex, GraphPath)> = vec![(start_idx, vec![start_idx])];
let mut visited: Vec<NodeIndex> = vec![];
let mut all_paths: Vec<GraphPath> = vec![];

while !stack.is_empty() {
let (node_idx, path) = stack.pop().unwrap();

if visited.contains(&node_idx) {
continue;
}

visited.push(node_idx);
all_paths.push(path.clone());

let childrens = topo
.graph
.neighbors_directed(node_idx, petgraph::Direction::Outgoing)
.map(|child_idx| {
let mut path = path.clone();
path.push(child_idx);
(child_idx, path)
});
stack.extend(childrens);
}

for path in all_paths {
let path = path
.iter()
.map(|node_idx| topo.asn_of(*node_idx))
.collect::<Vec<_>>();

for path in topo.path_to_all_ases(start).unwrap() {
println!("{:?}", path);
}
}
18 changes: 4 additions & 14 deletions examples/all_paths_between_two_ases.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fs::File;

use petgraph::algo::all_simple_paths;
use valley_free::Topology;

fn main() {
Expand All @@ -11,20 +10,11 @@ fn main() {
let universidade_de_sao_paulo_asn = 28571;
let ut_path = topo.paths_graph(university_of_twente_asn);

let paths = all_simple_paths::<Vec<_>, _>(
&ut_path.graph,
ut_path.index_of(university_of_twente_asn).unwrap(),
ut_path.index_of(universidade_de_sao_paulo_asn).unwrap(),
0,
None,
);

println!("Paths from UT to USP:");
for path in paths {
let path = path
.iter()
.map(|node| ut_path.asn_of(*node))
.collect::<Vec<_>>();
for path in ut_path
.all_paths_to(university_of_twente_asn, universidade_de_sao_paulo_asn)
.unwrap()
{
println!(" {:?}", path);
}
}
23 changes: 4 additions & 19 deletions examples/shortest_path_between_two_ases.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fs::File;

use petgraph::algo::astar;
use valley_free::{RelType, Topology};
use valley_free::Topology;

fn main() {
let file = File::open("20231201.as-rel.txt").unwrap();
Expand All @@ -12,23 +11,9 @@ fn main() {
let ut_path = topo.paths_graph(university_of_twente_asn);

// Use A* to find the shortest path between two nodes
let (_len, path) = astar(
&ut_path.graph,
ut_path.index_of(university_of_twente_asn).unwrap(),
|finish| finish == ut_path.index_of(universidade_de_sao_paulo_asn).unwrap(),
|edge| match edge.weight() {
// priorize pearing
RelType::PearToPear => 0,
RelType::ProviderToCustomer => 1,
RelType::CustomerToProvider => 2,
},
|_| 0,
)
.unwrap();
let path = path
.iter()
.map(|node| ut_path.asn_of(*node))
.collect::<Vec<_>>();
let path = ut_path
.shortest_path_to(university_of_twente_asn, universidade_de_sao_paulo_asn)
.unwrap();

println!("Path from UT to USP: {:?}", path);
}
1 change: 1 addition & 0 deletions out2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error: a bin target must be available for `cargo run`
Loading

0 comments on commit bbdd906

Please sign in to comment.