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

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

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