Skip to content

Commit

Permalink
Update to 2024 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
vandenheuvel committed Nov 30, 2024
1 parent ac9576c commit eb37230
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "relp"
version = "0.2.6"
authors = ["Bram van den Heuvel <[email protected]>"]
edition = "2021"
edition = "2024"
description = "Rust Exact Linear Programming"
repository = "https://github.com/vandenheuvel/relp"
license = "GPL-3.0-only"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ where

let pivot_index = vector.binary_search_by_key(&self.pivot, |&(i, _)| i);
if let Ok(pivot_index) = pivot_index {
for &(j, ref value) in &self.values {
let has_index = vector.binary_search_by_key(&j, |&(jj, _)| jj);
for (j, value) in &self.values {
let has_index = vector.binary_search_by_key(j, |&(jj, _)| jj);

// TODO(PERFORMANCE): Sort once at the end instead of inserting all the time.
let difference = value * &vector[pivot_index].1;
update_value(difference, has_index, j, vector);
update_value(difference, has_index, *j, vector);
}

debug_assert!(vector.windows(2).all(|w| w[0].0 < w[1].0));
Expand Down Expand Up @@ -120,10 +120,9 @@ where
};

let difference = self.values.iter()
.filter_map(|&(j, ref value)| {
let row = j;
.filter_map(|(row, value)| {
spike[search_index..]
.binary_search_by_key(&row, |&(i, _)| i)
.binary_search_by_key(row, |&(i, _)| i)
.ok()
.map(|shift| {
value * &spike[search_index + shift].1
Expand Down
10 changes: 5 additions & 5 deletions src/data/linear_program/general_form/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ where
};

// Shift such that any lower bound is zero.
if let Some(ref mut lower) = variable.lower_bound {
if let Some(lower) = &mut variable.lower_bound {
variable.shift -= &*lower;
if let Some(ref mut upper) = variable.upper_bound {
if let Some(upper) = &mut variable.upper_bound {
*upper -= &*lower;
}

Expand Down Expand Up @@ -597,7 +597,7 @@ where

self.constraints.change_row_signs(&rows_to_negate);
for row in rows_to_negate {
match self.constraint_types[row] {
match &self.constraint_types[row] {
RangedConstraintRelation::Less => {
self.constraint_types[row] = RangedConstraintRelation::Greater;
self.b[row] *= -OF::one();
Expand All @@ -609,7 +609,7 @@ where
self.constraint_types[row] = RangedConstraintRelation::Less;
self.b[row] *= -OF::one();
},
RangedConstraintRelation::Range(ref range) => {
RangedConstraintRelation::Range(range) => {
let minus_old_lower_bound = range - &self.b[row];
self.b[row] = minus_old_lower_bound;
},
Expand Down Expand Up @@ -918,7 +918,7 @@ where
(Some(positive), Some(negative)) => positive - negative,
}
},
OriginalVariable::Removed(Solved(ref v)) => v.clone().into(),
OriginalVariable::Removed(Solved(v)) => v.clone().into(),
OriginalVariable::Removed(FunctionOfOthers { constant, coefficients }) => {
-coefficients.iter()
.map(|(j, coefficient)| {
Expand Down
2 changes: 1 addition & 1 deletion src/data/linear_program/general_form/presolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ where
}

let bound_to_edit = direction * coefficient.non_zero_signum();
if let Some(ref mut bound) = match bound_to_edit {
if let Some(bound) = match bound_to_edit {
BoundDirection::Lower => &mut self.activity_bounds[row].0,
BoundDirection::Upper => &mut self.activity_bounds[row].1,
} {
Expand Down
3 changes: 1 addition & 2 deletions src/data/linear_program/general_form/presolve/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,8 @@ where
}

// Remove changes that are not actually changes (might have been changed back and forth)
let existing_b = &self.general_form.b;
let b = self.b.into_iter()
.filter(|&(i, ref new_b)| new_b != &existing_b[i])
.filter(|(i, new_b)| new_b != &self.general_form.b[*i])
.collect();

let existing_constraint_types = &self.general_form.constraint_types;
Expand Down
4 changes: 2 additions & 2 deletions src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Error for Parse {
///
/// Option<&Error> which may be a `ParseErrorCause`.
fn source(&self) -> Option<&(dyn Error + 'static)> {
if let Some(Source::Other(ref error)) = self.source {
if let Some(Source::Other(error)) = &self.source {
Some(error.as_ref())
} else { None }
}
Expand Down Expand Up @@ -167,7 +167,7 @@ impl Parse {

/// Get all errors in the chain, leading up to this one.
fn trace(&self) -> Vec<String> {
let mut descriptions = if let Some(ref source) = self.source {
let mut descriptions = if let Some(source) = &self.source {
match source {
Source::FileLocation(line_number, line) => {
vec![format!("Caused at line {}: \t{}", line_number, line)]
Expand Down
2 changes: 1 addition & 1 deletion src/io/mps/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn replace_existing_with<OF: Ord>(option: &mut Option<OF>, new_value: OF, orderi
// Nothing would change if they would need to be equal, so this doesn't make sense.
debug_assert_ne!(ordering, Ordering::Equal);

if let Some(ref mut existing_value) = option {
if let Some(existing_value) = option {
if new_value.cmp(existing_value) == ordering {
*existing_value = new_value;
}
Expand Down

0 comments on commit eb37230

Please sign in to comment.