Skip to content

Commit

Permalink
fix compile errors for changed rand method
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldmaida committed Nov 7, 2021
1 parent 4f0562d commit f852c51
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 26 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ All user visible changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/), as described
for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution.md)

## 0.5.0 : <unreleased>
## 0.6.0 : 2021-11-07

* bump `fixedbitset` optional dependency to version 0.4
* bump `rand` crate dependency to version 0.8
* bump `rand_xoshiro` crate dependency to version 0.6
* bump `proptest` crate dependency to version 1

### Fixed issues:

* fix index out of bounds exception in `OrderOneCrossover` and `PartiallyMappedCrossover` operations.
* fix typos in docs.

### Internal:

* replace deprecated method with new one in Criterion benchmark tests

## 0.5.0 : 2019-11-10

* bump `rand` crate dependency to version 0.7
* bump `rand_xoshiro` crate dependency to version 0.3
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "genevo"
version = "0.5.0"
version = "0.6.0"
authors = ["haraldmaida"]
license = "MIT/Apache-2.0"
description = """
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
genevo = "0.5"
genevo = "0.6"
```

If you are not using Rust 2018 edition add this to your crate root:
Expand Down
10 changes: 5 additions & 5 deletions examples/queens/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl RandomValueMutation for Pos {
{
Pos {
x: value.x,
y: rng.gen_range(min_value.y, max_value.y),
y: rng.gen_range(min_value.y..max_value.y),
}
}
}
Expand All @@ -117,7 +117,7 @@ impl GenomeBuilder<Positions> for QueensPositions {
(0..NUM_ROWS)
.map(|row| Pos {
x: row,
y: rng.gen_range(0, NUM_COLS),
y: rng.gen_range(0..NUM_COLS),
})
.collect()
}
Expand Down Expand Up @@ -179,7 +179,7 @@ fn main() {
for row in best_solution.solution.genome.as_board() {
println!(" {:?}", row);
}
},
}
Ok(SimResult::Final(step, processing_time, duration, stop_reason)) => {
let best_solution = step.result.best_solution;
println!("{}", stop_reason);
Expand All @@ -196,11 +196,11 @@ fn main() {
println!(" {:?}", row);
}
break;
},
}
Err(error) => {
println!("{}", error);
break;
},
}
}
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
//! searches for solutions of the
//! [N Queens Problem](https://en.wikipedia.org/wiki/Eight_queens_puzzle)
#![doc(html_root_url = "https://docs.rs/genevo/0.5.0")]
#![doc(html_root_url = "https://docs.rs/genevo/0.6.0")]
#![warn(
bare_trait_objects,
missing_copy_implementations,
Expand Down
2 changes: 1 addition & 1 deletion src/mutation/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ macro_rules! impl_random_value_mutation {
fn random_mutated<R>(_: $t, min_value: &$t, max_value: &$t, rng: &mut R) -> $t
where R: Rng + Sized
{
rng.gen_range(*min_value, *max_value)
rng.gen_range(*min_value..*max_value)
}
}
)*
Expand Down
6 changes: 3 additions & 3 deletions src/population/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
//! (0..8).map(|row|
//! Pos {
//! x: row,
//! y: rng.gen_range(0, 8)
//! y: rng.gen_range(0..8)
//! }
//! ).collect()
//! }
Expand Down Expand Up @@ -346,7 +346,7 @@ where
R: Rng + Sized,
{
(0..self.genome_length)
.map(|_| rng.gen_range(self.min_value.clone(), self.max_value.clone()))
.map(|_| rng.gen_range(self.min_value.clone()..self.max_value.clone()))
.collect()
}
}
Expand Down Expand Up @@ -400,7 +400,7 @@ mod smallvec_genome_builder {
R: Rng + Sized,
{
(0..self.genome_length)
.map(|_| rng.gen_range(self.min_value.clone(), self.max_value.clone()))
.map(|_| rng.gen_range(self.min_value.clone()..self.max_value.clone()))
.collect()
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/random/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn random_index_from_range<R>(rng: &mut R, min: usize, max: usize) -> usize
where
R: Rng + Sized,
{
rng.gen_range(min, max)
rng.gen_range(min..max)
}

/// Generates two cut points for a slice of given length using the given `Prng`.
Expand All @@ -65,8 +65,8 @@ where
assert!(max >= min + 4);
let max_slice = max - min - 2;
loop {
let cutpoint1 = rng.gen_range(min, max);
let cutpoint2 = rng.gen_range(min, max);
let cutpoint1 = rng.gen_range(min..max);
let cutpoint2 = rng.gen_range(min..max);
if cutpoint1 < cutpoint2 {
if cutpoint2 - cutpoint1 >= max_slice {
continue;
Expand All @@ -93,12 +93,12 @@ where
match n {
1 => {
cutpoints.push(random_index(rng, length));
},
}
2 => {
let (cp1, cp2) = random_cut_points(rng, length);
cutpoints.push(cp1);
cutpoints.push(cp2);
},
}
_ => {
let slice_len = length / n;
let mut start = 0;
Expand All @@ -121,7 +121,7 @@ where
end += slice_len;
}
}
},
}
}
cutpoints
}
Expand Down
12 changes: 6 additions & 6 deletions src/recombination/discrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
// for each value in the genotype
for locus in 0..genome_length {
// pick the value of a randomly chosen parent
let random = rng.gen_range(0, num_parents);
let random = rng.gen_range(0..num_parents);
let value = parents[random][locus].clone();
genome.push(value);
}
Expand Down Expand Up @@ -92,7 +92,7 @@ mod fixedbitset_uniform_cross_breeder {
// for each value in the genotype
for locus in 0..genome_length {
// pick the value of a randomly chosen parent
let random = rng.gen_range(0, num_parents);
let random = rng.gen_range(0..num_parents);
let value = parents[random][locus];
genome.set(locus, value);
}
Expand Down Expand Up @@ -129,7 +129,7 @@ mod smallvec_uniform_cross_breeder {
// for each value in the genotype
for locus in 0..genome_length {
// pick the value of a randomly chosen parent
let random = rng.gen_range(0, num_parents);
let random = rng.gen_range(0..num_parents);
let value = parents[random][locus].clone();
genome.push(value);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ where
let mut p_index = num_parents;
loop {
loop {
let index = rng.gen_range(0, num_parents);
let index = rng.gen_range(0..num_parents);
if index != p_index {
p_index = index;
break;
Expand Down Expand Up @@ -312,7 +312,7 @@ mod smallvec_multipoint_crossover {
let mut p_index = num_parents;
loop {
loop {
let index = rng.gen_range(0, num_parents);
let index = rng.gen_range(0..num_parents);
if index != p_index {
p_index = index;
break;
Expand Down Expand Up @@ -366,7 +366,7 @@ mod fixedbitset_multipoint_crossover {
let mut p_index = num_parents;
loop {
loop {
let index = rng.gen_range(0, num_parents);
let index = rng.gen_range(0..num_parents);
if index != p_index {
p_index = index;
break;
Expand Down
2 changes: 1 addition & 1 deletion tests/population_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn create_population_of_custom_genotype_uniform_at_random() {
(0..8)
.map(|row| Pos {
x: row,
y: rng.gen_range(0, 8),
y: rng.gen_range(0..8),
})
.collect()
}
Expand Down

0 comments on commit f852c51

Please sign in to comment.