Skip to content

Commit 3639bce

Browse files
1. Fixed circular dependencies between header files using forward declarations:
- Resolved circular dependencies between neuron.h and neuron_reference.h - Fixed Direction vs NetworkDirection name conflicts 2. Made const-correctness fixes: - Updated method signatures to properly mark const methods - Updated parameter types to match function declarations 3. Fixed template and inheritance issues: - Fixed template specialization and implementation - Corrected method overrides and abstract class implementations 4. Fixed relation initialization: - Updated relation constructors to use proper parameters - Fixed handling of abstract classes in collections (std::vector) 5. Fixed naming conflicts: - Renamed Direction to NetworkDirection - Fixed include paths for different component hierarchies 6. Fixed file I/O operations: - Simplified read/write operations that were using undefined methods 7. Added missing method implementations: - Added implementations for methods declared in header files but missing from source files
1 parent e2ff8c8 commit 3639bce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+521
-284
lines changed

include/network/activation.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
#include "network/model_provider.h"
1010
#include "network/neuron.h"
1111
#include "network/bs_type.h"
12-
#include "network/binding_signal.h"
13-
#include "network/link.h"
14-
#include "network/fired.h"
12+
// Forward declarations to avoid circular includes
13+
class BindingSignal;
14+
class Link;
15+
class Fired;
16+
class Synapse;
17+
class LinkDefinition;
18+
class ActivationKey;
1519

1620
#include <map>
1721
#include <set>
@@ -23,7 +27,7 @@ class Activation : public Obj, public Element, public ModelProvider {
2327
public:
2428
static const std::function<bool(Activation*, Activation*)> ID_COMPARATOR;
2529

26-
Activation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType, BindingSignal*> bindingSignals);
30+
Activation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType*, BindingSignal*> bindingSignals);
2731
virtual ~Activation();
2832

2933
// Implementation of Obj virtual methods
@@ -34,12 +38,12 @@ class Activation : public Obj, public Element, public ModelProvider {
3438
Activation* getParent() const;
3539
void addOutputLink(Link* l);
3640
virtual void addInputLink(Link* l) = 0;
37-
BindingSignal* getBindingSignal(BSType s) const;
38-
std::map<BSType, BindingSignal*> getBindingSignals() const;
39-
bool hasConflictingBindingSignals(std::map<BSType, BindingSignal*> targetBindingSignals) const;
40-
bool isConflictingBindingSignal(BSType s, BindingSignal* targetBS) const;
41-
bool hasNewBindingSignals(std::map<BSType, BindingSignal*> targetBindingSignals) const;
42-
Activation* branch(std::map<BSType, BindingSignal*> bindingSignals);
41+
BindingSignal* getBindingSignal(BSType* s) const;
42+
std::map<BSType*, BindingSignal*> getBindingSignals() const;
43+
bool hasConflictingBindingSignals(std::map<BSType*, BindingSignal*> targetBindingSignals) const;
44+
bool isConflictingBindingSignal(BSType* s, BindingSignal* targetBS) const;
45+
bool hasNewBindingSignals(std::map<BSType*, BindingSignal*> targetBindingSignals) const;
46+
Activation* branch(std::map<BSType*, BindingSignal*> bindingSignals);
4347
void linkOutgoing();
4448
void linkOutgoing(Synapse* targetSyn);
4549
void propagate(Synapse* targetSyn);
@@ -75,7 +79,7 @@ class Activation : public Obj, public Element, public ModelProvider {
7579
int id;
7680
Neuron* neuron;
7781
Document* doc;
78-
std::map<BSType, BindingSignal*> bindingSignals;
82+
std::map<BSType*, BindingSignal*> bindingSignals;
7983
Activation* parent;
8084
long created;
8185
long fired;

include/network/activation_definition.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#define NETWORK_ACTIVATION_DEFINITION_H
33

44
#include "network/node_definition.h"
5+
#include "fields/type.h"
56

6-
class ActivationDefinition : public NodeDefinition {
7+
class ActivationDefinition : public Type {
78
public:
8-
ActivationDefinition();
9+
ActivationDefinition(TypeRegistry* registry, const std::string& name);
910
virtual ~ActivationDefinition();
1011

1112
// Add any additional methods or members specific to ActivationDefinition here

include/network/activation_key.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class ActivationKey {
1313
};
1414

1515
struct ActivationKeyComparator {
16-
bool operator()(ActivationKey* a, ActivationKey* b) const {
17-
if(a->getNeuronId() != b->getNeuronId())
18-
return a->getNeuronId() < b->getNeuronId();
16+
bool operator()(const ActivationKey& a, const ActivationKey& b) const {
17+
if(a.getNeuronId() != b.getNeuronId())
18+
return a.getNeuronId() < b.getNeuronId();
1919
else
20-
return a->getActId() < b->getActId();
20+
return a.getActId() < b.getActId();
2121
}
2222
};
2323

include/network/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef NETWORK_CONFIG_H
22
#define NETWORK_CONFIG_H
33

4+
#include <string>
5+
46
class Config {
57
public:
68
Config();

include/network/conjunctive_activation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
class ConjunctiveActivation : public Activation {
88
public:
9-
ConjunctiveActivation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType, BindingSignal*> bindingSignals);
9+
ConjunctiveActivation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType*, BindingSignal*> bindingSignals);
1010
virtual ~ConjunctiveActivation();
1111

1212
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
1313

1414
void linkIncoming(Activation* excludedInputAct) override;
15+
void linkIncoming(Synapse* targetSyn, Activation* excludedInputAct);
1516
void addInputLink(Link* l) override;
1617
std::vector<Link*> getInputLinks() const override;
1718

include/network/conjunctive_synapse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ConjunctiveSynapse : public Synapse {
99
ConjunctiveSynapse(SynapseDefinition* type, Neuron* input, Neuron* output);
1010

1111
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
12-
Obj* followSingleRelation(const Relation* rel) override;
12+
Obj* followSingleRelation(const Relation* rel) const override;
1313
/*
1414
void write(DataOutput* out) override;
1515
void readFields(DataInput* in, TypeRegistry* tr) override;

include/network/direction.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@
99
#include "network/bs_type.h"
1010
#include "network/transition.h"
1111

12-
class Direction {
12+
class NetworkDirection {
1313
public:
14-
virtual ~Direction() = default;
15-
virtual Direction* invert() = 0;
14+
virtual ~NetworkDirection() = default;
15+
virtual NetworkDirection* invert() = 0;
1616
virtual Neuron* getNeuron(Model* m, Synapse* s) = 0;
1717
virtual Activation* getActivation(Link* l) = 0;
1818
virtual int getOrder() = 0;
1919
virtual BSType* transition(BSType* s, Transition* t) = 0;
20+
21+
static NetworkDirection* INPUT;
22+
static NetworkDirection* OUTPUT;
23+
/*
2024
virtual void write(DataOutput* out) = 0;
2125
22-
static Direction* read(DataInput* in);
26+
static NetworkDirection* read(DataInput* in);
27+
*/
2328
};
2429

2530
#endif // NETWORK_DIRECTION_H

include/network/disjunctive_activation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class DisjunctiveActivation : public Activation {
88
public:
9-
DisjunctiveActivation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType, BindingSignal*> bindingSignals);
9+
DisjunctiveActivation(ActivationDefinition* t, Activation* parent, int id, Neuron* n, Document* doc, std::map<BSType*, BindingSignal*> bindingSignals);
1010
virtual ~DisjunctiveActivation();
1111

1212
RelatedObjectIterable* followManyRelation(Relation* rel) const override;

include/network/disjunctive_synapse.h

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

1111
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
12-
Obj* followSingleRelation(const Relation* rel) override;
12+
Obj* followSingleRelation(const Relation* rel) const override;
1313

14-
void link(Model* m) override;
14+
void link(Model* m);
1515

1616
private:
1717
bool propagable;

include/network/edge_definition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "network/typedefs.h"
55

6-
class EdgeDefinition : public Type {
6+
class EdgeDefinition {
77
public:
88
EdgeDefinition();
99
virtual ~EdgeDefinition();

include/network/element_step.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#ifndef NETWORK_ELEMENT_STEP_H
22
#define NETWORK_ELEMENT_STEP_H
33

4-
#include "network/step.h"
5-
#include "element.h"
6-
#include "queue_provider.h"
7-
#include "fired_queue_key.h"
4+
#include "fields/step.h"
5+
#include "network/element.h"
6+
#include "fields/queue_provider.h"
7+
#include "network/fired_queue_key.h"
88

99
class ElementStep : public Step {
1010
public:
1111
ElementStep(Element* element);
1212
Queue* getQueue() const override;
1313
void createQueueKey(long timestamp, int round) override;
1414
virtual const ProcessingPhase& getPhase() const override = 0; // Make this pure virtual for derived classes
15-
Element* getElement();
16-
std::string toString() const override;
15+
Element* getElement() const;
16+
std::string toString() const;
1717

1818
private:
1919
Element* element;

include/network/fired.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Fired : public Step {
1616
void process() override;
1717
void updateNet(double net);
1818
const Phase& getPhase() const override;
19-
Activation* getElement();
19+
Activation* getElement() const;
2020
Queue* getQueue() const override;
2121
std::string toString() const;
2222
bool isQueued() const;

include/network/fired_queue_key.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class FiredQueueKey : public QueueKey {
1212

1313
long getFired() const;
1414
long getCreated() const;
15-
std::string toString() const override;
16-
int compareTo(QueueKey* qk) const override;
15+
std::string toString() const;
16+
int compareTo(QueueKey* qk) const;
1717

1818
private:
1919
static const std::function<int(const FiredQueueKey*, const FiredQueueKey*)> COMPARATOR;

include/network/inhibitory_activation.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class InhibitoryActivation : public Activation {
1515
void addInputLink(Link* l) override;
1616
Link* getInputLink(int bsId) const;
1717
int getInputKey(Link* l) const;
18-
void addOutputLink(Link* l) override;
18+
void addOutputLink(Link* l);
1919
Link* getOutputLink(int bsId) const;
2020
int getOutputKey(Link* l) const;
2121
void linkIncoming(Activation* excludedInputAct) override;
2222
std::vector<Link*> getInputLinks() const override;
23-
std::vector<Link*> getOutputLinks() const override;
24-
Link* getCorrespondingInputLink(const Link* l) const override;
25-
Link* getCorrespondingOutputLink(const Link* l) const override;
23+
std::vector<Link*> getOutputLinks() const;
24+
Link* getCorrespondingInputLink(const Link* l) const;
25+
Link* getCorrespondingOutputLink(const Link* l) const;
2626

2727
private:
2828
std::map<int, Link*> inputLinks;

include/network/input.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include "network/direction.h"
55
#include <string>
66

7-
class Input : public Direction {
7+
class NetworkInput : public NetworkDirection {
88
public:
9-
Direction* invert() override;
9+
NetworkDirection* invert() override;
1010

1111
template <typename I>
1212
I getInput(I from, I to);
@@ -18,8 +18,8 @@ class Input : public Direction {
1818
Activation* getActivation(Link* l) override;
1919
BSType* transition(BSType* s, Transition* trns) override;
2020
int getOrder() override;
21-
void write(std::ostream& out) override;
22-
std::string toString() override;
21+
// void write(std::ostream& out) override;
22+
std::string toString();
2323
};
2424

2525
#endif // NETWORK_INPUT_H

include/network/link_definition.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ class LinkDefinition : public Type {
2424
static const RelationOne SYNAPSE;
2525
static const RelationOne CORRESPONDING_INPUT_LINK;
2626
static const RelationOne CORRESPONDING_OUTPUT_LINK;
27-
static const std::vector<Relation> RELATIONS;
27+
// We can't use vector of abstract class Relation directly
28+
// static const std::vector<Relation> RELATIONS;
2829

2930
LinkDefinition(TypeRegistry* registry, const std::string& name);
3031

31-
std::vector<Relation> getRelations() const;
32+
std::vector<Relation*> getRelations() const;
3233
Link* instantiate(Synapse* synapse, Activation* input, Activation* output);
3334

3435
SynapseDefinition* getSynapse() const;

include/network/model.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Model : public Queue {
2020
long createNeuronId();
2121
void registerDocument(Document* doc);
2222
void deregisterDocument(Document* doc);
23-
long getLowestDocumentId();
23+
long getLowestDocumentId() const;
2424
void addToN(int l);
2525
long getN() const;
2626
void setN(long n);
@@ -51,8 +51,8 @@ class Model : public Queue {
5151
std::map<long, Neuron*> activeNeurons;
5252
std::map<long, Document*> documents;
5353
long lastProcessedDocument;
54-
std::mutex documentMutex;
55-
std::mutex neuronMutex;
54+
mutable std::mutex documentMutex;
55+
mutable std::mutex neuronMutex;
5656
};
5757

5858
#endif // NETWORK_MODEL_H

include/network/neuron.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77
#include "network/element.h"
88
#include "network/model_provider.h"
99
#include "network/read_write_lock.h"
10-
#include "network/neuron_reference.h"
11-
#include "network/synapse.h"
10+
#include "network/ref_type.h" // Include RefType enum
11+
12+
// Forward declarations to break circular dependencies
13+
class Activation;
14+
class Synapse;
15+
class BSType;
16+
class BindingSignal;
17+
class Document;
18+
class NeuronReference; // Forward declare NeuronReference
1219
#include <map>
1320
#include <set>
1421
#include <vector>
@@ -20,9 +27,11 @@ class Neuron : public Obj, public Element, public ModelProvider {
2027
Neuron(NeuronDefinition* type, Model* model);
2128

2229
RelatedObjectIterable* followManyRelation(Relation* rel) const override;
23-
Obj* followSingleRelation(const Relation* rel) override;
30+
Obj* followSingleRelation(const Relation* rel) const override;
2431
long getId() const;
2532
void updatePropagable(Neuron* n, bool isPropagable);
33+
void addPropagable(Neuron* n);
34+
void removePropagable(Neuron* n);
2635
void wakeupPropagable();
2736
std::set<NeuronReference*> getPropagable() const;
2837
int getNewSynapseId();
@@ -38,6 +47,8 @@ class Neuron : public Obj, public Element, public ModelProvider {
3847
void removeInputSynapse(Synapse* s);
3948
void addOutputSynapse(Synapse* s);
4049
void removeOutputSynapse(Synapse* s);
50+
std::vector<Synapse*> getInputSynapses() const;
51+
std::vector<Synapse*> getOutputSynapses() const;
4152
std::vector<Synapse*> getInputSynapsesAsStream() const;
4253
std::vector<Synapse*> getOutputSynapsesAsStream() const;
4354
Synapse* getOutputSynapse(Neuron* n) const;
@@ -78,7 +89,7 @@ class Neuron : public Obj, public Element, public ModelProvider {
7889
std::map<long, Synapse*> outputSynapses;
7990
std::map<long, NeuronReference*> propagable;
8091
int refCount;
81-
int refCountByType[RefType::OTHER + 1];
92+
int refCountByType[static_cast<int>(RefType::OTHER) + 1];
8293
long lastUsed;
8394
bool modified;
8495
};

include/network/neuron_definition.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class NeuronDefinition : public Type {
1717
static const RelationMany INPUT;
1818
static const RelationMany OUTPUT;
1919
static const RelationMany ACTIVATION;
20-
static const std::vector<Relation> RELATIONS;
20+
// Cannot store abstract class Relation in vector, need to use pointers instead
21+
// static const std::vector<Relation> RELATIONS;
2122

2223
NeuronDefinition(TypeRegistry* registry, const std::string& name);
2324

include/network/neuron_reference.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#ifndef NETWORK_NEURON_REFERENCE_H
22
#define NETWORK_NEURON_REFERENCE_H
33

4-
#include "neuron.h"
54
#include "ref_type.h"
65
#include "model.h"
6+
// Forward declaration to break circular dependency
7+
class Neuron;
78

89
class NeuronReference {
910
public:
@@ -13,6 +14,10 @@ class NeuronReference {
1314
long getId() const;
1415
Neuron* getRawNeuron() const;
1516

17+
// Non-template method for backward compatibility
18+
Neuron* getNeuron(Model* m);
19+
20+
// Template method for different neuron types
1621
template <typename N>
1722
N* getNeuron(Model* m);
1823

0 commit comments

Comments
 (0)