MatchedSynapse.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import copy
  2. from kalliope.core.NeuronParameterLoader import NeuronParameterLoader
  3. class MatchedSynapse(object):
  4. """
  5. This class represent a synapse that has matched an order send by an User.
  6. """
  7. def __init__(self, matched_synapse=None, matched_order=None, user_order=None):
  8. """
  9. :param matched_synapse: The synapse that has matched in the brain
  10. :param matched_order: The order from the synapse that have matched
  11. """
  12. # create a copy of the synapse. the received synapse come from the brain.
  13. self.synapse = matched_synapse
  14. # create a fifo list that contains all neurons to process
  15. self.neuron_fifo_list = self.synapse.neurons
  16. self.matched_order = matched_order
  17. self.parameters = NeuronParameterLoader.get_parameters(synapse_order=self.matched_order,
  18. user_order=user_order)
  19. # list of Neuron Module
  20. self.neuron_module_list = list()
  21. def __str__(self):
  22. returned_string = str()
  23. returned_string += str(self.synapse)
  24. returned_string += "answers: "
  25. for neuron_module in self.neuron_module_list:
  26. returned_string += str(neuron_module)
  27. return returned_string
  28. def serialize(self):
  29. """
  30. This method allows to serialize in a proper way this object
  31. :return: A dict of name and parameters
  32. :rtype: Dict
  33. """
  34. return {
  35. 'synapse_name': self.synapse.name,
  36. 'matched_order': self.matched_order,
  37. 'neuron_module_list': [e.serialize() for e in self.neuron_module_list]
  38. }