OneShotUFun

class scml.oneshot.OneShotUFun(ex_pin, ex_qin, ex_pout, ex_qout, input_product, input_agent, output_agent, production_cost, disposal_cost, shortfall_penalty, input_penalty_scale, output_penalty_scale, n_input_negs, n_output_negs, current_step, input_qrange=(0, 0), input_prange=(0, 0), output_qrange=(0, 0), output_prange=(0, 0), force_exogenous=True, n_lines=10, normalized=False, current_balance=inf, **kwargs)[source]

Bases: negmas.utilities.base.UtilityFunction

Calculates the utility function of a list of contracts or offers.

Parameters
  • force_exogenous (bool) – Is the agent forced to accept exogenous contracts given through ex_* arguments?

  • ex_pin (int) – total price of exogenous inputs for this agent

  • ex_qin (int) – total quantity of exogenous inputs for this agent

  • ex_pout (int) – total price of exogenous outputs for this agent

  • ex_qout (int) – total quantity of exogenous outputs for this agent.

  • cost – production cost of the agent.

  • disposal_cost (float) – disposal cost per unit of input/output.

  • shortfall_penalty (float) – penalty for failure to deliver one unit of output.

  • input_agent (bool) – Is the agent an input agent which means that its input product is the raw material

  • output_agent (bool) – Is the agent an output agent which means that its output product is the final product

  • n_lines (int) – Number of production lines. If None, will be read through the AWI.

  • input_product (int) – Index of the input product. If None, will be read through the AWI

  • input_qrange (Tuple[int, int]) – A 2-int tuple giving the range of input quantities negotiated. If not given will be read through the AWI

  • input_prange (Tuple[int, int]) – A 2-int tuple giving the range of input unit prices negotiated. If not given will be read through the AWI

  • output_qrange (Tuple[int, int]) – A 2-int tuple giving the range of output quantities negotiated. If not given will be read through the AWI

  • output_prange (Tuple[int, int]) – A 2-int tuple giving the range of output unit prices negotiated. If not given will be read through the AWI

  • n_input_negs (int) – How many input negotiations are allowed. If not given, it will be the number of suppliers as given by the AWI

  • n_output_negs (int) – How many output negotiations are allowed. If not given, it will be the number of consumers as given by the AWI

  • current_step (int) – Current simulation step. Needed only for ufun_range when returning best outcomes

  • normalized (bool) – If given the values returned by from_*, utility_range and __call__ will all be normalized between zero and one.

Remarks:
  • The utility function assumes that the agent will have to pay for all its input products but will receive money only for the output products it could generate and sell.

  • The utility function respects production capacity (n. lines). The agent cannot produce more than the number of lines it has.

  • disposal cost is paid for items bought but not produced only. Items consumed in production (i.e. sold) are not counted.

Attributes Summary

max_utility

The maximum possible utility value

min_utility

The minimum possible utility value

Methods Summary

__call__(offer)

Calculates the utility function given a single contract.

breach_level([qin, qout])

Calculates the breach level that would result from a given quantities

find_limit(best[, n_input_negs, …])

Finds either the maximum or the minimum of the ufun.

find_limit_brute_force(best[, n_input_negs, …])

Finds either the maximum and the minimum of the ufun.

from_aggregates(qin, qout_signed, qout_sold, …)

Calculates the utility from aggregates of input/output quantity/prices

from_contracts(contracts[, ignore_exogenous])

Calculates the utility function given a list of contracts

from_offers(offers, outputs[, return_producible])

Calculates the utility value given a list of offers and whether each offer is for output or not (= input).

is_breach([qin, qout])

Whether the given quantities would lead to a breach.

ok_to_buy_at(unit_price)

Checks if the unit price can – even in principle – be acceptable for buying

ok_to_sell_at(unit_price)

Checks if the unit price can – even in principle – be acceptable for selling

outcome_as_tuple(offer)

register_agrerement(quantity, unit_price)

rtype

None

utility_range([issues, outcomes, …])

Finds the utility range and optionally returns the corresponding outcomes from a given issue space or in a single negotiation.

xml(issues)

Converts the function into a well formed XML string preferrably in GENIUS format.

Attributes Documentation

max_utility

The maximum possible utility value

min_utility

The minimum possible utility value

Methods Documentation

__call__(offer)[source]

Calculates the utility function given a single contract.

Remarks:
  • This method calculates the utility value of a single offer assuming all other negotiations end in failure.

  • It can only be called for agents that exist in the first or last layer of the production graph.

Return type

float

breach_level(qin=0, qout=0)[source]

Calculates the breach level that would result from a given quantities

find_limit(best, n_input_negs=None, n_output_negs=None, secured_input_quantity=0, secured_input_unit_price=0.0, secured_output_quantity=0, secured_output_unit_price=0.0)[source]

Finds either the maximum or the minimum of the ufun.

Parameters
  • best (bool) – Best(max) or worst (min) ufun value?

  • n_input_negs – How many input negs are we to consider? None means all

  • n_output_negs – How many output negs are we to consider? None means all

  • secured_input_quantity – A quantity that MUST be bought

  • secured_input_unit_price – The (average) unit price of the quantity that MUST be bought.

  • secured_output_quantity – A quantity that MUST be sold.

  • secured_output_unit_price – The (average) unit price of the quantity that MUST be sold.

Remarks:
  • You can use the secured_* arguments and control over the number of negotiations to consider to find the utility limits given some already concluded and signed contracts

Return type

UFunLimit

find_limit_brute_force(best, n_input_negs=None, n_output_negs=None, secured_input_quantity=0, secured_input_unit_price=0.0, secured_output_quantity=0, secured_output_unit_price=0.0)[source]

Finds either the maximum and the minimum of the ufun.

Parameters
  • best – Best(max) or worst (min) ufun value?

  • n_input_negs – How many input negs are we to consider? None means all

  • n_output_negs – How many output negs are we to consider? None means all

  • secured_input_quantity – A quantity that MUST be bought

  • secured_input_unit_price – The (average) unit price of the quantity that MUST be bought.

  • secured_output_quantity – A quantity that MUST be sold.

  • secured_output_unit_price – The (average) unit price of the quantity that MUST be sold.

Remarks:
  • You can use the secured_* arguments and control over the number of negotiations to consider to find the utility limits given some already concluded and signed contracts

Return type

UFunLimit

Returns

worst and best outcome information in the form of UFunLimit tuple.

from_aggregates(qin, qout_signed, qout_sold, pin, pout, input_penalty, output_penalty)[source]

Calculates the utility from aggregates of input/output quantity/prices

Parameters
  • qin (int) – Input quantity (total including all exogenous contracts).

  • qout_signed (int) – Output quantity (total including all exogenous contracts) that the agent agreed to sell.

  • qout_sold (int) – Output quantity (total including all exogenous contracts) that the agent will actually sell.

  • pin (int) – Input total price (i.e. unit price * qin).

  • pout (int) – Output total price (i.e. unit price * qin).

  • input_penalty – total disposal cost

  • output_penalty – total shortfall penalty

Remarks:
  • Most likely, you do not need to directly call this method. Consider from_offers and from_contracts that take current balance and exogenous contract information (passed during ufun construction) into account.

  • The method respects production capacity (n. lines). The agent cannot produce more than the number of lines it has.

  • This method does not take exogenous contracts or current balance into account.

  • The method assumes that the agent CAN pay for all input and production.

Return type

float

from_contracts(contracts, ignore_exogenous=True)[source]

Calculates the utility function given a list of contracts

Parameters
  • contracts (Iterable[Contract]) – A list/tuple of contracts

  • ignore_exogenous – If given, any contracts with a system agent will be ignored.

Remarks:
  • This method ignores any unsigned contracts passed to it.

  • We do not consider time at all so it is implicitly assumed that all contracts have the same delivery time value.

  • The reason for having the ignore_exogenous parameter is to avoid double counting exogenous contracts if their information is passed during construction of the ufun and they also exist in the list of contracts passed here.

Return type

float

from_offers(offers, outputs, return_producible=False)[source]

Calculates the utility value given a list of offers and whether each offer is for output or not (= input).

Parameters
  • offers (Iterable[Tuple]) – An iterable (e.g. list) of tuples each with three values: (quantity, time, unit price) IN THAT ORDER. Time is ignored and can be set to any value.

  • outputs (Iterable[bool]) – An iterable of the same length as offers of booleans specifying for each offer whether it is an offer for buying the agent’s output product.

  • return_producible – If true, the producible quantity will be returned

Remarks:
  • This method takes into account the exogenous contract information passed when constructing the ufun.

Return type

Union[float, Tuple[float, int]]

is_breach(qin=0, qout=0)[source]

Whether the given quantities would lead to a breach.

ok_to_buy_at(unit_price)[source]

Checks if the unit price can – even in principle – be acceptable for buying

Remarks:
  • This method is very optimistic. If it returns False, an agent should never buy at this price. If it returns True, it may still be a bad idea to buy at this price.

  • If we buy at this price, the best case scenario is that we pay it and pay production cost then receive the unit price of one output.

  • If we do not buy at this price, the worst case scenario is that we will pay shortfall penalty for one item

  • We should NOT buy if the best case scenario when buying is worse than the worst case scenario when not buying.

  • If called for agents not at the end of the production chain, it will always return True because in these cases we do not know what the the unit price for the output so there is nothing to compare with.

Return type

bool

ok_to_sell_at(unit_price)[source]

Checks if the unit price can – even in principle – be acceptable for selling

Remarks:
  • This method is very optimistic. If it returns False, an agent should never sell at this price. If it returns True, it may still be a bad idea to sell at this price.

  • Sales decisions does not affect in any way the amount we pay for input materials. It only affects the amount we produce, the amout we get paid in sales and the amount we pay as disposal cost and shortfall penalty.

  • If we agree to sell an item at this price, the best case scenario is that we can actually produce this item and sell it. We pay production cost and receive the given unit price.

  • If we do not sell at this price, the worst case scenario is that we really needed that sale. In this case, we will pay disposal cost for one item.

  • We should NOT sell if the best case scenario when selling is worse than the worst case scenario when not selling.

  • If called for agents not at the beginning of the production chain, it will always return True because in these cases we do not know what the the unit price for the input so there is nothing to compare with.

Return type

bool

static outcome_as_tuple(offer)[source]
register_agrerement(quantity, unit_price)[source]
Return type

None

utility_range(issues=None, outcomes=None, infeasible_cutoff=None, return_outcomes=False, max_n_outcomes=1000, ami=None)[source]

Finds the utility range and optionally returns the corresponding outcomes from a given issue space or in a single negotiation.

Parameters
  • issues (Optional[List[Issue]]) – The set of issues of the negotiation. If not given it will be read from the AWI. Note that you cannot specify these issues except for agent in the first or last layer of the production graph (because otherwise, the agent cannot know whether this negotiation is for buying of selling).

  • outcomes (Optional[Collection[Union[OutcomeType, Tuple[Union[int, float, str, list]], Dict[Union[int, str], Union[int, float, str, list]]]]]) – A list of outcomes to consider. Using outcomes is much slower than using issues and you should never pass both.

  • infeasible_cutoff (Optional[float]) – A utility value under which we consider the outcome infeasible.

  • return_outcomes – If given the worst and best outcomes (in that order) will be returned.

  • max_n_outcomes – Maximum number of outcomes to try. Not used.

Return type

Union[Tuple[Union[Distribution, float], Union[Distribution, float]], Tuple[Union[Distribution, float], Union[Distribution, float], Union[OutcomeType, Tuple[Union[int, float, str, list]], Dict[Union[int, str], Union[int, float, str, list]]], Union[OutcomeType, Tuple[Union[int, float, str, list]], Dict[Union[int, str], Union[int, float, str, list]]]]]

Returns

A tuple of worst and best utility values if return_outcomes is False. otherwise, the worst and best outcomes are appended to the returned utilities leading to a 4-items tuple instead of two.

Remarks:
  • You will get a warning if you use a list of outcomes here because it is too slow.

  • You should only pass issues if you know that the agent is either an input agent or an output agent. Agents in the middle of the production graph cannot know whether these issues are for buying of for selling. To find the utility range for these agents, you can use worst and best that allow specifying input and output issues separately.

  • It is always assumed that the range required is for a single negotiation not a set of negotiations and under the assumption that all other negotiations if any will end in failure

xml(issues)[source]

Converts the function into a well formed XML string preferrably in GENIUS format.

If the output has with </objective> then discount factor and reserved value should also be included If the output has </utility_space> it will not be appended in to_xml_str

Return type

str