AnimatLab  2
Test
CsSynapseIndividual.cpp
1 
7 #include "StdAfx.h"
8 
9 #include "CsSynapseGroup.h"
10 #include "CsNeuronGroup.h"
11 #include "CsNeuralModule.h"
12 #include "CsSynapseIndividual.h"
13 
14 namespace AnimatCarlSim
15 {
16 
24 {
25 }
26 
34 {
35 
36 try
37 {
38 }
39 catch(...)
40 {Std_TraceMsg(0, "Caught Error in desctructor of CsSynapseOneToOne\r\n", "", -1, false, true);}
41 }
42 
43 void CsSynapseIndividual::FromIdx(int iVal)
44 {
45  Std_IsAboveMin((int) -1, iVal, true, "FromIdx", true);
46  m_iFromIdx = iVal;
47  m_vSynapseKey.first = iVal;
48 }
49 
50 int CsSynapseIndividual::FromIdx() {return m_iFromIdx;}
51 
52 void CsSynapseIndividual::ToIdx(int iVal)
53 {
54  Std_IsAboveMin((int) -1, iVal, true, "ToIdx", true);
55  m_iToIdx = iVal;
56  m_vSynapseKey.second = iVal;
57 }
58 
59 int CsSynapseIndividual::ToIdx() {return m_iToIdx;}
60 
61 std::pair<int, int> CsSynapseIndividual::SynapseIndexKey() {return m_vSynapseKey;}
62 
63 void CsSynapseIndividual::SetCARLSimulation()
64 {
66  m_iFromIdx >= 0 && m_iToIdx >= 0 &&
67  m_lpFromNeuron->GroupID() >= 0 && m_lpToNeuron->GroupID() >= 0)
68  {
69  std::string strKey = this->GeneratorKey();
70 
71  //First try and find a generator if one exists
73 
74  //If one does not exist then create a new one.
75  if(!lpGen)
76  {
78  m_lpCsModule->AddConnectionGenerator(strKey, lpGen);
79  }
80 
81  //Add this synapse to the correct generator for later.
82  lpGen->SynapseMap()->insert(std::pair<std::pair<int, int>, CsSynapseIndividual *>(m_vSynapseKey, this));
83  }
84 }
85 
86 bool CsSynapseIndividual::SetCARLSimulation(int iFromIdx, int iToIdx, float& weight, float& maxWt, float& delay, bool& connected)
87 {
88  if(iFromIdx == m_iFromIdx && iToIdx == m_iToIdx)
89  {
90  weight = m_fltInitWt;
91  maxWt = m_fltMaxWt;
92  delay = m_iMinDelay;
93  connected = true;
94  }
95  else
96  connected = false;
97 
98  return connected;
99 }
100 
101 #pragma region DataAccesMethods
102 
103 bool CsSynapseIndividual::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
104 {
105  std::string strType = Std_CheckString(strDataType);
106 
107  if(CsSynapseGroup::SetData(strDataType, strValue, false))
108  return true;
109 
110  if(strType == "FROMIDX")
111  {
112  FromIdx(atoi(strValue.c_str()));
113  return true;
114  }
115 
116  if(strType == "TOIDX")
117  {
118  ToIdx(atoi(strValue.c_str()));
119  return true;
120  }
121 
122  //If it was not one of those above then we have a problem.
123  if(bThrowError)
124  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
125 
126  return false;
127 }
128 
129 void CsSynapseIndividual::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
130 {
131  CsSynapseGroup::QueryProperties(aryProperties);
132 
133  aryProperties.Add(new TypeProperty("FromIdx", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
134  aryProperties.Add(new TypeProperty("ToIdx", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
135 }
136 
137 #pragma endregion
138 
139 void CsSynapseIndividual::Load(CStdXml &oXml)
140 {
141  CsSynapseGroup::Load(oXml);
142 
143  oXml.IntoElem(); //Into Synapse Element
144 
145  FromIdx(oXml.GetChildInt("FromIdx", m_iFromIdx));
146  ToIdx(oXml.GetChildInt("ToIdx", m_iToIdx));
147 
148  oXml.OutOfElem(); //OutOf Synapse Element
149 }
150 
151 
152 } //AnimatCarlSim
153 
154 
155 
156 
157 
158 
Contains the classes for a firing rate neural model.
Definition: CsAdapter.cpp:14
bool m_bPlastic
connection type, either SYN_FIXED or SYN_PLASTIC
float m_fltInitWt
initial weight strength (arbitrary units); should be negative for inhibitory connections ...
Declares the CsNeuronGroup class.
CsNeuronGroup * m_lpFromNeuron
The pointer to pre-synaptic neuron.
unsigned char m_iMinDelay
the minimum delay allowed (ms)
std::pair< int, int > m_vSynapseKey
The synapse index key used in the synapse map.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
int m_iToIdx
The Jth neuron of the post-synaptic group to connect.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
AnimatSim::Environment::Structure * m_lpStructure
The pointer to this items parent Structure. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:46
Declares the synapse class.
CsSynapseIndividual()
Default constructor.
int m_iFromIdx
The Ith neuron of the pre-synaptic group to connect.
Firing rate synapse model.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
CsNeuronGroup * m_lpToNeuron
The pointer to post-synaptic neuron.
float m_fltMaxWt
upper bound on weight strength (arbitrary units); should be negative for inhibitory connections ...
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
Definition: AnimatBase.h:40
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual CsConnectionGenerator * FindConnectionGenerator(std::string strID, bool bThrowError=true)
Searches for an item with the specified ID and sets its index in the array.
CsNeuralModule * m_lpCsModule
Pointer to parent CsNeuralModule.