-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: change fitness from function to struct #221
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, after merging this PR we should update text of our thesis (these diagrams with physical architecture)
use crate::ga::individual::Chromosome; | ||
|
||
pub trait Fitness<T: Chromosome> { | ||
fn apply(&self, chromosome: &T) -> f64; | ||
} | ||
|
||
pub struct FnBasedFitness<T: Chromosome> { | ||
fn_ptr: fn(&T) -> f64, | ||
} | ||
|
||
impl<T: Chromosome> FnBasedFitness<T> { | ||
pub fn new(fn_ptr: fn(&T) -> f64) -> Self { | ||
FnBasedFitness { fn_ptr } | ||
} | ||
} | ||
|
||
impl<T: Chromosome> Fitness<T> for FnBasedFitness<T> { | ||
fn apply(&self, chromosome: &T) -> f64 { | ||
(self.fn_ptr)(chromosome) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should try to avoid usage of pointers here (I know that it was implemented with function pointers before), as we spent a lot of time on making the whole to use static-dispatch only. Calling the most hot function in our system via pointer kinda defeats this purpose. But I guess, we should maybe create separate issue for that.
# Conflicts: # src/ga/builder/bistring.rs # src/ga/builder/realvalued.rs
Linked issues
Closes #217