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

perf: Optimize generation of initial state for default fluents. #559

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions unified_planning/model/fluent.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,19 @@ def Iff(self, right):


def get_ith_fluent_exp(
objects_set: "up.model.mixins.ObjectsSetMixin",
fluent: "up.model.fluent.Fluent",
domain_sizes: List[int],
domains: List[List["up.model.FNode"]],
idx: int,
) -> "up.model.fnode.FNode":
"""Returns the ith ground fluent expression."""
quot = idx
rem = 0
actual_parameters = []
for i, p in enumerate(fluent.signature):
ds = domain_sizes[i]
ds = len(domains[i])
rem = quot % ds
quot //= ds
v = domain_item(objects_set, p.type, rem)
v = domains[i][rem]
actual_parameters.append(v)
return fluent(*actual_parameters)

Expand All @@ -276,10 +275,11 @@ def get_all_fluent_exp(
yield fluent.environment.expression_manager.FluentExp(fluent)
else:
ground_size = 1
domain_sizes = []
domains = []
for p in fluent.signature:
ds = domain_size(objects_set, p.type)
domain_sizes.append(ds)
domain = [domain_item(objects_set, p.type, i) for i in range(ds)]
domains.append(domain)
ground_size *= ds
for i in range(ground_size):
yield get_ith_fluent_exp(objects_set, fluent, domain_sizes, i)
yield get_ith_fluent_exp(fluent, domains, i)
Loading