source: src/test/java/boaexample/BoaPartyExample.java@ 178

Last change on this file since 178 was 178, checked in by Tim Baarslag, 6 years ago

Re-merged my fixes to BoaPartyExample to make it more readable and easier to edit

File size: 3.1 KB
Line 
1package boaexample;
2
3import java.util.List;
4
5import java.util.Collections;
6import java.util.HashMap;
7
8import negotiator.boaframework.opponentmodel.HardHeadedFrequencyModel;
9
10import genius.core.boaframework.AcceptanceStrategy;
11import genius.core.boaframework.BoaParty;
12import genius.core.boaframework.OMStrategy;
13import genius.core.boaframework.OfferingStrategy;
14import genius.core.boaframework.OpponentModel;
15import genius.core.issue.IssueDiscrete;
16import genius.core.issue.ValueDiscrete;
17import genius.core.parties.NegotiationInfo;
18import genius.core.uncertainty.AdditiveUtilitySpaceFactory;
19import genius.core.utility.AbstractUtilitySpace;
20
21/**
22 * This example shows how BOA components can be made into an independent
23 * negotiation party.
24 *
25 * Note that this is equivalent to adding a BOA party via the GUI by selecting
26 * the components and parameters. However, this method gives more control over
27 * the implementation, as the agent designer can choose to override behavior
28 * (such as handling preference uncertainty).
29 */
30@SuppressWarnings("serial")
31public class BoaPartyExample extends BoaParty
32{
33 @SuppressWarnings("unchecked")
34 @Override
35 public void init(NegotiationInfo info)
36 {
37 // The choice for each component is made here
38 AcceptanceStrategy ac = new AC_Next();
39 OfferingStrategy os = new TimeDependent_Offering();
40 OpponentModel om = new HardHeadedFrequencyModel();
41 OMStrategy oms = new BestBid();
42
43 // All component parameters can be set below.
44 HashMap<String, Double> noparams = (HashMap<String, Double>) Collections.EMPTY_MAP;
45 HashMap<String, Double> osParams = new HashMap<String, Double>();
46 // Set the concession parameter "e" for the offering strategy to yield
47 // Boulware-like behavior
48 osParams.put("e", 0.2);
49
50 // Initialize all the components of this party to the choices defined above
51 configure(ac, noparams,
52 os, osParams,
53 om, noparams,
54 oms, noparams);
55 super.init(info);
56 }
57
58 /**
59 * Specific functionality, such as the estimate of the utility space in the
60 * face of preference uncertainty, can be specified by overriding the
61 * default behavior.
62 *
63 * This example estimator sets all weights and all evaluator values randomly.
64 */
65 @Override
66 public AbstractUtilitySpace estimateUtilitySpace() {
67 AdditiveUtilitySpaceFactory additiveUtilitySpaceFactory = new AdditiveUtilitySpaceFactory(getDomain());
68 List<IssueDiscrete> issues = additiveUtilitySpaceFactory.getIssues();
69 for (IssueDiscrete i : issues)
70 {
71 additiveUtilitySpaceFactory.setWeight(i, rand.nextDouble());
72 for (ValueDiscrete v : i.getValues())
73 additiveUtilitySpaceFactory.setUtility(i, v, rand.nextDouble());
74 }
75
76 // Normalize the weights, since we picked them randomly in [0, 1]
77 additiveUtilitySpaceFactory.normalizeWeights();
78
79 // The factory is done with setting all parameters, now return the utility space
80 return additiveUtilitySpaceFactory.getUtilitySpace();
81 }
82
83 @Override
84 public String getDescription()
85 {
86 return "Boa Party Example";
87 }
88
89 // All the rest of the functionality is defined by the BOA framework
90}
Note: See TracBrowser for help on using the repository browser.