Skip to content

Commit 654118e

Browse files
Compile fixes
1 parent ad79972 commit 654118e

File tree

4 files changed

+134
-27
lines changed

4 files changed

+134
-27
lines changed

include/network/activation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "network/element.h"
99
#include "network/model_provider.h"
1010
#include "network/neuron.h"
11+
#include "network/bs_type.h"
1112
#include "network/binding_signal.h"
1213
#include "network/link.h"
1314
#include "network/timestamp.h"

include/network/link_definition.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
#include "network/activation.h"
99
#include "network/link.h"
10-
#include "network/synapse.h"
1110

1211
#include <string>
1312
#include <vector>
1413

14+
class Link;
15+
class SynapseDefinition;
16+
17+
1518
class LinkDefinition : public Type {
1619
public:
1720
static const RelationSelf SELF;
@@ -36,7 +39,7 @@ class LinkDefinition : public Type {
3639
ActivationDefinition* getOutput() const;
3740
LinkDefinition* setOutput(ActivationDefinition* output);
3841

39-
std::string toString() const override;
42+
std::string toString() const;
4043

4144
private:
4245
SynapseDefinition* synapse;

include/network/synapse.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ class Synapse : public Obj, public Element {
5757
Neuron* getOutput() const;
5858
Neuron* getOutput(Model* m) const;
5959

60+
/*
6061
virtual void write(DataOutput* out) const = 0;
6162
static Synapse* read(DataInput* in, TypeRegistry* tr);
6263
virtual void readFields(DataInput* in, TypeRegistry* tr) = 0;
64+
*/
6365

6466
Timestamp getCreated() const override;
6567
Timestamp getFired() const override;
@@ -68,8 +70,8 @@ class Synapse : public Obj, public Element {
6870

6971
Queue* getQueue() const override;
7072

71-
std::string toString() const override;
72-
std::string toKeyString() const override;
73+
std::string toString() const;
74+
std::string toKeyString() const;
7375

7476
protected:
7577
int synapseId;

src/network/synapse.cpp

Lines changed: 124 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
11
#include "network/synapse.h"
2-
3-
Synapse::Synapse(SynapseDefinition* type) : type(type), synapseId(0), input(nullptr), output(nullptr), propagable(false) {}
4-
5-
Synapse::Synapse(SynapseDefinition* type, Neuron* input, Neuron* output) : type(type), synapseId(0), input(new NeuronReference(input, RefType::SYNAPSE_IN)), output(new NeuronReference(output, RefType::SYNAPSE_OUT)), propagable(false) {}
2+
#include "network/synapse_definition.h"
3+
#include <iostream>
4+
#include <stdexcept>
5+
#include <limits>
6+
7+
// Need to add the missing SynapseDefinition* type member to Synapse class
8+
// This will be a temporary fix until the proper header update is done
9+
10+
Synapse::Synapse(SynapseDefinition* type) : Obj(type), synapseId(0), input(nullptr), output(nullptr), propagable(false) {}
11+
12+
Synapse::Synapse(SynapseDefinition* type, Neuron* input, Neuron* output)
13+
: Obj(type), synapseId(0),
14+
input(new NeuronReference(input, RefType::SYNAPSE_IN)),
15+
output(new NeuronReference(output, RefType::SYNAPSE_OUT)),
16+
propagable(false)
17+
{
18+
link(input->getModel(), input, output);
19+
}
20+
21+
std::vector<Obj*> Synapse::followManyRelation(Relation* rel) {
22+
if (rel->getRelationId() == SynapseDefinition::LINK.getRelationId()) {
23+
// Return links - this would need implementation but returning empty for now
24+
return std::vector<Obj*>();
25+
} else {
26+
throw std::runtime_error("Invalid Relation");
27+
}
28+
}
29+
30+
Obj* Synapse::followSingleRelation(Relation* rel) {
31+
if (rel->getRelationId() == SynapseDefinition::SELF.getRelationId()) {
32+
return this;
33+
} else if (rel->getRelationId() == SynapseDefinition::INPUT.getRelationId()) {
34+
return getInput();
35+
} else if (rel->getRelationId() == SynapseDefinition::OUTPUT.getRelationId()) {
36+
return getOutput();
37+
} else {
38+
throw std::runtime_error("Invalid Relation");
39+
}
40+
}
641

742
int Synapse::getSynapseId() const {
843
return synapseId;
@@ -13,12 +48,27 @@ void Synapse::setSynapseId(int synapseId) {
1348
}
1449

1550
std::map<BSType*, BindingSignal*> Synapse::transitionForward(const std::map<BSType*, BindingSignal*>& inputBindingSignals) {
16-
// Implementation for transitioning forward
17-
return std::map<BSType*, BindingSignal*>(); // Placeholder
51+
std::map<BSType*, BindingSignal*> outputTransitions;
52+
auto transitions = static_cast<SynapseDefinition*>(getType())->getTransition();
53+
54+
for (auto t : transitions) {
55+
auto it = inputBindingSignals.find(t->from());
56+
if (it != inputBindingSignals.end()) {
57+
outputTransitions[t->to()] = it->second;
58+
}
59+
}
60+
61+
return outputTransitions;
1862
}
1963

2064
Synapse* Synapse::setPropagable(Model* m, bool propagable) {
65+
if (this->propagable != propagable) {
66+
input->getNeuron(m)->setModified();
67+
}
68+
69+
getInput(m)->updatePropagable(output->getNeuron(m), propagable);
2170
this->propagable = propagable;
71+
2272
return this;
2373
}
2474

@@ -27,7 +77,10 @@ bool Synapse::isPropagable() const {
2777
}
2878

2979
void Synapse::setModified(Model* m) {
30-
// Implementation for setting modified
80+
Neuron* n = getStoredAt()->getNeuron(m, this);
81+
if (n != nullptr) {
82+
n->setModified();
83+
}
3184
}
3285

3386
void Synapse::setInput(Neuron* n) {
@@ -39,34 +92,48 @@ void Synapse::setOutput(Neuron* n) {
3992
}
4093

4194
Synapse* Synapse::link(Model* m, Neuron* input, Neuron* output) {
42-
// Implementation for linking
95+
synapseId = output->getNewSynapseId();
96+
97+
setInput(input);
98+
setOutput(output);
99+
100+
link(m);
101+
43102
return this;
44103
}
45104

46105
void Synapse::link(Model* m) {
47-
// Implementation for linking
106+
input->getNeuron(m)->addOutputSynapse(this);
107+
output->getNeuron(m)->addInputSynapse(this);
48108
}
49109

50110
void Synapse::unlinkInput(Model* m) {
51-
// Implementation for unlinking input
111+
getInput(m)->removeOutputSynapse(this);
52112
}
53113

54114
void Synapse::unlinkOutput(Model* m) {
55-
// Implementation for unlinking output
115+
getOutput(m)->removeInputSynapse(this);
56116
}
57117

58118
Link* Synapse::createLink(Activation* input, Activation* output) {
59-
// Implementation for creating a link
60-
return nullptr; // Placeholder
119+
return createLink(input, transitionForward(input->getBindingSignals()), output);
61120
}
62121

63122
Link* Synapse::createLink(Activation* input, const std::map<BSType*, BindingSignal*>& bindingSignals, Activation* output) {
64-
// Implementation for creating a link with binding signals
65-
return nullptr; // Placeholder
123+
if (output->hasConflictingBindingSignals(bindingSignals)) {
124+
return nullptr;
125+
} else if (output->hasNewBindingSignals(bindingSignals)) {
126+
output = output->branch(bindingSignals);
127+
output->linkIncoming(input);
128+
}
129+
130+
return static_cast<SynapseDefinition*>(getType())
131+
->getLink()
132+
->instantiate(this, input, output);
66133
}
67134

68135
Direction* Synapse::getStoredAt() const {
69-
return nullptr; // Placeholder
136+
return static_cast<SynapseDefinition*>(getType())->getStoredAt();
70137
}
71138

72139
NeuronReference* Synapse::getInputRef() const {
@@ -78,33 +145,67 @@ NeuronReference* Synapse::getOutputRef() const {
78145
}
79146

80147
Neuron* Synapse::getInput() const {
81-
return input->getRawNeuron();
148+
if (!output || !output->getRawNeuron()) {
149+
return nullptr;
150+
}
151+
return getInput(output->getRawNeuron()->getModel());
82152
}
83153

84154
Neuron* Synapse::getInput(Model* m) const {
155+
if (!input) {
156+
return nullptr;
157+
}
85158
return input->getNeuron(m);
86159
}
87160

88161
Neuron* Synapse::getOutput() const {
89-
return output->getRawNeuron();
162+
if (!input || !input->getRawNeuron()) {
163+
return nullptr;
164+
}
165+
return getOutput(input->getRawNeuron()->getModel());
90166
}
91167

92168
Neuron* Synapse::getOutput(Model* m) const {
169+
if (!output) {
170+
return nullptr;
171+
}
93172
return output->getNeuron(m);
94173
}
95174

175+
Timestamp Synapse::getCreated() const {
176+
// We would need MIN Timestamp defined somewhere
177+
return Timestamp(0); // Using 0 as MIN for now
178+
}
179+
180+
Timestamp Synapse::getFired() const {
181+
// We would need MAX Timestamp defined somewhere
182+
return Timestamp(std::numeric_limits<long>::max()); // Using max long as MAX for now
183+
}
184+
96185
void Synapse::deleteSynapse(Model* m) {
97-
// Implementation for deleting a synapse
186+
std::cout << "Delete synapse: " << toString() << std::endl;
187+
188+
if (input) {
189+
getInput(m)->removeOutputSynapse(this);
190+
}
191+
if (output) {
192+
getOutput(m)->removeInputSynapse(this);
193+
}
98194
}
99195

100196
Queue* Synapse::getQueue() const {
101-
return nullptr; // Placeholder
197+
return nullptr; // Not implemented yet
102198
}
103199

104200
std::string Synapse::toString() const {
105-
return "Synapse: " + std::to_string(synapseId);
201+
return getType()->getName() +
202+
" in:[" + (input ? input->toKeyString() : "X") + "] " +
203+
" --> " +
204+
" out:[" + (output ? output->toKeyString() : "X") + "])";
106205
}
107206

108207
std::string Synapse::toKeyString() const {
109-
return "SynapseKey: " + std::to_string(synapseId);
110-
}
208+
return (input ? input->toKeyString() : "X") +
209+
" --> " +
210+
(output ? output->toKeyString() : "X");
211+
}

0 commit comments

Comments
 (0)