182 lines
3.4 KiB
C++
182 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#include <EvolutionaryAlgorithms/GeneticPrograming/CodeTree.h>
|
|
#include "./Instruction/Instruction.h"
|
|
|
|
#include <cstddef>
|
|
#include <vector>
|
|
|
|
namespace NeuralNetworks {
|
|
namespace ConstructiveAlgorithms {
|
|
namespace CelularEncoding {
|
|
class CelularEncoding;
|
|
|
|
class Link {
|
|
public:
|
|
Link(bool status_, float value_, std::size_t neuron_) : status(status_), value(value_), neuron(neuron_) {
|
|
|
|
}
|
|
|
|
bool status=false;
|
|
float value=0.0;
|
|
std::size_t neuron;
|
|
};
|
|
|
|
class Cell {
|
|
friend Instruction::Instruction;
|
|
|
|
public:
|
|
Cell(const Cell&)=delete;
|
|
Cell&operator=(const Cell&)=delete;
|
|
|
|
Cell(Cell &&r): id(r.id), codePtr(r.codePtr), _isOutput(r._isOutput), _isInput(r._isInput), alive(r.alive), life(r.life), bias(r.bias), links(r.links) {
|
|
|
|
}
|
|
|
|
Cell(const std::size_t& id_, const EvolutionaryAlgorithm::GeneticPrograming::CodeTree* codePtr_): id(id_), codePtr(codePtr_) {
|
|
|
|
}
|
|
|
|
void step(CelularEncoding&);
|
|
|
|
bool isAlive() const {
|
|
return alive;
|
|
};
|
|
|
|
void die() {
|
|
alive=false;
|
|
};
|
|
|
|
std::size_t getLife() const {
|
|
return life;
|
|
}
|
|
|
|
void setLife(const std::size_t &newLife) {
|
|
life=newLife;
|
|
}
|
|
|
|
float getBias() const {
|
|
return bias;
|
|
}
|
|
void setBias(const float &newBias) {
|
|
bias=newBias;
|
|
}
|
|
|
|
std::size_t getLinkRegister() const {
|
|
return linkRegister;
|
|
}
|
|
|
|
void setLinkRegister(const std::size_t &newLinkRegister) {
|
|
linkRegister=newLinkRegister;
|
|
}
|
|
|
|
const std::vector<Link>& getLinks() const {
|
|
return links;
|
|
}
|
|
|
|
void setLinks(const std::vector<Link> &links_) {
|
|
links=links_;
|
|
}
|
|
|
|
void addLink(const Link& l) {
|
|
for(auto &link:links) {
|
|
if(link.neuron ==l.neuron) {
|
|
link.value=l.value;
|
|
link.status=l.status;
|
|
return;
|
|
}
|
|
}
|
|
links.push_back(l);
|
|
}
|
|
|
|
bool getLinkStatus(const std::size_t index) const {
|
|
if(index < links.size()) {
|
|
return links[index].status;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void setLinkStatus(const std::size_t index, const bool &status) {
|
|
if(index < links.size()) {
|
|
links[index].status=status;
|
|
}
|
|
}
|
|
|
|
float getLinkValue(const std::size_t index) const {
|
|
if(index < links.size()) {
|
|
return links[index].value;
|
|
}
|
|
return 0.0;
|
|
}
|
|
|
|
void setLinkValue(const std::size_t index, const float &value) {
|
|
if(index < links.size()) {
|
|
links[index].value = value;
|
|
}
|
|
}
|
|
|
|
void setCodePointer(const EvolutionaryAlgorithm::GeneticPrograming::CodeTree *c) {
|
|
codePtr=c;
|
|
}
|
|
|
|
const EvolutionaryAlgorithm::GeneticPrograming::CodeTree* getCodePointer() const {
|
|
return codePtr;
|
|
}
|
|
|
|
std::size_t getID() const {
|
|
return id;
|
|
}
|
|
|
|
bool isOutput() const {
|
|
return _isOutput;
|
|
}
|
|
|
|
void setOutput() {
|
|
_isOutput=true;
|
|
}
|
|
void disableOutput() {
|
|
_isOutput=false;
|
|
}
|
|
|
|
bool isInput() const {
|
|
return _isInput;
|
|
}
|
|
|
|
void setInput() {
|
|
_isInput=true;
|
|
}
|
|
void disableInput() {
|
|
_isInput=false;
|
|
}
|
|
|
|
protected:
|
|
std::size_t id;
|
|
|
|
const EvolutionaryAlgorithm::GeneticPrograming::CodeTree *codePtr;
|
|
//const Code &code;
|
|
|
|
bool _isOutput=false;
|
|
bool _isInput=false;
|
|
|
|
bool alive=true;
|
|
std::size_t life=1;
|
|
float bias = 0.0;
|
|
|
|
std::size_t linkRegister=0;
|
|
|
|
std::vector<Link> links = std::vector<Link>();
|
|
/*
|
|
std::size_t codePosition;
|
|
std::size_t linkRegister;
|
|
|
|
std::size_t sigme;
|
|
std::size_t dyn;
|
|
std::size_t link;
|
|
std::size_t simplif;
|
|
*/
|
|
// 150 of paper
|
|
private:
|
|
};
|
|
}
|
|
}
|
|
} |