As soon as I saw this open source document, I thought that the best way to replicate your code would be to use a
Python class. After having replicated and extended the paper arxiv link here, using a
class, I saw this question here that uses loops.
I still think that when one sees the problem of stable marriage, an agent comes to mind as a solution. I would like to ask the community if my implementation is solid and pythonic.
The central point is a
Class of people as below The idea is that all the functionality: send messages, receive messages, maintain the classification of other group preferences, store partners, match and divorce is a single class of agent.
Then, another GitHub / BAFurtado / HISMP / main.py code calls the class, generates the agents and applies the conditions.
The biggest advantage, I see, is the flexibility to adapt and change the class. Therefore, I extended the problem of instability with the possibility that any of the agents (belonging to any of the groups: Man or Woman) could be active messengers. I also included a
I j signal that informs me if a given agent has successfully sent a message to all the members of the other group.
I would be happy to hear your opinions and suggestions.
"" "Main class of agents. Be it males or females I am ready to be ACTIVE or PASSIVE agents (see the attached document in arXiv) "" import numpy as np Person of class: def __init __ (self, name, active): self.id = name self.j = 0 self.my_ranking = None self.my_partner = None self.my_energy = None self.status = active self.messaged = False Def classification (self, other_group): group = other_group.copy () np.random.shuffle (group) self.my_ranking = group definitive party (own, candidate): self.my_partner = candidate Div divorce (auto): self.my_partner = None def send_msg (auto): yes self.status == True: yes self.my_partner == None: for i in the range (self.j, len (self.my_ranking)): result = self.my_ranking[self.j].receive_msg (self) self.j + = 1 yes self.j == len (self.my_ranking): self.messaged = True if the result == & # 39; + & # 39 ;: break def receive_msg (auto, candidate): if self.my_partner is None: self.match (candidate) candidate.match (self) returns & # 39; + & # 39; elif [i.id for i in self.my_ranking].index (candidate.id) < [i.id for i in self.my_ranking].index (self.my_partner.id): self.my_partner.divorce () self.match (candidate) candidate.match (self) returns & # 39; + & # 39; plus: back & # 39; - & # 39; def energy (self): if self.my_partner is not None: self.my_energy = [i.id for i in self.my_ranking].index (self.my_partner.id) + 1 returns self.my_energy plus: self.my_energy = len (self.my_ranking) + 1 returns self.my_energy Man class (Person): happen Female class (Person): happen