Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

A graph represented as an adjacency list

Implementations§

Source§

impl Graph

Source

pub fn new(n: usize) -> Self

Create a new empty graph with n vertices

Source

pub fn add_edge(&mut self, u: usize, v: usize) -> Result<(), &'static str>

Add an edge between vertices u and v

Source

pub fn degree(&self, v: usize) -> Result<usize, &'static str>

Get the degree of a vertex

Source

pub fn first_zagreb_index(&self) -> usize

Calculate the first Zagreb index of the graph

Source

pub fn min_degree(&self) -> usize

Get the minimum degree of the graph

Source

pub fn max_degree(&self) -> usize

Get the maximum degree of the graph

Source

pub fn is_k_connected(&self, k: usize, use_exact: bool) -> bool

Check if the graph is k-connected (wrapper function)

§Arguments
  • k - The connectivity parameter to check
  • use_exact - Whether to use the exact algorithm (slower but more accurate) or the approximation
§Returns

true if the graph is k-connected, false otherwise

Source

pub fn is_k_connected_approx(&self, k: usize) -> bool

Check if the graph is k-connected using an approximation algorithm This is faster but may give incorrect results in some cases

Source

pub fn is_k_connected_exact(&self, k: usize) -> bool

Check if the graph is k-connected using an exact algorithm based on Menger’s theorem This is slower but gives correct results for all graphs

Source

pub fn independence_number_approx(&self) -> usize

Calculate independence number (approximate) Finding the exact independence number is NP-hard, so this is a greedy approximation

Source

pub fn is_likely_hamiltonian(&self, use_exact_connectivity: bool) -> bool

Check if the graph is likely Hamiltonian using Theorem 1 from the paper and known graph properties

§Arguments
  • use_exact_connectivity - Whether to use exact connectivity checking (slower but more accurate)
Source

pub fn is_likely_traceable(&self, use_exact_connectivity: bool) -> bool

Check if the graph is likely traceable using Theorem 2 from the paper and known graph properties

§Arguments
  • use_exact_connectivity - Whether to use exact connectivity checking (slower but more accurate)
Source

pub fn zagreb_upper_bound(&self) -> f64

Calculate upper bound on Zagreb index using Theorem 3 from the paper

Source

pub fn vertex_count(&self) -> usize

Get the number of vertices

Source

pub fn edge_count(&self) -> usize

Get the number of edges

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnwindSafe for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.