source: src/main/java/bargainingchips/BargainingChips.java@ 330

Last change on this file since 330 was 330, checked in by Tim Baarslag, 5 years ago

BasicAgent

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