source: boa/src/main/java/geniusweb/boa/BoaParty.java@ 20

Last change on this file since 20 was 20, checked in by bart, 4 years ago

Added BOA support, some bug fixes

File size: 4.7 KB
Line 
1package geniusweb.boa;
2
3import java.util.HashMap;
4
5import geniusweb.actions.Action;
6import geniusweb.boa.acceptancestrategy.AcceptanceStrategy;
7import geniusweb.boa.biddingstrategy.BiddingStrategy;
8import geniusweb.opponentmodel.OpponentModel;
9import geniusweb.party.inform.Settings;
10import tudelft.utilities.logging.Reporter;
11
12/**
13 * Determines the next {@link Action} given our profile, the opponent models,
14 * the acceptance strategy and BiddingStrategy.
15 * <p>
16 * The settings are assumed to contain parameters to set the BOA components:
17 * <ul>
18 * <li>"as" containing the full.class.path to the {@link AcceptanceStrategy}
19 * clas,
20 * <li>"os" containing the full.class.path to the   {@link OpponentModel} class
21 * <li>"bs" containing the full.class.path to the   {@link BiddingStrategy}
22 * class.
23 * <li>Other parameters as needed by the components
24 * </ul>
25 * <h1>more info</h1> For more information, see: Baarslag T., Hindriks K.V.,
26 * Hendrikx M., Dirkzwager A., Jonker C.M. Decoupling Negotiating Agents to
27 * Explore the Space of Negotiation Strategies. Proceedings of The Fifth
28 * International Workshop on Agent-based Complex Automated Negotiations (ACAN
29 * 2012), 2012.
30 * https://homepages.cwi.nl/~baarslag/pub/Decoupling_Negotiating_Agents_to_Explore_the_Space_of_Negotiation_Strategies_ACAN_2012.pdf
31 *
32 */
33public class BoaParty extends DefaultBoa {
34 public BoaParty() {
35 super();
36 }
37
38 public BoaParty(Reporter reporter) {
39 super(reporter); // for debugging
40 }
41
42 @Override
43 public String getDescription() {
44 return "BOA party that is fully configurable through parameters. "
45 + "Takes parameters om=OpponentModel full.class.path, "
46 + "as=AcceptanceStrategy full.class.path "
47 + "and bs=BiddingStrategy full.class.path. ";
48 }
49
50 /**
51 * Overridable getter for the acceptance strategy. Override if you want to
52 * hard code a {@link BoaParty} behaviour
53 *
54 * @param settings the {@link Settings}
55 * @return the {@link OpponentModel} class to use for modeling opponents
56 */
57 @Override
58 protected Class<? extends OpponentModel> getOpponentModel(Settings settings)
59 throws InstantiationFailedException {
60 HashMap<String, Object> parameters = settings.getParameters();
61 return loadClass("om", OpponentModel.class, parameters);
62 }
63
64 /**
65 * Overridable getter for the acceptance strategy. Override if you want to
66 * hard code a {@link BoaParty} behaviour
67 *
68 * @param settings the {@link Settings}
69 * @return the {@link BiddingStrategy} to use for determining the next
70 * {@link Action}
71 */
72 @Override
73 protected BiddingStrategy getBiddingStrategy(Settings settings)
74 throws InstantiationFailedException {
75 try {
76 return loadClass("bs", BiddingStrategy.class,
77 settings.getParameters()).newInstance();
78 } catch (InstantiationException | IllegalAccessException e) {
79 throw new InstantiationFailedException(
80 "Can't instantiate bidding strategy", e);
81 }
82 }
83
84 /**
85 * Overridable getter for the acceptance strategy. Override if you want to
86 * hard code a {@link BoaParty} behaviour
87 *
88 * @param settings the {@link Settings}
89 * @return the {@link AcceptanceStrategy} to use for determining if a bid is
90 * acceptable
91 */
92 @Override
93 protected AcceptanceStrategy getAccceptanceStrategy(Settings settings)
94 throws InstantiationFailedException {
95 try {
96 return loadClass("as", AcceptanceStrategy.class,
97 settings.getParameters()).newInstance();
98 } catch (InstantiationException | IllegalAccessException e) {
99 throw new InstantiationFailedException(
100 "Can't instantiate acceptance strategy", e);
101 }
102 }
103
104 /**
105 *
106 * @param <T> the type of the class object to load
107 * @param paramname the name of the parameter in parameters that contains
108 * the class reference, shoul dbe full.clsss.path
109 * @param clazz the class object to load
110 * @param parameters the parameterlist
111 * @return object of T, loaded from the parameter with paramname
112 * @throws ClassNotFoundException
113 * @throws InstantiationFailedException
114 */
115 @SuppressWarnings("unchecked")
116 private <T> Class<T> loadClass(String paramname, Class<T> clazz,
117 HashMap<String, Object> parameters)
118 throws InstantiationFailedException {
119
120 if (!parameters.containsKey(paramname))
121 throw new InstantiationFailedException(
122 "Can not load BOA component: the parameter " + paramname
123 + " is not specified");
124 Class<?> c;
125 try {
126 c = Class.forName((String) parameters.get(paramname));
127 } catch (ClassNotFoundException e) {
128 throw new InstantiationFailedException("Unknown BOA component", e);
129 }
130 if (!clazz.isAssignableFrom(c))
131 throw new InstantiationFailedException("Parameter " + paramname
132 + " requires an instance of " + clazz + ", but got " + c);
133
134 return (Class<T>) c;
135 }
136
137}
Note: See TracBrowser for help on using the repository browser.