Ejemplo n.º 1
0
    def random(cls,
               issues: List["Issue"],
               reserved_value=(0.0, 1.0),
               normalized=True,
               **kwargs):
        from negmas.utilities.ops import normalize

        reserved_value = make_range(reserved_value)
        n_issues = len(issues)
        r = reserved_value if reserved_value is not None else random.random()
        s = 0.0
        weights = [2 * (random.random() - 0.5) for _ in range(n_issues)]
        biases = [2 * (random.random() - 0.5) for _ in range(n_issues)]
        ufun = cls(
            weights=weights,
            biases=biases,
            reserved_value=random.random() *
            (reserved_value[1] - reserved_value[0]) + reserved_value[0],
        )
        if normalized:
            return normalize(
                ufun,
                outcomes=Issue.discretize_and_enumerate(issues,
                                                        n_discretization=10,
                                                        max_n_outcomes=10000),
            )
        return ufun
Ejemplo n.º 2
0
def pareto_frontier(
    ufuns: Iterable[UtilityFunction],
    outcomes: Iterable[Outcome] = None,
    issues: Iterable[Issue] = None,
    n_discretization: Optional[int] = 10,
    sort_by_welfare=False,
) -> Tuple[List[Tuple[float]], List[int]]:
    """Finds all pareto-optimal outcomes in the list

    Args:

        ufuns: The utility functions
        outcomes: the outcomes to be checked. If None then all possible outcomes from the issues will be checked
        issues: The set of issues (only used when outcomes is None)
        n_discretization: The number of items to discretize each real-dimension into
        sort_by_welfare: If True, the resutls are sorted descendingly by total welfare

    Returns:
        Two lists of the same length. First list gives the utilities at pareto frontier points and second list gives their indices

    """

    ufuns = list(ufuns)
    if issues:
        issues = list(issues)
    if outcomes:
        outcomes = list(outcomes)

    # calculate all candidate outcomes
    if outcomes is None:
        if issues is None:
            return [], []
        outcomes = Issue.discretize_and_enumerate(issues, n_discretization)
        # outcomes = itertools.product(
        #     *[issue.alli(n=n_discretization) for issue in issues]
        # )
    points = [[ufun(outcome) for ufun in ufuns] for outcome in outcomes]
    return _pareto_frontier(points, sort_by_welfare=sort_by_welfare)
Ejemplo n.º 3
0
    def random(cls,
               issues: List["Issue"],
               reserved_value=(0.0, 1.0),
               normalized=True,
               **kwargs):
        from negmas.utilities.ops import normalize

        reserved_value = make_range(reserved_value)

        n_issues = len(issues)
        # r = reserved_value if reserved_value is not None else random.random()
        s = 0.0
        weights = dict(
            zip([_.name for _ in issues],
                [random.random() for _ in range(n_issues)]))
        s = sum(_ for _ in weights.values())
        if s:
            for k, v in weights.items():
                weights[k] = v / s
        issue_utilities = dict(
            zip([_.name for _ in issues],
                [random_mapping(issue) for issue in issues]))

        ufun = cls(
            weights=weights,
            issue_utilities=issue_utilities,
            reserved_value=random.random() *
            (reserved_value[1] - reserved_value[0]) + reserved_value[0],
            **kwargs,
        )
        if normalized:
            return normalize(
                ufun,
                outcomes=Issue.discretize_and_enumerate(issues,
                                                        max_n_outcomes=5000),
            )