cellular encoding
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
#pragma once
|
||||
|
||||
#include "./Instruction.h"
|
||||
#include "../Cell.h"
|
||||
#include "../CelularEncoding.h"
|
||||
|
||||
namespace NeuralNetworks {
|
||||
namespace ConstructiveAlgorithms {
|
||||
namespace CelularEncoding {
|
||||
namespace Instruction {
|
||||
class Inclr : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
if(cell.getLinkRegister() == cell.getLinks().size() - 1) {
|
||||
cell.setLinkRegister(0);
|
||||
} else {
|
||||
cell.setLinkRegister(cell.getLinkRegister() + 1);
|
||||
}
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "IncLr";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class Declr : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
if(cell.getLinkRegister() == 0) {
|
||||
if(cell.getLinks().size() > 1) {
|
||||
cell.setLinkRegister(cell.getLinks().size() - 1);
|
||||
}
|
||||
} else {
|
||||
cell.setLinkRegister(cell.getLinkRegister() - 1);
|
||||
}
|
||||
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "Declr";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class ValPlus : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
cell.setLinkValue(cell.getLinkRegister(), 1.0);
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "Val+";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class ValMinus : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
cell.setLinkValue(cell.getLinkRegister(), -1.0);
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "Val-";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class Inc : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
cell.setLinkValue(cell.getLinkRegister(), cell.getLinkValue(cell.getLinkRegister()) + 1.0);
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "Inc";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class Dec : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
cell.setLinkValue(cell.getLinkRegister(), cell.getLinkValue(cell.getLinkRegister()) - 1.0);
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "Dec";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class Mult : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
cell.setLinkValue(cell.getLinkRegister(), cell.getLinkValue(cell.getLinkRegister()) * 2.0);
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "Mult";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class Div : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
cell.setLinkValue(cell.getLinkRegister(), cell.getLinkValue(cell.getLinkRegister()) * 0.5);
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "Div";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class On : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
cell.setLinkStatus(cell.getLinkRegister(), true);
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "On";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class Cyc : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
bool exists = false;
|
||||
for(std::size_t i = 0; i < cell.getLinks().size(); i++) {
|
||||
auto &link = cell.getLinks()[i];
|
||||
if(link.neuron == cell.getID()) {
|
||||
exists = true;
|
||||
cell.setLinkStatus(i,true);
|
||||
}
|
||||
}
|
||||
|
||||
if(!exists) {
|
||||
cell.addLink(Link(true, 1.0, cell.getID()));
|
||||
}
|
||||
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "Cyc";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class Off : public Instruction {
|
||||
public:
|
||||
virtual void run(Cell &cell, CelularEncoding &, const std::vector<double> &) override {
|
||||
cell.setLinkStatus(cell.getLinkRegister(), false);
|
||||
cell.setCodePointer(cell.getCodePointer()->c1);
|
||||
}
|
||||
|
||||
virtual std::size_t numberOfNodes() const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override {
|
||||
return "Off";
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user