Skip to content

Commit 7f4f326

Browse files
committed
Satisfy clippy
1 parent 2064c46 commit 7f4f326

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

src/nn/gene.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ impl Gene {
5757
is_bias: bool,
5858
) -> Gene {
5959
Gene {
60-
in_neuron_id: in_neuron_id,
61-
out_neuron_id: out_neuron_id,
62-
weight: weight,
63-
enabled: enabled,
64-
is_bias: is_bias,
60+
in_neuron_id,
61+
out_neuron_id,
62+
weight,
63+
enabled,
64+
is_bias,
6565
}
6666
}
6767
/// Generate a weight

src/nn/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Genome for NeuralNetwork {
5757

5858
// average weight differences of matching genes
5959
let w1 = matching_genes.iter().fold(0.0, |acc, &m_gene| {
60-
acc + (m_gene.weight - &other.genes[other.genes.binary_search(m_gene).unwrap()].weight)
60+
acc + (m_gene.weight - other.genes[other.genes.binary_search(m_gene).unwrap()].weight)
6161
.abs()
6262
});
6363

@@ -121,7 +121,7 @@ impl NeuralNetwork {
121121
let tau = vec![1.0; neurons_len];
122122
let theta = self.get_bias();
123123

124-
let mut i = sensors.clone();
124+
let mut i = sensors;
125125

126126
if neurons_len < sensors_len {
127127
i.truncate(neurons_len);
@@ -144,9 +144,9 @@ impl NeuralNetwork {
144144
if sensors_len < neurons_len {
145145
let outputs_activations = activations.split_at(sensors_len).1.to_vec();
146146

147-
for n in 0..cmp::min(outputs_activations.len(), outputs.len()) {
148-
outputs[n] = outputs_activations[n];
149-
}
147+
let max_idx = cmp::min(outputs_activations.len(), outputs.len());
148+
outputs[..max_idx]
149+
.clone_from_slice(&outputs_activations[..max_idx])
150150
}
151151
}
152152

@@ -204,7 +204,7 @@ impl NeuralNetwork {
204204
if self.last_neuron_id == 0 {
205205
vec![0, 0]
206206
} else {
207-
(0..self.last_neuron_id + 1).choose_multiple(&mut rng, 2)
207+
(0..=self.last_neuron_id).choose_multiple(&mut rng, 2)
208208
}
209209
};
210210
self.add_connection(neuron_ids_to_connect[0], neuron_ids_to_connect[1]);

src/population.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<G: Genome> Population<G> {
5353
self.generate_offspring();
5454
}
5555
/// TODO
56-
pub fn evaluate_in(&mut self, environment: &mut Environment<G>) {
56+
pub fn evaluate_in(&mut self, environment: &mut dyn Environment<G>) {
5757
let champion = SpeciesEvaluator::new(environment).evaluate(&mut self.species);
5858

5959
if self.champion_fitness >= champion.fitness {
@@ -135,7 +135,7 @@ impl<G: Genome> Population<G> {
135135
}
136136

137137
for specie in &self.species {
138-
if result.len() < 1 {
138+
if result.is_empty() {
139139
result.push(specie.clone())
140140
} else if result.len() < 2 {
141141
if result[0].calculate_champion_fitness() < specie.calculate_champion_fitness() {
@@ -176,8 +176,8 @@ impl<G: Genome> Population<G> {
176176
new_specie = Some(specie);
177177
}
178178
};
179-
if new_specie.is_some() {
180-
self.species.push(new_specie.unwrap());
179+
if let Some(new_specie) = new_specie {
180+
self.species.push(new_specie);
181181
}
182182
}
183183
}

src/species_evaluator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ use std::sync::mpsc::{Receiver, Sender};
77
/// Calculate fitness and champions for a species
88
pub struct SpeciesEvaluator<'a, G> {
99
threads: usize,
10-
environment: &'a mut Environment<G>,
10+
environment: &'a mut dyn Environment<G>,
1111
}
1212

1313
impl<'a, G: Genome + Send> SpeciesEvaluator<'a, G> {
1414
/// Take an environment that will test organisms.
15-
pub fn new(environment: &mut Environment<G>) -> SpeciesEvaluator<G> {
15+
pub fn new(environment: &mut dyn Environment<G>) -> SpeciesEvaluator<G> {
1616
SpeciesEvaluator {
1717
threads: num_cpus::get(),
18-
environment: environment,
18+
environment,
1919
}
2020
}
2121

@@ -64,7 +64,7 @@ impl<'a, G: Genome + Send> SpeciesEvaluator<'a, G> {
6464
match organisms.split_at_mut(organisms_by_thread) {
6565
(thread_organisms, remaining_organisms) => {
6666
self.evaluate_organisms(thread_organisms, tx.clone(), scope);
67-
if remaining_organisms.len() > 0 {
67+
if !remaining_organisms.is_empty() {
6868
return self.dispatch_organisms(
6969
remaining_organisms,
7070
organisms_by_thread,

0 commit comments

Comments
 (0)