101 lines
2.2 KiB
C++
101 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "./Instruction.h"
|
|
#include "../Cell.h"
|
|
#include "../CelularEncoding.h"
|
|
|
|
namespace NeuralNetworks {
|
|
namespace ConstructiveAlgorithms {
|
|
namespace CelularEncoding {
|
|
namespace Instruction{
|
|
class Par : public Instruction{
|
|
public:
|
|
virtual void run(Cell &cell, CelularEncoding &encoding, const std::vector<double> &) override {
|
|
Cell &newCell = encoding.addCell(cell.getCodePointer()->c2);
|
|
|
|
if(cell.isOutput()) {
|
|
newCell.setOutput();
|
|
}
|
|
|
|
if(cell.isInput()) {
|
|
newCell.setInput();
|
|
}
|
|
|
|
newCell.setLife(cell.getLife());
|
|
newCell.setBias(cell.getBias());
|
|
|
|
newCell.setLinks(cell.getLinks());
|
|
|
|
for(auto &cellI:encoding.getCells()) {
|
|
for( const Link &link: cellI->getLinks()) {
|
|
if(link.neuron == cell.getID()) {
|
|
Link newLink (link);
|
|
newLink.neuron=newCell.getID();
|
|
cellI->addLink(newLink);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
encoding.addCellToProcessingOrder(newCell.getID());
|
|
cell.setCodePointer(cell.getCodePointer()->c1);
|
|
}
|
|
|
|
virtual std::size_t numberOfNodes() const override {
|
|
return 2;
|
|
}
|
|
|
|
virtual std::string toString() const override {
|
|
return "Par";
|
|
}
|
|
|
|
protected:
|
|
private:
|
|
};
|
|
|
|
class Seq : public Instruction{
|
|
public:
|
|
virtual void run(Cell &cell, CelularEncoding &encoding, const std::vector<double> &) override {
|
|
Cell &newCell = encoding.addCell(cell.getCodePointer()->c2);
|
|
|
|
Link l(true, 1.0, cell.getID());
|
|
|
|
if(cell.isOutput()) {
|
|
newCell.setOutput();
|
|
cell.disableOutput();
|
|
}
|
|
|
|
newCell.addLink(l);
|
|
|
|
for(auto& cellIter:encoding.getCells()) {
|
|
if(cellIter->getID() != newCell.getID()) {
|
|
auto links = cellIter->getLinks();
|
|
for(auto& link: links) {
|
|
if(link.neuron==cell.getID()) {
|
|
link.neuron=newCell.getID();
|
|
}
|
|
}
|
|
cellIter->setLinks(links);
|
|
}
|
|
}
|
|
|
|
newCell.setLife(cell.getLife());
|
|
encoding.addCellToProcessingOrder(newCell.getID());
|
|
cell.setCodePointer(cell.getCodePointer()->c1);
|
|
//TODO: copy registers
|
|
}
|
|
|
|
virtual std::size_t numberOfNodes() const override {
|
|
return 2;
|
|
}
|
|
|
|
virtual std::string toString() const override {
|
|
return "Seq";
|
|
}
|
|
|
|
protected:
|
|
private:
|
|
};
|
|
}
|
|
}
|
|
}
|
|
} |