-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <vector> | ||
|
||
using namespace Tai; | ||
using namespace std; | ||
|
||
template <class Gene, class FitnessFunction> | ||
GeneticAlgorithm<Gene,FitnessFunction>::GeneticAlgorithm(const FitnessFunction& ff) : fitnessFunction(ff) | ||
{ | ||
} | ||
|
||
template <class Gene, class FitnessFunction> | ||
GeneticAlgorithm<Gene,FitnessFunction>::~GeneticAlgorithm() | ||
{ | ||
} | ||
|
||
template <class Gene, class FitnessFunction> | ||
void GeneticAlgorithm<Gene,FitnessFunction>::iterate() | ||
{ | ||
|
||
// Selection for crossover | ||
// Mutation | ||
// Fitness Calculation | ||
// Selection of next generation | ||
|
||
typename vector<Gene>::iterator gene_it = population.begin(); | ||
for (; gene_it != population.end(); ++gene_it) | ||
{ | ||
fitnessFunction.calculate(*gene_it); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef GENETICALGORITHM_H | ||
#define GENETICALGORITHM_H | ||
|
||
#include <vector> | ||
|
||
namespace Tai | ||
{ | ||
template <class Gene, class FitnessFunction> | ||
class GeneticAlgorithm | ||
{ | ||
public: | ||
GeneticAlgorithm(const FitnessFunction &); | ||
~GeneticAlgorithm(); | ||
|
||
void iterate(); | ||
|
||
typedef Gene GeneType; | ||
|
||
private: | ||
std::vector<Gene> population; | ||
FitnessFunction fitnessFunction; | ||
|
||
}; | ||
}; //namespace Tai | ||
|
||
#include "geneticalgorithm.cpp" | ||
|
||
#endif //GENETICALGORITHM_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "simplefitness.h" | ||
#include "simplegene.h" | ||
|
||
using namespace Tai; | ||
|
||
double SimpleFitness::calculate(const SimpleGene& gene) | ||
{ | ||
return 0.0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef TAI_SIMPLEFITNESS | ||
#define TAI_SIMPLEFITNESS | ||
|
||
namespace Tai | ||
{ | ||
// forward declaration | ||
class SimpleGene; | ||
|
||
class SimpleFitness | ||
{ | ||
public: | ||
double calculate(const SimpleGene&); | ||
}; | ||
}; //namespace Tai | ||
|
||
#endif //TAI_SIMPLEFITNESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "simplegene.h" | ||
|
||
using namespace Tai; | ||
using namespace std; | ||
|
||
|
||
SimpleGene::SimpleGene() | ||
{ | ||
} | ||
|
||
SimpleGene::~SimpleGene() | ||
{ | ||
} | ||
|
||
int SimpleGene::getLength() | ||
{ | ||
return 0; | ||
//return values.length; | ||
} | ||
|
||
void SimpleGene::mutate() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef TAI_SIMPLEGENE_H | ||
#define TAI_SIMPLEGENE_H | ||
|
||
#include <vector> | ||
|
||
namespace Tai | ||
{ | ||
class SimpleGene | ||
{ | ||
public: | ||
SimpleGene(); | ||
~SimpleGene(); | ||
|
||
int getLength(); | ||
void mutate(); | ||
|
||
private: | ||
std::vector<double> values; | ||
}; | ||
}; //namespace Tai | ||
|
||
#endif //TAI_SIMPLEGENE_H |