source: src/main/java/agents/anac/y2018/beta_one/Group2.java@ 341

Last change on this file since 341 was 341, checked in by Katsuhide Fujita, 5 years ago

Katsuhide Fujita added ANAC2018 agents.

File size: 3.0 KB
Line 
1package agents.anac.y2018.beta_one;
2
3import java.util.HashMap;
4import java.util.Map;
5import java.util.Map.Entry;
6
7import org.apache.commons.math.stat.regression.SimpleRegression;
8
9import list.Tuple;
10import misc.Range;
11import negotiator.AgentID;
12import negotiator.actions.Offer;
13import negotiator.persistent.StandardInfo;
14import negotiator.persistent.StandardInfoList;
15import negotiator.utility.AdditiveUtilitySpace;
16
17public class Group2 extends GroupNegotiator
18{
19 private static final double OBSERVE_DURATION = 0.75;
20 private static final double BOX_SIZE = 0.05;
21 private static final double SLOPE_TOLERANCE = 0.035;
22
23 private static final double MIN_SELFISH_RATIO = 0.15;
24 private static final double MAX_SELFISH_RATIO = 0.30;
25
26 private static final int HISTORY_ANALYZE_COUNT = 5;
27
28 private AntiAnalysis antiAnalysis;
29
30 private HashMap<AgentID, SimpleRegression> data;
31
32 @Override
33 protected void initialize()
34 {
35 antiAnalysis = new AntiAnalysis((AdditiveUtilitySpace) utilitySpace, OBSERVE_DURATION, (MIN_SELFISH_RATIO + MAX_SELFISH_RATIO) / 2.0, BOX_SIZE);
36
37 data = new HashMap<AgentID, SimpleRegression>();
38 }
39
40 @Override
41 protected void initializeHistory(StandardInfoList infoList)
42 {
43 if (infoList.isEmpty())
44 return;
45
46 Map<String, Double> utilitySet = new HashMap<String, Double>();
47 for (int i = infoList.size() - 1; i >= 0 && i >= infoList.size() - HISTORY_ANALYZE_COUNT; i--)
48 {
49 StandardInfo info = infoList.get(i);
50
51 for (Tuple<String, Double> offered : info.getUtilities())
52 {
53 String agent = offered.get1();
54 Double utility = offered.get2();
55
56 agent = agent.substring(0, agent.indexOf("@"));
57
58 if (!utilitySet.containsKey(agent) || utility < utilitySet.get(agent).doubleValue())
59 utilitySet.put(agent, utility);
60 }
61 }
62
63 double maxUtility = 0;
64
65 for (Entry<String, Double> entry : utilitySet.entrySet())
66 {
67 if (maxUtility < entry.getValue())
68 maxUtility = entry.getValue();
69 }
70
71 double selfishRatio = AntiAnalysis.lerp(MIN_SELFISH_RATIO, MAX_SELFISH_RATIO, maxUtility);
72 antiAnalysis.setSelfishPoint(selfishRatio);
73 }
74
75 @Override
76 public void receiveOffer(Offer receivedOffer, double utility)
77 {
78 AgentID id = receivedOffer.getAgent();
79 addData(id, utility);
80 boolean betrayed = hasBetrayed(id);
81
82 double t = negotiationTime / utilitySpace.getDiscountFactor();
83 Range range = antiAnalysis.getBox(t, betrayed);
84 setAcceptableRange(id, range);
85 }
86
87 private boolean hasBetrayed(AgentID id)
88 {
89 double mySlope = antiAnalysis.getSelfishSlope(utilitySpace.getDiscountFactor());
90 double oppSlope = getSlope(id);
91
92 return oppSlope + mySlope < -SLOPE_TOLERANCE;
93 }
94
95 private double getSlope(AgentID id)
96 {
97 return getRegression(id).getSlope();
98 }
99
100 private void addData(AgentID id, double utility)
101 {
102 getRegression(id).addData(negotiationTime, utility);
103 }
104
105 private SimpleRegression getRegression(AgentID id)
106 {
107 if (!data.containsKey(id))
108 {
109 data.put(id, new SimpleRegression());
110 }
111
112 return data.get(id);
113 }
114}
Note: See TracBrowser for help on using the repository browser.