Last change
on this file since 127 was 1, checked in by Wouter Pasman, 6 years ago |
Initial import : Genius 9.0.0
|
File size:
851 bytes
|
Rev | Line | |
---|
[1] | 1 | package agents.nastyagent;
|
---|
| 2 |
|
---|
| 3 | import java.util.Comparator;
|
---|
| 4 |
|
---|
| 5 | import genius.core.Bid;
|
---|
| 6 | import 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 | */
|
---|
| 18 | public 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.