Skip to main content

WeightedGraph

Struct WeightedGraph 

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

An undirected graph whose edges carry small positive integer weights (1 to 255), as used by the original wsub_search and wggen. Weights live in an n x n byte matrix (O(1) lookup, n * n bytes) alongside sorted neighbor lists. A graph made from real-valued scores with WeightedGraph::from_scores also keeps those scores (8 * n * n bytes), so that results can be totalled exactly (WeightedGraph::induced_score).

Implementations§

Source§

impl WeightedGraph

Source

pub fn from_weighted_edges<I>( n: usize, edges: I, ) -> Result<WeightedGraph, Error>
where I: IntoIterator<Item = (usize, usize, u32)>,

Builds a weighted graph from (u, v, weight) triples. Weights must be between 1 and 255; if an edge is listed more than once, the last weight given wins.

Source

pub fn from_scores<I>( n: usize, scores: I, resolution: u32, ) -> Result<(WeightedGraph, f64), Error>
where I: IntoIterator<Item = (usize, usize, f64)>,

Builds a weighted graph from real-valued, non-negative scores between pairs of vertices, such as distances or similarities, given as (u, v, score) triples, and returns it with the factor the scores were scaled by. Weights are integers from 1 to 255, so each score is multiplied by resolution / largest score and rounded (ties to even): the largest becomes resolution, at most 255. A positive score too small to survive rounding keeps weight 1, and a score of 0 is no edge. A total weight t stands for scores totalling about t / factor; the graph keeps the scores, so WeightedGraph::induced_score gives the exact total. If a pair is listed more than once, the last score given wins.

Source

pub fn scores(&self) -> Option<&[f64]>

The scores the graph was made from with WeightedGraph::from_scores, as an n x n row-major matrix (0 for pairs without a score), or None for other graphs.

Source

pub fn induced_score(&self, vertices: &[usize]) -> Option<f64>

The total score of the pairs among vertices, from the scores the graph was made from: the exact counterpart of WeightedGraph::induced_weight. None for graphs without scores.

Source

pub fn from_graph(g: &Graph) -> WeightedGraph

Every edge of g with weight 1.

Source

pub fn num_vertices(&self) -> usize

Number of vertices.

Source

pub fn num_edges(&self) -> usize

Number of edges.

Source

pub fn total_weight(&self) -> u64

Sum of all edge weights.

Source

pub fn max_weight_at(&self, u: usize) -> u8

The largest weight of an edge at u, or 0 if it has none.

Source

pub fn weight(&self, u: usize, v: usize) -> u8

The weight of {u, v}, or 0 if it is not an edge.

Source

pub fn row(&self, u: usize) -> &[u8] ⓘ

Row u of the weight matrix.

Source

pub fn neighbors(&self, u: usize) -> &[u32]

The neighbors of u, in ascending order.

Source

pub fn edges(&self) -> impl Iterator<Item = (usize, usize, u8)> + '_

Edges (u, v, weight) with u < v, in lexicographic order.

Source

pub fn induced_weight(&self, vertices: &[usize]) -> u64

Total weight of the edges among vertices, which must be distinct.

Source

pub fn structure(&self) -> Graph

The underlying unweighted graph.

Trait Implementations§

Source§

impl Clone for WeightedGraph

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for WeightedGraph

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for WeightedGraph

Source§

impl PartialEq for WeightedGraph

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl SearchGraph for WeightedGraph

Source§

type Row<'a> = &'a [u8]

A row of the adjacency (or weight) matrix.
Source§

fn num_vertices(&self) -> usize

Source§

fn neighbors(&self, u: usize) -> &[u32]

Neighbors of u, ascending.
Source§

fn adjacency_row(&self, u: usize) -> &[u8] ⓘ

Source§

fn edge_value(&self, u: usize, v: usize) -> i64

What the edge {u, v} contributes to the subgraph’s value: its weight, or 0 or 1.
Source§

fn objective_bound(&self) -> i64

The initial “best value so far” of an experiment: the sum of the degrees in sub_search, the total weight in wsub_search.
Source§

fn max_row_value(&self, u: usize) -> i64

An upper bound on AdjacencyRow::value in u’s row: 1 in an unweighted graph, the largest weight at u in a weighted one. The search uses it to skip rows that cannot hold a best move; the default, a bound too large to skip any, is always correct.
Source§

fn as_graph(&self) -> Option<&Graph>

The graph as an unweighted Graph, if it is one (regular searches need one).
Source§

fn neighbor_value(&self, u: usize, v: usize) -> i64

SearchGraph::edge_value for a known neighbor v of u.
Source§

impl StructuralPartialEq for WeightedGraph

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.