use super::GraphPredicateInput;
#[derive(Debug, Clone, PartialEq)]
pub struct GraphPageRankParams {
pub alpha: f64,
pub epsilon: f64,
pub max_iterations: u32,
}
impl Default for GraphPageRankParams {
fn default() -> Self {
Self { alpha: 0.85, epsilon: 1e-5, max_iterations: 100 }
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphPersonalizedPageRankParams {
pub pagerank: GraphPageRankParams,
pub personalization: GraphPageRankPersonalizationInput,
}
impl GraphPersonalizedPageRankParams {
pub(crate) fn side_input_ordinals(&self) -> impl Iterator<Item = usize> + '_ {
std::iter::once(self.personalization.input)
}
}
impl Default for GraphPersonalizedPageRankParams {
fn default() -> Self {
Self {
pagerank: GraphPageRankParams::default(),
personalization: GraphPageRankPersonalizationInput::new(1, "vertex", "value"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GraphPageRankPersonalizationInput {
pub input: usize,
pub vertex: String,
pub value: String,
}
impl GraphPageRankPersonalizationInput {
pub fn new(input: usize, vertex: impl Into<String>, value: impl Into<String>) -> Self {
Self { input, vertex: vertex.into(), value: value.into() }
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphEigenvectorCentralityParams {
pub epsilon: f64,
pub max_iterations: u32,
}
impl Default for GraphEigenvectorCentralityParams {
fn default() -> Self {
Self { epsilon: 1.0e-6, max_iterations: 200 }
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphKatzCentralityParams {
pub alpha: f64,
pub beta: f64,
pub epsilon: f64,
pub max_iterations: u32,
}
impl Default for GraphKatzCentralityParams {
fn default() -> Self {
Self { alpha: 0.01, beta: 1.0, epsilon: 1.0e-6, max_iterations: 1000 }
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphHitsParams {
pub epsilon: f64,
pub max_iterations: u32,
pub normalize: bool,
}
impl Default for GraphHitsParams {
fn default() -> Self {
Self { epsilon: 1.0e-5, max_iterations: 100, normalize: false }
}
}
pub const DEFAULT_BETWEENNESS_EXACT_VERTEX_THRESHOLD: u64 = 100_000;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GraphBetweennessSeeds {
I64(Vec<i64>),
Input {
input: GraphPredicateInput,
row_count_upper_bound: u64,
},
}
impl GraphBetweennessSeeds {
pub fn len(&self) -> usize {
match self {
Self::I64(values) => values.len(),
Self::Input { row_count_upper_bound, .. } => usize::try_from(*row_count_upper_bound).unwrap_or(usize::MAX),
}
}
pub fn is_empty(&self) -> bool {
match self {
Self::I64(values) => values.is_empty(),
Self::Input { row_count_upper_bound, .. } => *row_count_upper_bound == 0,
}
}
}
impl GraphBetweennessSeeds {
pub(crate) fn side_input_ordinals(&self) -> impl Iterator<Item = usize> + '_ {
match self {
Self::I64(_) => None,
Self::Input { input, .. } => Some(input.input),
}
.into_iter()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GraphBetweennessCentralityParams {
pub seeds: Option<GraphBetweennessSeeds>,
pub k: Option<u64>,
pub normalized: bool,
pub include_endpoints: bool,
pub exact_vertex_threshold: u64,
}
impl GraphBetweennessCentralityParams {
pub(crate) fn side_input_ordinals(&self) -> impl Iterator<Item = usize> + '_ {
self.seeds.iter().flat_map(GraphBetweennessSeeds::side_input_ordinals)
}
}
impl Default for GraphBetweennessCentralityParams {
fn default() -> Self {
Self {
seeds: None,
k: None,
normalized: true,
include_endpoints: false,
exact_vertex_threshold: DEFAULT_BETWEENNESS_EXACT_VERTEX_THRESHOLD,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GraphEdgeBetweennessCentralityParams {
pub seeds: Option<GraphBetweennessSeeds>,
pub k: Option<u64>,
pub normalized: bool,
pub exact_vertex_threshold: u64,
}
impl GraphEdgeBetweennessCentralityParams {
pub(crate) fn side_input_ordinals(&self) -> impl Iterator<Item = usize> + '_ {
self.seeds.iter().flat_map(GraphBetweennessSeeds::side_input_ordinals)
}
}
impl Default for GraphEdgeBetweennessCentralityParams {
fn default() -> Self {
Self {
seeds: None,
k: None,
normalized: true,
exact_vertex_threshold: DEFAULT_BETWEENNESS_EXACT_VERTEX_THRESHOLD,
}
}
}