Skip to content
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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

denzo9
Copy link
Collaborator

@denzo9 denzo9 commented Apr 19, 2020

No description provided.

@denzo9 denzo9 requested a review from meirhalachmi April 19, 2020 20:57
@denzo9 denzo9 linked an issue Apr 19, 2020 that may be closed by this pull request
@meirhalachmi
Copy link
Collaborator

Hey. The PR is ready for review? Cause right now it's only a "draft PR"

@denzo9 denzo9 marked this pull request as ready for review April 20, 2020 08:37
@denzo9 denzo9 requested a review from tal-nc April 21, 2020 09:56
Copy link
Collaborator

@bgmoshe bgmoshe left a 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()
Copy link
Collaborator

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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use numpy choice

Copy link
Collaborator Author

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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

Copy link
Collaborator

@bgmoshe bgmoshe left a 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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor how we allocate agents to circles
3 participants