#![allow(unused)]
use anyhow::anyhow;
use cpu_time::ProcessTime;
use std::time::SystemTime;
use num_traits::{float::*, FromPrimitive};
use atomic::{Atomic, Ordering};
use parking_lot::RwLock;
use rayon::prelude::*;
use std::sync::Arc;
use indexmap::IndexSet;
use petgraph::graph::{DefaultIx, EdgeReference, Graph, IndexType, NodeIndex};
use petgraph::{visit::*, EdgeType, Undirected};
#[cfg_attr(doc, katexit::katexit)]
pub fn p1<N, F, Ty, Ix>(
graph: &Graph<N, F, Ty, Ix>,
vset: &IndexSet<NodeIndex<Ix>>,
node: NodeIndex<Ix>,
) -> f64
where
Ty: EdgeType,
Ix: IndexType,
{
let mut degree: usize = 0;
let mut neighbors = graph.neighbors(node);
for n in neighbors {
if vset.get(&n).is_some() {
degree += 1;
}
}
degree as f64
}
#[cfg_attr(doc, katexit::katexit)]
pub fn p2<N, F, Ty, Ix>(
graph: &Graph<N, F, Ty, Ix>,
vset: &IndexSet<NodeIndex<Ix>>,
node: NodeIndex<Ix>,
) -> f64
where
Ty: EdgeType,
Ix: IndexType,
{
let mut degree: f64 = 0.;
let mut edges = graph.neighbors_directed(node, petgraph::Incoming).detach();
while let Some((edge, n)) = edges.next(graph) {
if vset.get(&n).is_some() {
degree += 1.;
}
}
degree
}
#[cfg_attr(doc, katexit::katexit)]
pub fn p3<N, F, Ty, Ix>(
graph: &Graph<N, F, Ty, Ix>,
vset: &IndexSet<NodeIndex<Ix>>,
node: NodeIndex<Ix>,
) -> f64
where
Ty: EdgeType,
Ix: IndexType,
{
let mut degree: f64 = 0.;
let mut edges = graph.neighbors_directed(node, petgraph::Outgoing).detach();
while let Some((edge, n)) = edges.next(graph) {
if vset.get(&n).is_some() {
degree += 1.;
}
}
degree
}
#[cfg_attr(doc, katexit::katexit)]
pub fn p11<N, F, Ty, Ix>(
graph: &Graph<N, F, Ty, Ix>,
vset: &IndexSet<NodeIndex<Ix>>,
node: NodeIndex<Ix>,
) -> f64
where
Ty: EdgeType,
Ix: IndexType,
F: Float + FromPrimitive + std::ops::AddAssign,
{
let mut weight = F::zero();
let mut neighbors = graph.neighbors(node).detach();
while let Some((e, n)) = neighbors.next(graph) {
if vset.get(&n).is_some() {
weight += graph[e];
}
}
weight.to_f64().unwrap()
}