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