/* format "src dst delay weight\n" multiple src dst combinations are possible (?) */ #include #include #include #include #include #include #include "pla_set.hpp" #include "pointers.hpp" #include "property_composition.hpp" #include "simlimits.hpp" #include "time.hpp" #include "topology.hpp" #include "model.hpp" #include "mempool.hpp" using namespace std; typedef Ptr::ptr_t np_t; typedef Ptr::ptr_t sp_t; typedef Ptr::offset_t op_t; struct Connection { np_t src, dst; Weight::type weight; Time::type delay; }; map*> cons; PropertyComposition>, boost::mpl::pair>, boost::mpl::pair> >> pc; void init() { // check that pc time is 0.0 assert(pc.properties.data.data.timeLimit == 0.0); for (np_t i=0; i(); } void read() { cin >> skipws; while (!cin.eof()) { Connection c; // read from stream cin >> c.src >> c.dst >> c.delay >> c.weight; assert(!cin.fail()); cin >> ws; // first sanity check assert(c.src < maxNeurons); assert(c.dst < maxNeurons); assert(c.delay > 0.0); assert(c.weight != 0.0); // store (to sort) cons[c.src]->insert(make_pair(c.delay, c)); } } void addPseudo() { const Ptr::ptr_t half = maxNeurons/2; assert(numActualNeurons <= half); for (Ptr::ptr_t i=0; iinsert(make_pair(c.delay, c)); } } void setWeight(const sp_t synapse, Weight::type weight) { PLA_Set pla{Time{0}, Ptr{synapse}, weight}; pc.call(pla); } void writeTopology() { // fill topology tables Array &delay = *(new Array()); Array::ptr_t, maxNeurons * maxSynapsesPerNeuron> &target = *(new Array::ptr_t, maxNeurons * maxSynapsesPerNeuron>()); op_t currentSynapse[maxNeurons]; memset(currentSynapse, 0, sizeof(currentSynapse)); for (np_t i=0; i &l = *(cons[i]); assert(l.size() < maxSynapsesPerNeuron); // last synapse required for nil for (multimap::iterator k = l.begin(); k != l.end(); k++) { sp_t t = i * maxSynapsesPerNeuron + j; Connection &c = (*k).second; Time::type dt = c.delay; sp_t s = c.dst * maxSynapsesPerNeuron + currentSynapse[c.dst]++; delay.set (t, dt); target.set(t, s); setWeight(s, c.weight); j++; } // fill unused synapses for (; j::infinity()); currentSynapse[i]++; } } } void writeWeightSums() { Topology t; PropertyInstance weights; for (auto neuron : Ptr().childs()) { SumWeight::type weightSum = 0; for (auto synapse : neuron.childs()) { Weight::type weight = weights.data.getValue(Time{0}, synapse()); if (weight > 0 and weight < std::numeric_limits::infinity()) weightSum += weight; } PLA_Set s1{Time{0}, neuron, weightSum}; PLA_Set s2{Time{0}, neuron, weightSum}; pc.call(s1); pc.call(s2); } } int main() { init(); read(); addPseudo(); writeTopology(); writeWeightSums(); }