source: src/main/java/agents/BidComparator.java@ 256

Last change on this file since 256 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 840 bytes
Line 
1package agents;
2
3import java.util.Comparator;
4
5import genius.core.Bid;
6import genius.core.utility.UtilitySpace;
7
8/**
9 * {@link Comparator} for {@link Bid}s. Used for sorting a set of bids.
10 *
11 * Use example:
12 * <code> Collections.sort(bids, new BidComparator(utilitySpace));
13</code>
14 *
15 * @author W.Pasman
16 *
17 */
18public class BidComparator implements java.util.Comparator<Bid> {
19 UtilitySpace utilspace;
20
21 public BidComparator(UtilitySpace us) {
22 if (us == null)
23 throw new NullPointerException("null utility space");
24 utilspace = us;
25 }
26
27 public int compare(Bid b1, Bid b2) throws ClassCastException {
28 double d1 = 0, d2 = 0;
29 try {
30 d1 = utilspace.getUtility(b1);
31 d2 = utilspace.getUtility(b2);
32 } catch (Exception e) {
33 e.printStackTrace();
34 }
35
36 if (d1 < d2)
37 return 1;
38 if (d1 > d2)
39 return -1;
40 return 0;
41 }
42}
Note: See TracBrowser for help on using the repository browser.