-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor agent allocation #284
base: develop
Are you sure you want to change the base?
Conversation
Hey. The PR is ready for review? Cause right now it's only a "draft PR" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some fixes needed
circles = [] | ||
|
||
while len(agents_for_type) > 0: | ||
circle_size = circles_size_distribution.rvs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using numpy choice is much better
adults = [agent for agent in agents_for_type if agent.age > 18] | ||
non_adults = [agent for agent in agents_for_type if agent.age <= 18] | ||
|
||
adult_num = min(round(adult_type_distribution.rvs()), len(adults)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use numpy choice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the current implementation, the adult distribution is only available from data_holder a randint. Should I change it to a tuple of arrays, to be used with numpy choice?
# if there is place left in the circle, fill it with agents: | ||
while circle.agent_count < size: | ||
agent = agents_for_type.pop() | ||
assert agent not in circle.agents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Social circle already checks this. So this is not needed.
FOR ALL the asserts. instead, why not use hust add_many instead of add_agent each time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the assert was used to debug a specific issue. I haven't found a simpler way to select adults multiple adults, and remove them at once from adults and agents_for_type, so the loop would still be required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? You know how many are needed ( size - circle.agent_count) , you can take a cut out of agent_of_type use add_many.
Also pop sounds like a bad use, because you modify the outer list, a result which seems undesirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The outer list should be modified because those agents were allocated to a circle of the current connection type, and should not be selected for similar circles again. I guess this can be accomplished more efficiently through list slicing, instead of this original implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@denzo9 Check if it does so, what in actuall might happen with just slicing is that it will change your pointer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a solution that seems to work, using slicing and the del keyword
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still some work
# if there is place left in the circle, fill it with agents: | ||
while circle.agent_count < size: | ||
agent = agents_for_type.pop() | ||
assert agent not in circle.agents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? You know how many are needed ( size - circle.agent_count) , you can take a cut out of agent_of_type use add_many.
Also pop sounds like a bad use, because you modify the outer list, a result which seems undesirable.
No description provided.