source: src/main/java/bargainingchips/analysis/ParetoFrontier.java@ 339

Last change on this file since 339 was 339, checked in by Faria Nassiri Mofakham, 5 years ago

BargainingChips creates bob calling BargainingBuyer. OutcomeSpace is Iterable<Bundle>, also getAllBids, getRandom, getRandom(r), getAverageUtility(u), size(), checkReadyForNegotiation, getName(), getUtility(u, b), getReservationValue(u), and getDiscountFactor added. An update on Bid getSampleBid type. An update on Agent. A history' package of BidEvent, BidEventHistory, BidEventHisoryKeeper, BidEventSortedUtility, and BidEventStrictSortedUtility added. HistoryAgent added. An analysis' package of BundleUtilityPoint, BundleUtilitySpace, and ParetoFrontier added. BargainingAgent added. TitForTatNegotiationAgent. Now, Buyer extended to BargainingBuyer which is created using Boulware or TitForTatNegotiationAgent using one among 9 utility functions. Name of strategy added toDescription in BoulwareAgent. A few small updates on several utility function classes.

File size: 3.4 KB
Line 
1/**
2 *
3 */
4package bargainingchips.analysis;
5
6import java.io.Serializable;
7import java.util.ArrayList;
8import java.util.Collections;
9import java.util.Comparator;
10import java.util.List;
11
12import bargainingchips.analysis.BundleUtilityPoint;
13
14/**
15 *
16 * This class is for storing Pareto-frontier by adding bundles at analysis time.
17 * It adapts {@link genius.core.analysis.ParetoFrontier}.
18 *
19 *
20 * @author Faria Nassiri-Mofakham
21 *
22 */
23
24public class ParetoFrontier implements Serializable {
25
26 /**
27 *
28 */
29 private static final long serialVersionUID = 1L;
30 /** List holding the Pareto-frontier bids. */
31 private List<BundleUtilityPoint> frontier;
32
33 /**
34 * Create an empty list to store the Pareto-frontier.
35 */
36 public ParetoFrontier() {
37 frontier = new ArrayList<BundleUtilityPoint>();
38 }
39
40 /**
41 * Determines if a bid should be added to the Pareto-frontier. A bid is
42 * added when it strictly dominates a bid in the Pareto-frontier OR when it
43 * is equal to a bid in the Pareto-frontier.
44 *
45 * @param bidpoint
46 * bid to be added to the Pareto-frontier.
47 */
48 public void mergeIntoFrontier(BundleUtilityPoint bundleutilitypoint) {
49 for (BundleUtilityPoint f : frontier) {
50 if (bundleutilitypoint.isStrictlyDominatedBy(f)) {
51 // the bundleutilitypoint is dominated, and therefore not added
52 return;
53 }
54 if (f.isStrictlyDominatedBy(bundleutilitypoint)) {
55 // the bundleutilitypoint dominates a Pareto-bid, which is therefore
56 // replaced
57 merge(bundleutilitypoint, f);
58 return;
59 }
60 }
61 // the bid must be equal to an existing bid, therefore add it
62 frontier.add(bundleutilitypoint);
63 }
64
65 /**
66 * Adds a bid to the Pareto frontier
67 *
68 * @param newParetoBid
69 * new Pareto bid.
70 * @param dominatedParetoBid
71 * old Pareto bid which must now be removed.
72 */
73 private void merge(BundleUtilityPoint newParetoBid, BundleUtilityPoint dominatedParetoBid) {
74 // remove dominated bid.
75 frontier.remove(dominatedParetoBid);
76 // there might still be more bids which should be removed.
77 ArrayList<BundleUtilityPoint> toBeRemoved = new ArrayList<BundleUtilityPoint>();
78 for (BundleUtilityPoint f : frontier) {
79 if (f.isStrictlyDominatedBy(newParetoBid)) // delete dominated
80 // frontier points
81 toBeRemoved.add(f);
82 }
83 frontier.removeAll(toBeRemoved);
84 frontier.add(newParetoBid);
85 }
86
87 /**
88 * Returns true if the given BundleUtilityPoint is not part of the Pareto-frontier.
89 *
90 * @param bid
91 * to be checked if it is Pareto-optimal.
92 * @return true if NOT pareto-optimal bid.
93 */
94 public boolean isBelowFrontier(BundleUtilityPoint bid) {
95 for (BundleUtilityPoint f : this.getFrontier())
96 if (bid.isStrictlyDominatedBy(f))
97 return true;
98 return false;
99 }
100
101 /**
102 * Order the bids based on the utility for agent A.
103 */
104 public void sort() {
105 Collections.sort(frontier, new Comparator<BundleUtilityPoint>() {
106 @Override
107 public int compare(BundleUtilityPoint x, BundleUtilityPoint y) {
108 if (x.getUtilityA() < y.getUtilityA())
109 return -1;
110 else if (x.getUtilityA() > y.getUtilityA())
111 return 1;
112 else
113 return 0;
114 }
115 });
116 }
117
118 /**
119 * Returns the Pareto-optimal frontier.
120 *
121 * @return Pareto-optimal frontier.
122 */
123 public List<BundleUtilityPoint> getFrontier() {
124 return frontier;
125 }
126}
Note: See TracBrowser for help on using the repository browser.