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
impl WeightedGraph
Sourcepub fn from_weighted_edges<I>(
n: usize,
edges: I,
) -> Result<WeightedGraph, Error>
pub fn from_weighted_edges<I>( n: usize, edges: I, ) -> Result<WeightedGraph, Error>
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.
Sourcepub fn from_scores<I>(
n: usize,
scores: I,
resolution: u32,
) -> Result<(WeightedGraph, f64), Error>
pub fn from_scores<I>( n: usize, scores: I, resolution: u32, ) -> Result<(WeightedGraph, f64), Error>
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.
Sourcepub fn scores(&self) -> Option<&[f64]>
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.
Sourcepub fn induced_score(&self, vertices: &[usize]) -> Option<f64>
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.
Sourcepub fn from_graph(g: &Graph) -> WeightedGraph
pub fn from_graph(g: &Graph) -> WeightedGraph
Every edge of g with weight 1.
Sourcepub fn num_vertices(&self) -> usize
pub fn num_vertices(&self) -> usize
Number of vertices.
Sourcepub fn total_weight(&self) -> u64
pub fn total_weight(&self) -> u64
Sum of all edge weights.
Sourcepub fn max_weight_at(&self, u: usize) -> u8
pub fn max_weight_at(&self, u: usize) -> u8
The largest weight of an edge at u, or 0 if it has none.
Sourcepub fn weight(&self, u: usize, v: usize) -> u8
pub fn weight(&self, u: usize, v: usize) -> u8
The weight of {u, v}, or 0 if it is not an edge.
Sourcepub fn edges(&self) -> impl Iterator<Item = (usize, usize, u8)> + '_
pub fn edges(&self) -> impl Iterator<Item = (usize, usize, u8)> + '_
Edges (u, v, weight) with u < v, in lexicographic order.
Sourcepub fn induced_weight(&self, vertices: &[usize]) -> u64
pub fn induced_weight(&self, vertices: &[usize]) -> u64
Total weight of the edges among vertices, which must be distinct.
Trait Implementations§
Source§impl Clone for WeightedGraph
impl Clone for WeightedGraph
Source§impl Debug for WeightedGraph
impl Debug for WeightedGraph
impl Eq for WeightedGraph
Source§impl PartialEq for WeightedGraph
impl PartialEq for WeightedGraph
Source§impl SearchGraph for WeightedGraph
impl SearchGraph for WeightedGraph
fn num_vertices(&self) -> usize
fn adjacency_row(&self, u: usize) -> &[u8] ⓘ
Source§fn edge_value(&self, u: usize, v: usize) -> i64
fn edge_value(&self, u: usize, v: usize) -> i64
{u, v} contributes to the subgraph’s value: its weight, or 0 or 1.Source§fn objective_bound(&self) -> i64
fn objective_bound(&self) -> i64
sub_search, the total weight in wsub_search.Source§fn max_row_value(&self, u: usize) -> i64
fn max_row_value(&self, u: usize) -> i64
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>
fn as_graph(&self) -> Option<&Graph>
Graph, if it is one (regular searches need one).impl StructuralPartialEq for WeightedGraph
Auto Trait Implementations§
impl Forget for WeightedGraph
impl Freeze for WeightedGraph
impl Move for WeightedGraph
impl RefUnwindSafe for WeightedGraph
impl Send for WeightedGraph
impl Sync for WeightedGraph
impl Unpin for WeightedGraph
impl UnsafeUnpin for WeightedGraph
impl UnwindSafe for WeightedGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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