dlugolecki.net.pl
Dziennik
Polecane
Software
projects
/
genetic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Finished Roulette Selection.
[genetic.git]
/
src
/
fitness
/
wsti.h
diff --git
a/src/fitness/wsti.h
b/src/fitness/wsti.h
index 068590d94c815868b0d2bf6c04401932a47ef566..fa303b0eb97fd13d706e8206ec8c609ca47e86e9 100644
(file)
--- a/
src/fitness/wsti.h
+++ b/
src/fitness/wsti.h
@@
-5,45
+5,46
@@
#include "../gene.h"
#include "../gene.h"
+#include "fitness.h"
+
using namespace std;
namespace genetic {
/**
* Just an example Fitness function based on WSTI version.
*/
using namespace std;
namespace genetic {
/**
* Just an example Fitness function based on WSTI version.
*/
- template <
typename _Chromosome
>
- class WSTI {
+ template <
typename _Chromosome, typename _Value = double
>
+ class WSTI
: public Fitness<_Chromosome, _Value>
{
protected:
protected:
- _Chromosome chromosome;
-
float span_start;
float span_end;
float span_start;
float span_end;
-
doubl
e fenotype() {
- int
fen
= 0;
- int rat = 1;
- for (unsigned int i = 0; i < chromosome.get().size(); i++) {
-
fen = fen + chromosome.get()[i].get() * rat
;
- rat
= rat
* 2;
+
_Valu
e fenotype() {
+ int
_fenotype
= 0;
+ int rat
io
= 1;
+ for (unsigned int i = 0; i <
this->
chromosome.get().size(); i++) {
+
_fenotype = _fenotype + this->chromosome.get()[i].get() * ratio
;
+ rat
io = ratio
* 2;
}
}
- return
fen
;
+ return
_fenotype
;
}
}
-
doubl
e calculateFenotype() {
+
_Valu
e calculateFenotype() {
const unsigned int power2N = 1 << this->chromosome.get().size();
return span_start + (span_end - span_start) * this->fenotype() / power2N;
}
const unsigned int power2N = 1 << this->chromosome.get().size();
return span_start + (span_end - span_start) * this->fenotype() / power2N;
}
- public:
- WSTI(_Chromosome& chromosome, float start, float end) {
- this->chromosome = chromosome;
- this->span_start = start;
- this->span_end = end;
- }
-
double
calculate() {
-
doubl
e fenotype = this->calculateFenotype();
+
_Value do_
calculate() {
+
_Valu
e fenotype = this->calculateFenotype();
return (exp(fenotype) * sin(3.1415 * fenotype) + 1) / fenotype;
}
return (exp(fenotype) * sin(3.1415 * fenotype) + 1) / fenotype;
}
+ public:
+ WSTI(float start, float end)
+ : span_start(start), span_end(end) {
+ }
+ WSTI(_Chromosome& _chromosome, float start, float end)
+ : Fitness<_Chromosome>(_chromosome), span_start(start), span_end(end) {
+ }
};
}
};
}