Skip to content

Commit

Permalink
Add sample_cluster_id
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuzka committed Nov 21, 2023
1 parent ef711f4 commit 0390c05
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/popy/pop_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ def draw_sample(

samples = []
counter = 0
sample_cluster_id = 1
while counter < n:
if weight is None:
random_id = self.rng.choice(sample_level_ids)
else:
random_id = self.rng.choices(sample_level_ids, weights=weights, k=1)[0]

sample = df.loc[df[sample_level] == random_id, :]
# TODO: kann man hier nicht einfach `sample` einsetzen?
samples.append(df.loc[df[sample_level] == random_id, :])
sample["sample_cluster_id"] = sample_cluster_id

samples.append(sample)

counter += len(sample)
sample_cluster_id += 1

df_sample = pd.concat(samples).reset_index(drop=True)

Expand Down Expand Up @@ -161,7 +164,7 @@ def create_locations(
subtype_locations = [
location_cls(model=self.model) for _ in range(n_location_subtypes)
]

# Run setup-method for each location
for location in subtype_locations:
location.setup()
Expand All @@ -172,7 +175,7 @@ def create_locations(
# Assigning process:

# get all unique values to stick agents together
stick_values = set([location_dummy.stick_together(agent) for agent in subtype_affiliated_agents])
stick_values = {location_dummy.stick_together(agent) for agent in subtype_affiliated_agents}

# for each group of sticky agents
for stick_value in stick_values:
Expand All @@ -181,33 +184,33 @@ def create_locations(

# for each location of this subtype
for location in subtype_locations:

# if there are still enough free places available
if location.size is None or (location.size - location.n_affiliated_agents) >= len(sticky_agents):

# assign agents
for agent in sticky_agents:
location.add_agent(agent)
assigned = True

break

# if agents are not assigned and all locations are full
# TODO: hier verschiedene Möglichkeiten anbieten, was passieren soll, wenn Agenten übrigen bleiben
if not assigned:
if not assigned:
random_location = self.rng.choice(subtype_locations)
random_location.add_agent(agent)
assigned = True

# TODO:
# TODO:
# Warum gibt es keinen Fehler, wenn man ein Argument falsch schreibt? Habe gerade ewig
# nach einem Bug gesucht und letzt hatte ich nur das "j" in "objs" vergessen
self.agents = agents
self.locations = popy.LocationList(
model=self.model,
objs=locations,
)
)


return self.locations

Expand Down

0 comments on commit 0390c05

Please sign in to comment.