def random( cls, issues, reserved_value=(0.0, 1.0), normalized=True, cost_range=(0.8, 1.0), power_range=(0.0, 1.0), base_ufun_type: Type[ UtilityFunction] = "negmas.LinearUtilityAggregationFunction", **kwargs, ) -> "ExpDiscountedUFun": """Generates a random ufun of the given type""" reserved_value = make_range(reserved_value) cost_range = make_range(cost_range) power_range = make_range(power_range) kwargs["cost"] = (random.random() * (cost_range[1] - cost_range[0]) + cost_range[0]) kwargs["power"] = (random.random() * (power_range[1] - power_range[0]) + power_range[0]) kwargs["reserved_value"] = (random.random() * (reserved_value[1] - reserved_value[0]) + reserved_value[0]) return cls( get_class(base_ufun_type)._random( issues, reserved_value=kwargs["reserved_value"], normalized=normalized), **kwargs, )
def random( cls, issues, reserved_value=(0.0, 1.0), normalized=True, discount_range=(0.8, 1.0), base_ufun_type: Union[ str, Type[UtilityFunction]] = "negmas.LinearUtilityAggregationFunction", **kwargs, ) -> "ExpDiscountedUFun": """Generates a random ufun of the given type""" reserved_value = make_range(reserved_value) discount_range = make_range(discount_range) kwargs["discount"] = (random.random() * (discount_range[1] - discount_range[0]) + discount_range[0]) kwargs["reserved_value"] = (random.random() * (reserved_value[1] - reserved_value[0]) + reserved_value[0]) return cls( get_class(base_ufun_type).random(issues, reserved_value=reserved_value, normalized=normalized), **kwargs, )
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
def random( cls, issues, reserved_value=(0.0, 1.0), normalized=True, value_range=(0.0, 1.0), **kwargs, ) -> "ExpDiscountedUFun": """Generates a random ufun of the given type""" reserved_value = make_range(reserved_value) value_range = make_range(value_range) kwargs["value"] = (random.random() * (value_range[1] - value_range[0]) + value_range[0]) kwargs["reserved_value"] = (random.random() * (reserved_value[1] - reserved_value[0]) + reserved_value[0]) return cls(**kwargs)
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), )