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
| Operation | Definition |
|---|---|
$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) = aandmin(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
MinWeightfor dual minimization problemsTropicalWeightfor standard shortest-path optimization- Core Concepts - Custom Semirings for mathematical background
Implementations§
Trait Implementations§
impl Copy for MaxWeight
Source§impl<'de> Deserialize<'de> for MaxWeight
impl<'de> Deserialize<'de> for MaxWeight
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for MaxWeight
impl NaturallyOrderedSemiring for MaxWeight
Source§impl Ord for MaxWeight
impl Ord for MaxWeight
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for MaxWeight
impl PartialOrd for MaxWeight
Source§impl Semiring for MaxWeight
impl Semiring for MaxWeight
Source§fn properties() -> SemiringProperties
fn properties() -> SemiringProperties
Semiring properties
Source§fn plus_assign(&mut self, other: &Self)
fn plus_assign(&mut self, other: &Self)
In-place semiring addition
Source§fn times_assign(&mut self, other: &Self)
fn times_assign(&mut self, other: &Self)
In-place semiring multiplication
impl StructuralPartialEq for MaxWeight
Auto Trait Implementations§
impl Freeze for MaxWeight
impl RefUnwindSafe for MaxWeight
impl Send for MaxWeight
impl Sync for MaxWeight
impl Unpin for MaxWeight
impl UnsafeUnpin for MaxWeight
impl UnwindSafe for MaxWeight
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
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
impl<Q, K> Equivalent<K> for Q
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>
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 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>
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
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
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
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>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.