source: src/main/java/agents/anac/y2019/authenticagent/serviceclasses/SafeBidUtilityService.java@ 202

Last change on this file since 202 was 201, checked in by Katsuhide Fujita, 6 years ago

Add ANAC 2019 agents (2)

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1package agents.anac.y2019.authenticagent.serviceclasses;
2
3import authenticagent.biddingstrategy.services.internalpackageservices.AgentTool;
4import authenticagent.biddingstrategy.services.internalpackageservices.BidInfo;
5import genius.core.Bid;
6import genius.core.uncertainty.UserModel;
7import genius.core.utility.UtilitySpace;
8
9import java.util.*;
10
11public class SafeBidUtilityService {
12
13 private static UserModel userModel;
14 private static UtilitySpace utilitySpace;
15 private static List<BidInfo> bidInfoList;
16
17 public static void init(UtilitySpace us, UserModel um){
18 utilitySpace = us;
19 userModel = um;
20 double numberOfPossibleBids = userModel.getDomain().getNumberOfPossibleBids();
21 UtilityEstimationService.init(utilitySpace.getDomain().getIssues(), numberOfPossibleBids);
22 List<Bid> bids = userModel.getBidRanking().getBidOrder();
23 for(Bid bid : bids)
24 UtilityEstimationService.updateModel(bid);
25 int seed = 810193570;
26 bidInfoList = new ArrayList<>(AgentTool.generateRandomBids(userModel.getDomain(),
27 50000, new Random(seed)));
28 bidInfoList.sort((s1, s2) -> {
29 Double u1, u2;
30 u1 = UtilityEstimationService.getEstimatedUtilityFor(s1.getBid());
31 u2 = UtilityEstimationService.getEstimatedUtilityFor(s2.getBid());
32 return u1.compareTo(u2);
33 });
34 }
35
36 public static Bid getBidWithUtility(double utility){
37 return findBidWithUtility(0, bidInfoList.size() - 1, utility);
38 }
39
40 private static Bid findBidWithUtility(int lowerIndex, int higherIndex, double utility){
41 int currentIndex;
42 double currentUtility;
43 Bid result;
44 while (true) {
45 if (lowerIndex == higherIndex)
46 return bidInfoList.get(lowerIndex).getBid();
47 currentIndex = (lowerIndex + higherIndex) >> 1;
48 result = bidInfoList.get(currentIndex).getBid();
49 currentUtility = UtilityEstimationService.getEstimatedUtilityFor(result);
50 if (currentUtility == utility || Math.abs(currentUtility - utility) <= 0.001)
51 return result;
52 if (currentUtility > utility)
53 lowerIndex = currentIndex;
54 else
55 higherIndex = currentIndex;
56 }
57 }
58
59 public static Bid getBid(double threshold_high, double threshold_low) {
60 return findBidWithUtility(0, bidInfoList.size() - 1, (threshold_high + threshold_low) / 2);
61 }
62
63 public static double getUtility(Bid bid){
64 return UtilityEstimationService.getEstimatedUtilityFor(bid);
65 }
66
67 public static double getNumberOfPossibleBids(){
68 if(userModel != null){
69 return userModel.getDomain().getNumberOfPossibleBids();
70 }
71 if(utilitySpace != null)
72 return utilitySpace.getDomain().getNumberOfPossibleBids();
73 return 1001;
74 }
75}
Note: See TracBrowser for help on using the repository browser.