-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnegotiator.py
executable file
·33 lines (28 loc) · 1.38 KB
/
negotiator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from negotiator_base import BaseNegotiator
from random import random
from functools import wraps
# Example negotiator implementation, which randomly chooses to accept
# an offer or return with a randomized counteroffer.
# Important things to note: We always set self.offer to be equal to whatever
# we eventually pick as our offer. This is necessary for utility computation.
# Second, note that we ensure that we never accept an offer of "None".
class Negotiator(BaseNegotiator):
# Override the make_offer method from BaseNegotiator to accept a given offer 20%
# of the time, and return a random subset the rest of the time.
def make_offer(self, offer):
self.offer = offer
if random() < 0.1 and offer is not None:
# Very important - we save the offer we're going to return as self.offer
print "[RN]Random Negotiator agree that you can take " + str(self.offer)
self.offer = BaseNegotiator.set_diff(self)
print "[RN]Random Negotiator will take: " + str(self.offer)
return self.offer
else:
ordering = self.preferences
ourOffer = []
for item in ordering.keys():
if random() < 0.5:
ourOffer = ourOffer + [item]
print "[RN]Random Negotiator made an offer" + str(ourOffer)
self.offer = ourOffer
return self.offer