Skip to main content

MaxWeight

Struct MaxWeight 

Source
pub struct MaxWeight(/* private fields */);
Expand description

Max weight for maximization optimization and capacity problems.

The Max semiring provides a mathematical framework for solving maximization optimization problems where the goal is to find paths with maximum capacity or minimum bottleneck. This semiring uses maximum for path selection and minimum for path composition, making it the dual of the Min semiring and ideal for throughput optimization, resource maximization, and reliability analysis.

§Mathematical Definition

OperationDefinition
$a \oplus b$$\max(a, b)$
$a \otimes b$$\min(a, b)$
$\bar{0}$$-\infty$
$\bar{1}$$+\infty$

§Algebraic Properties

  • Commutative: Both $\oplus$ and $\otimes$ are commutative
  • Idempotent: $a \oplus a = a$ and $a \otimes a = a$
  • Path: $a \oplus b \in \{a, b\}$
  • Naturally Ordered: Forms a complete lattice structure
  • Dual: Exact dual of the Min semiring under negation

§Mathematical Semantics

  • Value Range: Real numbers $\mathbb{R} \cup \{\pm\infty\}$
  • Addition ($\oplus$): $\max(a, b)$ - selects path with better capacity
  • Multiplication ($\otimes$): $\min(a, b)$ - determines limiting bottleneck
  • Zero ($\bar{0}$): $-\infty$ - represents no path/infinite negative cost
  • One ($\bar{1}$): $+\infty$ - represents unlimited capacity

§Use Cases

§Network Throughput Optimization

use arcweight::prelude::*;

// Network link capacities (higher is better)
let link1_capacity = MaxWeight::new(100.0);  // 100 Mbps
let link2_capacity = MaxWeight::new(200.0);  // 200 Mbps
let link3_capacity = MaxWeight::new(50.0);   // 50 Mbps bottleneck

// Path capacity is limited by bottleneck (minimum capacity)
let path_capacity = link1_capacity
    .times(&link2_capacity)
    .times(&link3_capacity);  // min(100, min(200, 50)) = min(100, 50) = 50

// Choose between alternative paths (maximum throughput)
let path1 = MaxWeight::new(50.0);   // Path 1 throughput
let path2 = MaxWeight::new(75.0);   // Path 2 throughput
let best_path = path1.plus(&path2); // max(50, 75) = 75

§Resource Allocation and Scheduling

use arcweight::prelude::*;

// Available computational resources
let cpu_capacity = MaxWeight::new(80.0);    // 80% CPU available
let memory_capacity = MaxWeight::new(90.0); // 90% memory available
let disk_capacity = MaxWeight::new(60.0);   // 60% disk available

// System capacity limited by most constrained resource
let system_capacity = cpu_capacity
    .times(&memory_capacity)
    .times(&disk_capacity);  // min(80, min(90, 60)) = 60

// Choose between scheduling strategies
let strategy1 = MaxWeight::new(60.0);  // Conservative approach
let strategy2 = MaxWeight::new(85.0);  // Aggressive approach
let best_strategy = strategy1.plus(&strategy2);  // max(60, 85) = 85

§Signal Processing and Quality Analysis

use arcweight::prelude::*;

// Signal quality measurements (higher is better)
let signal_strength = MaxWeight::new(0.8);     // 80% signal strength
let noise_rejection = MaxWeight::new(0.9);     // 90% noise filtering
let channel_quality = MaxWeight::new(0.7);     // 70% channel quality

// Overall quality limited by weakest component
let system_quality = signal_strength
    .times(&noise_rejection)
    .times(&channel_quality);  // min(0.8, min(0.9, 0.7)) = 0.7

// Compare alternative signal paths
let primary_path = MaxWeight::new(0.7);
let backup_path = MaxWeight::new(0.6);
let best_signal = primary_path.plus(&backup_path);  // max(0.7, 0.6) = 0.7

§Financial Portfolio Optimization

use arcweight::prelude::*;

// Investment returns and risk constraints
let asset1_return = MaxWeight::new(0.12);      // 12% expected return
let asset2_return = MaxWeight::new(0.08);      // 8% expected return
let risk_constraint = MaxWeight::new(0.05);    // 5% maximum risk

// Portfolio return limited by risk constraints
let constrained_return1 = asset1_return.times(&risk_constraint);  // min(0.12, 0.05) = 0.05
let constrained_return2 = asset2_return.times(&risk_constraint);  // min(0.08, 0.05) = 0.05

// Choose best available return under constraints
let optimal_return = constrained_return1.plus(&constrained_return2);  // max(0.05, 0.05) = 0.05

§Manufacturing Quality Control

use arcweight::prelude::*;

// Quality scores from different production stages
let material_quality = MaxWeight::new(0.95);   // 95% material grade
let process_quality = MaxWeight::new(0.88);    // 88% process quality
let testing_quality = MaxWeight::new(0.92);    // 92% testing score

// Final product quality limited by weakest stage
let product_quality = material_quality
    .times(&process_quality)
    .times(&testing_quality);  // min(0.95, min(0.88, 0.92)) = 0.88

// Compare production lines
let line1_quality = MaxWeight::new(0.88);
let line2_quality = MaxWeight::new(0.91);
let best_line = line1_quality.plus(&line2_quality);  // max(0.88, 0.91) = 0.91

§Working with FSTs

use arcweight::prelude::*;

let weight1 = MaxWeight::new(10.0);
let weight2 = MaxWeight::new(20.0);

// Addition selects maximum (better capacity)
let sum = weight1 + weight2;  // max(10.0, 20.0) = 20.0
assert_eq!(sum, MaxWeight::new(20.0));

// Multiplication takes minimum (bottleneck constraint)
let product = weight1 * weight2;  // min(10.0, 20.0) = 10.0
assert_eq!(product, MaxWeight::new(10.0));

// Identity elements
assert_eq!(MaxWeight::zero(), MaxWeight::NEG_INFINITY);   // No path
assert_eq!(MaxWeight::one(), MaxWeight::INFINITY);       // Unlimited capacity

§Advanced Applications

§Load Balancing and Distribution

use arcweight::prelude::*;

// Server capacities (requests per second)
let server1_capacity = MaxWeight::new(1000.0);  // 1000 RPS
let server2_capacity = MaxWeight::new(1500.0);  // 1500 RPS
let server3_capacity = MaxWeight::new(800.0);   // 800 RPS

// Load balancer chooses server with highest available capacity
let available_capacity = server1_capacity
    .plus(&server2_capacity)
    .plus(&server3_capacity);  // max(1000, max(1500, 800)) = 1500

// Chain multiple load balancers (capacity limited by weakest link)
let lb1_capacity = MaxWeight::new(1500.0);
let lb2_capacity = MaxWeight::new(1200.0);
let chain_capacity = lb1_capacity.times(&lb2_capacity);  // min(1500, 1200) = 1200

§Security and Access Control

use arcweight::prelude::*;

// Security clearance levels (higher values = higher clearance)
let user_clearance = MaxWeight::new(3.0);      // Level 3 clearance
let resource_requirement = MaxWeight::new(2.0); // Level 2 required
let system_constraint = MaxWeight::new(4.0);    // Level 4 system max

// Access granted if user clearance meets all requirements
let effective_clearance = user_clearance
    .times(&resource_requirement)
    .times(&system_constraint);  // min(3, min(2, 4)) = 2

// Choose between access methods (highest security level available)
let method1_security = MaxWeight::new(2.0);
let method2_security = MaxWeight::new(3.0);
let best_security = method1_security.plus(&method2_security);  // max(2, 3) = 3

§Reliability and Fault Tolerance

use arcweight::prelude::*;

// Component reliability scores (1.0 = perfect, 0.0 = always fails)
let component1 = MaxWeight::new(0.99);  // 99% reliable
let component2 = MaxWeight::new(0.95);  // 95% reliable
let component3 = MaxWeight::new(0.98);  // 98% reliable

// System reliability limited by least reliable component
let system_reliability = component1
    .times(&component2)
    .times(&component3);  // min(0.99, min(0.95, 0.98)) = 0.95

// Redundant systems (choose most reliable)
let primary_system = MaxWeight::new(0.95);
let backup_system = MaxWeight::new(0.92);
let overall_reliability = primary_system.plus(&backup_system);  // max(0.95, 0.92) = 0.95

§Performance Characteristics

  • Arithmetic: Both max and min operations are O(1)
  • Memory: 4 bytes per weight (single f32)
  • Comparison: Fast floating-point comparison
  • Numerical: Standard IEEE 754 precision and edge case handling
  • Optimization: Highly optimizable by compilers

§Mathematical Properties

The Max semiring exhibits important algebraic properties:

  • Idempotent: max(a, a) = a and min(a, a) = a
  • Commutative: Operations are symmetric in arguments
  • Associative: Enables efficient parallel computation
  • Distributive: Follows semiring distributivity laws
  • Absorptive: Demonstrates lattice properties
  • Dual: Exact dual of the Min semiring under negation

§Integration with FST Algorithms

Max weights work with FST algorithms for maximization optimization:

  • Shortest Path: Finds paths with maximum total capacity
  • Composition: Combines throughput-optimized models
  • Determinization: Maintains maximization properties
  • Minimization: Preserves capacity characteristics

§See Also

Implementations§

Source§

impl MaxWeight

Source

pub const NEG_INFINITY: Self

Negative infinity (zero element)

Source

pub const INFINITY: Self

Positive infinity (one element)

Source

pub fn new(value: f32) -> Self

Create a new max weight

Trait Implementations§

Source§

impl Add for MaxWeight

Source§

type Output = MaxWeight

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for MaxWeight

Source§

fn clone(&self) -> MaxWeight

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 Copy for MaxWeight

Source§

impl Debug for MaxWeight

Source§

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

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

impl<'de> Deserialize<'de> for MaxWeight

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for MaxWeight

Source§

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

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

impl Eq for MaxWeight

Source§

impl Hash for MaxWeight

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul for MaxWeight

Source§

type Output = MaxWeight

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl NaturallyOrderedSemiring for MaxWeight

Source§

impl One for MaxWeight

Source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl Ord for MaxWeight

Source§

fn cmp(&self, other: &MaxWeight) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for MaxWeight

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for MaxWeight

Source§

fn partial_cmp(&self, other: &MaxWeight) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Semiring for MaxWeight

Source§

type Value = f32

Type of the underlying value
Source§

fn new(value: Self::Value) -> Self

Create a new weight from a value
Source§

fn value(&self) -> &Self::Value

Get the underlying value
Source§

fn properties() -> SemiringProperties

Semiring properties
Source§

fn plus(&self, other: &Self) -> Self

Semiring addition (⊕)
Source§

fn times(&self, other: &Self) -> Self

Semiring multiplication (⊗)
Source§

fn plus_assign(&mut self, other: &Self)

In-place semiring addition
Source§

fn times_assign(&mut self, other: &Self)

In-place semiring multiplication
Source§

fn is_zero(&self) -> bool

Check if weight is zero (additive identity)
Source§

fn is_one(&self) -> bool

Check if weight is one (multiplicative identity)
Source§

fn approx_eq(&self, other: &Self, _epsilon: f64) -> bool

Approximate equality for floating-point weights
Source§

impl Serialize for MaxWeight

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for MaxWeight

Source§

impl Zero for MaxWeight

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.

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

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
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> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,