Skip to content

Commit

Permalink
bugfixes due to renaming agenda->outcome_space
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserfarouk committed Dec 1, 2023
1 parent 37d50e9 commit dbe814f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
8 changes: 5 additions & 3 deletions negmas/inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,17 @@ def calc_extra_stats(
Returns:
A dictionary with the compiled stats
"""
agenda, ufuns = self.outcome_space, self.ufuns
outcomes = tuple(agenda.enumerate_or_sample(max_cardinality=max_cardinality))
outcome_space, ufuns = self.outcome_space, self.ufuns
outcomes = tuple(
outcome_space.enumerate_or_sample(max_cardinality=max_cardinality)
)
frontier_utils, frontier_indices = pareto_frontier(
ufuns, outcomes=outcomes, sort_by_welfare=True
)
frontier_outcomes = tuple(
outcomes[_] for _ in frontier_indices if _ is not None
)
pts = nash_points(ufuns, frontier_utils, outcome_space=agenda)
pts = nash_points(ufuns, frontier_utils, outcome_space=outcome_space)
nash_utils, nash_indx = pts[0] if pts else (None, None)
nash_outcome = frontier_outcomes[nash_indx] if nash_indx else None
minmax = [u.minmax() for u in ufuns]
Expand Down
4 changes: 3 additions & 1 deletion negmas/preferences/inv_ufun.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,9 @@ def all(
raise ValueError(f"Unknown outcome space. Cannot invert the ufun")

if os_.is_discrete():
return self.some(rng, normalized)
return self.some(
rng, normalized, fallback_to_higher=False, fallback_to_best=False
)
raise ValueError(
f"Cannot find all outcomes in a range for a continuous outcome space (there is in general an infinite number of them)"
)
Expand Down
2 changes: 1 addition & 1 deletion negmas/scripts/negotiate.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def run(
nutils = list(a for a, _ in utils_indices)
print(f"Ordinal Max. Welfare Points: {pts} -- Diff = {diff(ranks, nutils)}")
# pts = max_relative_welfare_points(
# frontier=pareto, ufuns=ranks_ufuns, outcome_space=scenario.agenda
# frontier=pareto, ufuns=ranks_ufuns, outcome_space=scenario.outcome_space
# )
# pts = tuple((a, pareto_outcomes[b]) for a, b in utils_indices)
# nutils = list(a for a, _ in utils_indices)
Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ def test_load_geniusweb_example_reserved_value():
# # folder_name = "/Users/yasser/code/projects/negmas/tests/data/scenarios/anac/y2012/FitnessC"
# d2 = Domain.from_genius_folder(folder_name, safe_parsing=False)
# d2.discretize()
# assert isinstance(d2.agenda, DiscreteCartesianOutcomeSpace)
# n = d2.agenda.cardinality
# assert isinstance(d2.outcome_space, DiscreteCartesianOutcomeSpace)
# n = d2.outcome_space.cardinality
# if n < 10_000:
# d2.to_single_issue()
# assert d2.agenda.cardinality == n or d2.agenda.cardinality == float("inf")
# assert d2.outcome_space.cardinality == n or d2.outcome_space.cardinality == float("inf")
3 changes: 2 additions & 1 deletion tests/core/test_inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,12 @@ def test_inv_matches_bruteforce_best_worst(rational_only, nissues, nvalues, mn,
@given(
rational_only=st.booleans(),
nissues=st.integers(1, 4),
nvalues=st.integers(1, 4),
nvalues=st.integers(2, 4),
mn=st.floats(0.0, 1.0),
mx=st.floats(0.0, 1.0),
r=st.floats(0.0, 1.0),
)
@example(rational_only=False, nissues=1, nvalues=3, mn=0.5, mx=0.5, r=0.0)
@example(rational_only=True, nissues=1, nvalues=2, mn=0.0, mx=1.0, r=1.0)
@example(rational_only=False, nissues=1, nvalues=2, mn=0.0, mx=1.0, r=0.0)
@example(rational_only=True, nissues=1, nvalues=1, mn=0.0, mx=0.0, r=1.0)
Expand Down
10 changes: 5 additions & 5 deletions tests/core/test_tau.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,16 @@
# domain = domain.to_single_issue(randomize=True)
# assert len(domain.issues) == 1
# if remove_under:
# outcomes = remove_under_line(domain.agenda, domain.ufuns) # type: ignore
# outcomes = remove_under_line(domain.outcome_space, domain.ufuns) # type: ignore
# issue = CategoricalIssue(
# values=[_[0] for _ in outcomes], name=domain.agenda.issues[0].name
# values=[_[0] for _ in outcomes], name=domain.outcome_space.issues[0].name
# )
# domain.agenda = make_os([issue])
# domain.outcome_space = make_os([issue])
#
# # domain.ufuns = [ MappingUtilityFunction(dict(zip(outcomes, [u(_) for _ in outcomes])), outcome_space=domain.agenda) for u in domain.ufuns ]
# # domain.ufuns = [ MappingUtilityFunction(dict(zip(outcomes, [u(_) for _ in outcomes])), outcome_space=domain.outcome_space) for u in domain.ufuns ]
# domain.mechanism_type = mechanism_type
# domain.mechanism_params = mechanism_params
# neg = domain.make_session([a1, a2], n_steps=domain.agenda.cardinality)
# neg = domain.make_session([a1, a2], n_steps=domain.outcome_space.cardinality)
# if neg is None:
# raise ValueError(f"Failed to lead domain from {base_folder}")
#
Expand Down
4 changes: 2 additions & 2 deletions tests/genius/test_inout_with_genius.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def compared_two_domains(domain, domain2):
u2, HyperRectangleUtilityFunction
):
continue
dm = domain.agenda.to_discrete(5)
dm = domain.outcome_space.to_discrete(5)
for i, w in enumerate(dm):
if i > MAX_CARDINALITY:
return
Expand All @@ -113,7 +113,7 @@ def compared_two_domains(domain, domain2):
for ufun in domain.ufuns:
if isinstance(ufun, HyperRectangleUtilityFunction):
continue
m = domain.make_session(n_steps=100, name=domain.agenda.name)
m = domain.make_session(n_steps=100, name=domain.outcome_space.name)
assert m is not None
if not genius_bridge_is_running():
continue
Expand Down

0 comments on commit dbe814f

Please sign in to comment.