Skip to content

Commit 41bab99

Browse files
Implemented followManyRelation and followSingleRelation
1 parent a94387a commit 41bab99

18 files changed

+226
-20
lines changed

include/fields/rel_obj_iterator.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef REL_OBJ_ITERATOR_H
22
#define REL_OBJ_ITERATOR_H
33

4+
#include <vector>
5+
46
class Obj;
57

68
class RelatedObjectIterator {
@@ -31,6 +33,27 @@ class SingleObjectIterator : public RelatedObjectIterator {
3133
}
3234
};
3335

36+
class VectorObjectIterator : public RelatedObjectIterator {
37+
std::vector<Obj*> _objects;
38+
size_t _currentIndex;
39+
40+
public:
41+
VectorObjectIterator(const std::vector<Obj*>& objects)
42+
: _objects(objects), _currentIndex(0) {}
43+
44+
~VectorObjectIterator() = default;
45+
46+
bool hasNext() override {
47+
return _currentIndex < _objects.size();
48+
}
49+
50+
Obj* next() override {
51+
if (!hasNext()) {
52+
return nullptr;
53+
}
54+
return _objects[_currentIndex++];
55+
}
56+
};
3457

3558
template <typename MapType>
3659
class MapRelObjIterator : public RelatedObjectIterator {
@@ -79,9 +102,20 @@ class SingleObjectIterable : public RelatedObjectIterable {
79102
public:
80103
SingleObjectIterable(Obj* obj) : _obj(obj) {}
81104

82-
SingleObjectIterator* iterator() const {
105+
SingleObjectIterator* iterator() const override {
83106
return new SingleObjectIterator(_obj);
84107
}
85108
};
86109

110+
class VectorObjectIterable : public RelatedObjectIterable {
111+
std::vector<Obj*> _objects;
112+
113+
public:
114+
VectorObjectIterable(const std::vector<Obj*>& objects) : _objects(objects) {}
115+
116+
VectorObjectIterator* iterator() const override {
117+
return new VectorObjectIterator(_objects);
118+
}
119+
};
120+
87121
#endif //REL_OBJ_ITERATOR_H

include/network/activation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class Activation : public Obj, public Element, public ModelProvider {
2626
Activation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType, BindingSignal*> bindingSignals);
2727
virtual ~Activation();
2828

29+
// Implementation of Obj virtual methods
30+
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
31+
Obj* followSingleRelation(const Relation* rel) override;
32+
2933
ActivationKey getKey();
3034
Activation* getParent();
3135
void addOutputLink(Link* l);

include/network/conjunctive_activation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class ConjunctiveActivation : public Activation {
99
ConjunctiveActivation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType, BindingSignal*> bindingSignals);
1010
virtual ~ConjunctiveActivation();
1111

12+
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
13+
1214
void linkIncoming(Activation* excludedInputAct) override;
1315
void addInputLink(Link* l) override;
1416
std::vector<Link*> getInputLinks() override;

include/network/conjunctive_synapse.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class ConjunctiveSynapse : public Synapse {
88
ConjunctiveSynapse(SynapseDefinition* type);
99
ConjunctiveSynapse(SynapseDefinition* type, Neuron* input, Neuron* output);
1010

11+
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
12+
Obj* followSingleRelation(const Relation* rel) override;
13+
1114
void write(DataOutput* out) override;
1215
void readFields(DataInput* in, TypeRegistry* tr) override;
1316

include/network/disjunctive_activation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class DisjunctiveActivation : public Activation {
99
DisjunctiveActivation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType, BindingSignal*> bindingSignals);
1010
virtual ~DisjunctiveActivation();
1111

12+
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
13+
1214
void linkIncoming(Activation* excludedInputAct) override;
1315
void addInputLink(Link* l) override;
1416
std::vector<Link*> getInputLinks() override;

include/network/disjunctive_synapse.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class DisjunctiveSynapse : public Synapse {
88
DisjunctiveSynapse(SynapseDefinition* type);
99
DisjunctiveSynapse(SynapseDefinition* type, Neuron* input, Neuron* output);
1010

11+
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
12+
Obj* followSingleRelation(const Relation* rel) override;
13+
1114
void link(Model* m) override;
1215

1316
private:

include/network/inhibitory_activation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class InhibitoryActivation : public Activation {
1010
public:
1111
InhibitoryActivation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType*, BindingSignal*> bindingSignals);
1212

13+
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
14+
1315
void addInputLink(Link* l) override;
1416
Link* getInputLink(int bsId);
1517
int getInputKey(Link* l);

include/network/link.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class Link : public Obj, public Element, public ModelProvider {
2020
public:
2121
Link(LinkDefinition* type, Synapse* s, Activation* input, Activation* output);
2222

23-
RelatedObjectIterable* followManyRelation(Relation* rel) override;
24-
Obj* followSingleRelation(Relation* rel) override;
23+
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
24+
Obj* followSingleRelation(const Relation* rel) override;
2525
Timestamp getFired() override;
2626
Timestamp getCreated() override;
2727
Synapse* getSynapse();

include/network/neuron.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class Neuron : public Obj, public Element, public ModelProvider {
1919
Neuron(NeuronDefinition* type, Model* model, long id);
2020
Neuron(NeuronDefinition* type, Model* model);
2121

22-
RelatedObjectIterable* followManyRelation(Relation* rel) override;
23-
Obj* followSingleRelation(Relation* rel) override;
22+
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
23+
Obj* followSingleRelation(const Relation* rel) override;
2424
long getId() const;
2525
void updatePropagable(Neuron* n, bool isPropagable);
2626
void wakeupPropagable();

include/network/synapse.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Synapse : public Obj, public Element {
2323

2424
virtual ~Synapse() = default;
2525

26-
virtual RelatedObjectIterable* followManyRelation(Relation* rel) = 0;
27-
virtual Obj* followSingleRelation(Relation* rel) = 0;
26+
virtual RelatedObjectIterable* followManyRelation(Relation* rel) const = 0;
27+
virtual Obj* followSingleRelation(const Relation* rel) = 0;
2828

2929
int getSynapseId() const;
3030
void setSynapseId(int synapseId);

0 commit comments

Comments
 (0)