1 | package bargainingchips;
|
---|
2 |
|
---|
3 | import java.util.concurrent.BlockingQueue;
|
---|
4 | import java.util.concurrent.LinkedBlockingQueue;
|
---|
5 |
|
---|
6 | import bargainingchips.actions.Offer;
|
---|
7 | import bargainingchips.actions.OfferBy;
|
---|
8 | import bargainingchips.players.Agent;
|
---|
9 | import bargainingchips.players.BoulwareAgent;
|
---|
10 | import bargainingchips.players.CoordinationMessage;
|
---|
11 | import bargainingchips.players.Coordinator;
|
---|
12 | import bargainingchips.players.StatusMessage;
|
---|
13 | import bargainingchips.protocol.AsynchronousOffersProtocol;
|
---|
14 | import bargainingchips.utilityfunctions.UF_CloseToQuantity;
|
---|
15 | import bargainingchips.utilityfunctions.UtilityFunction;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * This main class showcases the fundamental concepts in the Bargaining Chips game.
|
---|
19 | *
|
---|
20 | * Bargaining Chips is played by a buyer who seeks to acquire a number of chips for a good price.
|
---|
21 | * For example, the wish list of the buyer may consist of 2 red chips and 1 blue chip.
|
---|
22 | * Chips represents arbitrary indivisible items, such as products or tasks and are differentiated
|
---|
23 | * from others by a unique color.
|
---|
24 | *
|
---|
25 | * Bargaining Chips is played using an asynchronous offer protocol for each bilateral negotiation thread.
|
---|
26 | * Multiple deals in simultaneous threads of one-to-many negotiation need to be coordinated; therefore,
|
---|
27 | * the buyer is equipped with two modules, one coordinator and multiple negotiators one per each thread.
|
---|
28 | *
|
---|
29 | * Each of the individual negotiations is itself a bilateral negotiation over multiple items and multiple
|
---|
30 | * issues, i.e. a multi-issue multi-item thread. As each thread could reach a deal, the whole negotiation
|
---|
31 | * could reach multiple deals.
|
---|
32 | *
|
---|
33 | * Negotiating in this setting needs some coordination efforts to synchronize threads according to the
|
---|
34 | * progress of each individual negotiation as well as the multiple deals compared with the party's preference.
|
---|
35 | *
|
---|
36 | * Bargaining Chips is a testbed for evaluating agents in such settings.
|
---|
37 | *
|
---|
38 | */
|
---|
39 | public class BargainingChips
|
---|
40 | {
|
---|
41 | public static void main(String[] args) throws InterruptedException
|
---|
42 | {
|
---|
43 | // Set up the protocol
|
---|
44 | BlockingQueue<OfferBy> from = new LinkedBlockingQueue<OfferBy>();
|
---|
45 | BlockingQueue<Offer> toBuyer = new LinkedBlockingQueue<Offer>();
|
---|
46 | BlockingQueue<Offer> toSeller = new LinkedBlockingQueue<Offer>();
|
---|
47 |
|
---|
48 | String nameBuyer = "Bob 1";
|
---|
49 | String nameSeller = "Sam";
|
---|
50 |
|
---|
51 | AsynchronousOffersProtocol aop = new AsynchronousOffersProtocol(from, nameBuyer, toBuyer, nameSeller, toSeller);
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 | BlockingQueue<CoordinationMessage> cin = new LinkedBlockingQueue<CoordinationMessage>();
|
---|
57 | BlockingQueue<StatusMessage> cout = new LinkedBlockingQueue<StatusMessage>();
|
---|
58 |
|
---|
59 | NegotiationContext context = new NegotiationContext();
|
---|
60 |
|
---|
61 | // Bob
|
---|
62 | WishList wishlist = new WishListBuilder().addWish("Green", 2).build(); // Bob wishes for 2 Green chips
|
---|
63 | UtilityFunction u = new UF_CloseToQuantity(wishlist);
|
---|
64 | Agent bob1 = new BoulwareAgent(nameBuyer, u, context, toBuyer, from, cin, cout);
|
---|
65 |
|
---|
66 | // Coordinator
|
---|
67 | Coordinator c = new Coordinator(wishlist, cout, cin);
|
---|
68 |
|
---|
69 | // Sam
|
---|
70 | WishList wishlistSam = new WishListBuilder().addWish("Green", 10).build(); // Sam wishes for 10 Green chips
|
---|
71 | UtilityFunction uSam = new UF_CloseToQuantity(wishlistSam);
|
---|
72 | Agent sam = new BoulwareAgent(nameSeller, uSam, context, toSeller, from);
|
---|
73 |
|
---|
74 | // Start threads
|
---|
75 | System.out.println(bob1.toDescription());
|
---|
76 | System.out.println("playing vs");
|
---|
77 | System.out.println(sam.toDescription());
|
---|
78 |
|
---|
79 | Thread aopThread = new Thread(aop);
|
---|
80 | aopThread.start();
|
---|
81 |
|
---|
82 | Thread threadBuyer = new Thread(bob1);
|
---|
83 | threadBuyer.start();
|
---|
84 |
|
---|
85 | Thread threadSeller = new Thread(sam);
|
---|
86 | threadSeller.start();
|
---|
87 |
|
---|
88 | Thread threadCoordinator = new Thread(c);
|
---|
89 | threadCoordinator.start();
|
---|
90 | }
|
---|
91 |
|
---|
92 | }
|
---|