source: src/main/java/agents/anac/y2014/BraveCat/necessaryClasses/BidGenerator.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 3.2 KB
Line 
1package agents.anac.y2014.BraveCat.necessaryClasses;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.Iterator;
6import java.util.List;
7import java.util.Random;
8
9import genius.core.Bid;
10import genius.core.bidding.BidDetails;
11import genius.core.issue.Issue;
12import genius.core.issue.IssueDiscrete;
13import genius.core.issue.IssueInteger;
14import genius.core.issue.IssueReal;
15import genius.core.issue.ValueInteger;
16import genius.core.issue.ValueReal;
17
18public class BidGenerator {
19 Random random200;
20 Random random300;
21 NegotiationSession negotiationSession;
22
23 public BidGenerator(NegotiationSession negoSession) {
24 negotiationSession = negoSession;
25 random200 = new Random();
26 random300 = new Random();
27 }
28
29 private BidDetails searchBid() throws Exception {
30 HashMap values = new HashMap();
31 List issues = negotiationSession.getDomain().getIssues();
32 Bid bid = null;
33 for (Iterator it = issues.iterator(); it.hasNext();) {
34 Issue lIssue = (Issue) it.next();
35 switch (lIssue.getType()) {
36 case DISCRETE:
37 IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
38 int optionIndex = this.random300.nextInt(lIssueDiscrete
39 .getNumberOfValues());
40 values.put(Integer.valueOf(lIssue.getNumber()),
41 lIssueDiscrete.getValue(optionIndex));
42 break;
43 case REAL:
44 IssueReal lIssueReal = (IssueReal) lIssue;
45 int optionInd = this.random300.nextInt(lIssueReal
46 .getNumberOfDiscretizationSteps() - 1);
47 values.put(
48 Integer.valueOf(lIssueReal.getNumber()),
49 new ValueReal(lIssueReal.getLowerBound()
50 + (lIssueReal.getUpperBound() - lIssueReal
51 .getLowerBound()) * optionInd
52 / lIssueReal.getNumberOfDiscretizationSteps()));
53 break;
54 case INTEGER:
55 IssueInteger lIssueInteger = (IssueInteger) lIssue;
56 int optionIndex2 = lIssueInteger.getLowerBound()
57 + this.random300.nextInt(lIssueInteger.getUpperBound()
58 - lIssueInteger.getLowerBound());
59 values.put(Integer.valueOf(lIssueInteger.getNumber()),
60 new ValueInteger(optionIndex2));
61 break;
62 default:
63 throw new Exception("issue type " + lIssue.getType()
64 + " not supported!");
65 }
66 }
67 bid = new Bid(negotiationSession.getDomain(), values);
68 BidDetails bidDetails = new BidDetails(bid, this.negotiationSession
69 .getUtilitySpace().getUtility(bid),
70 this.negotiationSession.getTime());
71 return bidDetails;
72 }
73
74 public BidDetails selectBid(double bidTarget) throws Exception {
75 BidDetails nextBid = null;
76 double searchUtil = 0.0D;
77 try {
78 int loop = 0;
79 while (searchUtil < bidTarget) {
80 if (loop > 50) {
81 bidTarget -= 0.01D;
82 loop = 0;
83 }
84 nextBid = searchBid();
85 searchUtil = negotiationSession.getUtilitySpace().getUtility(
86 nextBid.getBid());
87 loop++;
88 }
89 } catch (Exception localException) {
90 System.out.println("Exception occured when selecting a bid!");
91 }
92 if (nextBid == null)
93 nextBid = searchBid();
94 return nextBid;
95 }
96
97 public List<BidDetails> NBidsNearUtility(double bidTarget, int n)
98 throws Exception {
99 ArrayList<BidDetails> tempList = new ArrayList();
100 for (int i = 0; i < n; i++)
101 tempList.add(selectBid(bidTarget));
102 return tempList;
103 }
104}
Note: See TracBrowser for help on using the repository browser.