abce.contracts package¶
Submodules¶
abce.contracts.contracting module¶
-
class
abce.contracts.contracting.
Contract
(sender_group, sender_id, deliver_good_group, deliver_good_id, pay_group, pay_id, good, quantity, price, end_date, id, round)[source]¶ Bases:
object
-
deliver_good_group
¶
-
deliver_good_id
¶
-
delivered
¶
-
end_date
¶
-
good
¶
-
id
¶
-
paid
¶
-
pay_group
¶
-
pay_id
¶
-
price
¶
-
quantity
¶
-
round
¶
-
sender_group
¶
-
sender_id
¶
-
-
class
abce.contracts.contracting.
Contracting
[source]¶ Bases:
object
This is a class, that allows you to create contracts. For example a work contract. One agent commits to deliver a good or service for a set amount of time.
For example you have a firm and a worker class. ‘Labor’ is set as a service meaning that it lasts not longer than one round and the worker how has an adult gets one unit of labor every round see:
abce.declare_service()
. The firm offers a work contract, the worker responds. Every round the worker delivers the labor and the firm pays.:class Firm(abce.Agent, abce.Contract) def request_offer(self): if self.round % 10 == 0: self.given_contract = self.request_contract('contractbuyer', 0, good='labor', quantity=5, price=10, duration=10 - 1) def deliver_or_pay(self): self.pay_contract('labor') class Worker(abce.Agent, abce.Contract): def init(self): self.create('adult', 1) def accept_offer(self): contracts = self.get_contract_requests('labor') for contract in contracts: if contract.price < 5: self.accepted_contract = self.accept_contract(contract) def deliver_or_pay(self): self.deliver('labor')
Firms and workers can check, whether they have been paid/provided with labor using the
is_paid()
andis_delivered()
methods.The worker can also initiate the transaction by requesting a contract with
make_contract_offer()
.A contract has the following fields:
sender_group:
sender_id:
deliver_group:
deliver_id:
pay_group:
pay_id:
good:
quantity:
price:
end_date:
- makerequest:
- ‘m’ for make_contract_offer and ‘r’ for request_contract
- id:
- unique number of contract
-
accept_contract
(contract, quantity=None)[source]¶ Accepts the contract. The contract is completely accepted, when the quantity is not given. Or partially when quantity is set.
Args:
- contract:
- the contract in question, received with get_contract_requests or get_contract_offers
- quantity (optional):
- the quantity that is accepted. Defaults to all.
-
get_contract_offers
(good, descending=False)[source]¶ Returns all contract offers and removes them. The contract are ordered by price (ascending), when tied they are randomized.
- Args:
- good:
- good that underlies the contract
- descending(bool,default=False):
- False for descending True for ascending by price
- Returns:
- list of contract offers ordered by price
-
offer_good_contract
(receiver_group, receiver_id, good, quantity, price, duration)[source]¶ This method offers a contract to provide a good or service to the receiver. For a given time at a given price.
Args:
- receiver_group:
- group to receive the good
- receiver_id:
- group to receive the good
- good:
- the good or service that should be provided
- quantity:
- the quantity that should be provided
- price:
- the price of the good or service
- duration:
- the length of the contract, if duration is None or not set, the contract has no end date.
Example:
self.given_contract = self.make_contract_offer('firm', 1, 'labor', quantity=8, price=10, duration=10 - 1)
-
request_good_contract
(receiver_group, receiver_id, good, quantity, price, duration)[source]¶ This method requests a contract to provide a good or service to the sender. For a given time at a given price. For example a job advertisement.
Args:
- receiver_group:
- group of the receiver
- receiver_id:
- id of the receiver
- good:
- the good or service that should be provided
- quantity:
- the quantity that should be provided
- price:
- the price of the good or service
- duration:
- the length of the contract, if duration is None or not set, the contract has no end date.
abce.contracts.contracts module¶
abce.contracts.flexiblecontracting module¶
-
class
abce.contracts.flexiblecontracting.
Credit
(sender_group, sender_id, deliver_good_group, deliver_good_id, pay_group, pay_id, amount, interest)[source]¶ Bases:
object
-
amount
¶
-
deliver_good_group
¶
-
deliver_good_id
¶
-
interest
¶
-
pay_group
¶
-
pay_id
¶
-
sender_group
¶
-
sender_id
¶
-
-
class
abce.contracts.flexiblecontracting.
FlexibleContracting
[source]¶ Bases:
object
This is a class, that allows you to create contracts. For example a work contract. One agent commits to deliver a good or service for a set amount of time.
For example you have a firm and a worker class. ‘Labor’ is set as a service meaning that it lasts not longer than one round and the worker how has an adult gets one unit of labor every round see:
abce.declare_service()
. The firm offers a work contract, the worker responds. Every round the worker delivers the labor and the firm pays.:class Firm(abce.Agent, abce.Contract) def request_offer(self): if self.round % 10 == 0: self.given_contract = self.request_contract('contractbuyer', 0, good='labor', quantity=5, price=10, duration=10 - 1) def deliver_or_pay(self): self.pay_contract('labor') class Worker(abce.Agent, abce.Contract): def init(self): self.create('adult', 1) def accept_offer(self): contracts = self.get_contract_requests('labor') for contract in contracts: if contract.price < 5: self.accepted_contract = self.accept_contract(contract) def deliver_or_pay(self): self.deliver('labor')
Firms and workers can check, whether they have been paid/provided with labor using the
is_paid()
andis_delivered()
methods.The worker can also initiate the transaction by requesting a contract with
make_contract_offer()
.A contract has the following fields:
sender_group:
sender_id:
deliver_group:
deliver_id:
pay_group:
pay_id:
good:
quantity:
price:
end_date:
- makerequest:
- ‘m’ for make_contract_offer and ‘r’ for request_contract
- id:
- unique number of contract
-
accept_contract
(contract, quantity=None)[source]¶ Accepts the contract. The contract is completely aceppted, when the quantity is not given. Or partially when quantity is set.
Args:
- contract:
- the contract in question, received with get_contract_requests or get_contract_offers
- quantity (optional):
- the quantity that is accepted. Defaults to all.
-
get_contract_offers
(good, descending=False)[source]¶ Returns all contract offers and removes them. The contract are ordered by price (ascending), when tied they are randomized.
- Args:
- good:
- good that underlies the contract
- descending(bool,default=False):
- False for descending True for ascending by price
- Returns:
- list of contract offers ordered by price
-
request_credit
(receiver_group, receiver_id, amount, interest, end_date)[source]¶ This method offers a contract to provide a good or service to the receiver. For a given time at a given price.
Args:
- receiver_group:
- group to receive the good
- receiver_id:
- group to receive the good
- deliver:
- an array or function that returns a number or dict for each round, the tuple specifies which goods have to be delivered at which price.
- receive:
- an array or function that returns a number or a dict for each round, the tuple specifies which goods have to be delivered at which price.
Example:
self.given_contract = self.make_contract_offer('firm', 1, 'labor', quantity=8, price=10, duration=10 - 1)
-
request_good_contract
(receiver_group, receiver_id, good, quantity, price, duration)[source]¶ This method requests a contract to provide a good or service to the sender. For a given time at a given price. For example a job advertisement.
Args:
- receiver_group:
- group of the receiver
- receiver_id:
- id of the receiver
- good:
- the good or service that should be provided
- quantity:
- the quantity that should be provided
- price:
- the price of the good or service
- duration:
- the length of the contract, if duration is None or not set, the contract has no end date.