Skip to main content

fractional_knapsack

Function fractional_knapsack 

Source
pub fn fractional_knapsack(
    weights: &[f64],
    values: &[f64],
    capacity: f64,
) -> Result<f64, Error>
Expand description

Fractional knapsack maximum value.

Negative or NaN weights and NaN values are rejected with Err(Error::InvalidInput); a zero-weight item contributes its full value when that value is positive, since it consumes no capacity. Items with a non-positive value-to-weight ratio are never taken.