$darkmode
DENOPTIM
FitnessParameters.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.fitness;
20
21import java.lang.reflect.Field;
22import java.util.ArrayList;
23import java.util.List;
24
25import denoptim.exception.DENOPTIMException;
26import denoptim.files.FileUtils;
27import denoptim.programs.RunTimeParameters;
28
36{
40 private boolean useExternalFitness = true;
41
45 private String externalExe = "";
46
50 private String interpreterExternalExe = "bash";
51
55 private String fitnessExpression = "";
56
62 private List<String> customVarDescExpressions =
63 new ArrayList<String>();
64
69 private List<DescriptorForFitness> descriptors =
70 new ArrayList<DescriptorForFitness>();
71
75 private boolean makePictures = false;
76
85 private boolean make3DTrees = true;
86
92 private boolean checkPreFitnessUID = true;
93
98 private boolean checkPreFitnessUIDFromInput = false;
99
107 private boolean writeCandidatesOnDisk = true;
108
109
110//------------------------------------------------------------------------------
111
116 {
118 }
119
120//------------------------------------------------------------------------------
121
126 public boolean useExternalFitness()
127 {
128 return useExternalFitness;
129 }
130
131//------------------------------------------------------------------------------
132
137 public boolean makePictures()
138 {
139 return makePictures;
140 }
141
142//------------------------------------------------------------------------------
143
150 public boolean make3dTree()
151 {
152 return make3DTrees;
153 }
154
155//------------------------------------------------------------------------------
156
161 public boolean checkPreFitnessUID()
162 {
163 return checkPreFitnessUID;
164 }
165
166//------------------------------------------------------------------------------
167
173 {
174 return externalExe;
175 }
176
177//------------------------------------------------------------------------------
178
184 {
186 }
187
188//------------------------------------------------------------------------------
189
194 public String getFitnessExpression()
195 {
196 return fitnessExpression;
197 }
198
199//------------------------------------------------------------------------------
200
204 public List<DescriptorForFitness> getDescriptors()
205 {
206 return descriptors;
207 }
208
209//------------------------------------------------------------------------------
210
211 public void interpretKeyword(String key, String value) throws DENOPTIMException
212 {
213 String msg = "";
214 switch (key.toUpperCase())
215 {
216 case "SOURCE=":
217 externalExe = value;
218 break;
219
220 case "INTERPRETER=":
222 break;
223
224 case "EQUATION=":
225 fitnessExpression = value;
226 useExternalFitness = false;
227 break;
228
229 case "DESCRIPTORSPECS=":
230 customVarDescExpressions.add(value);
231 break;
232
233 case "MAKEPICTURES":
234 makePictures = true;
235 break;
236
237 case "NO3DTREEMODEL":
238 make3DTrees = false;
239 break;
240
241 case "DONTWRITECANDIDATESONDISK":
242 writeCandidatesOnDisk = false;
243 break;
244
245 case "CHECKUIDBEFOREFITNESS=":
248 break;
249
250 default:
251 msg = "Keyword " + key + " is not a known fitness-related "
252 + "keyword. Check input files.";
253 throw new DENOPTIMException(msg);
254 }
255 }
256
257//------------------------------------------------------------------------------
258
260 {
261 String msg = "";
262 if ((externalExe.length() != 0)
264 {
265 msg = "Cannot find the fitness provider: " + externalExe;
266 throw new DENOPTIMException(msg);
267 }
269 }
270
271//------------------------------------------------------------------------------
272
274 {
275 if (!fitnessExpression.equals(""))
276 {
280 }
282 checkPreFitnessUID = false;
283
285 }
286
287//------------------------------------------------------------------------------
288
295 public String getPrintedList()
296 {
297 StringBuilder sb = new StringBuilder(1024);
298 sb.append(" " + paramTypeName() + " ").append(NL);
299 for (Field f : this.getClass().getDeclaredFields())
300 {
301 try
302 {
303 sb.append(f.getName()).append(" = ").append(
304 f.get(this)).append(NL);
305 }
306 catch (Throwable t)
307 {
308 sb.append("ERROR! Unable to print " + paramTypeName()
309 + " parameters. Cause: " + t);
310 break;
311 }
312 }
313 for (RunTimeParameters otherCollector : otherParameters.values())
314 {
315 sb.append(otherCollector.getPrintedList());
316 }
317 return sb.toString();
318 }
319
320//------------------------------------------------------------------------------
321
326 public boolean writeCandidatesOnDisk()
327 {
329 }
330
331//------------------------------------------------------------------------------
332
333}
static boolean checkExists(String fileName)
Definition: FileUtils.java:241
Class parsing fitness expression by means of Expression Language.
List< DescriptorForFitness > getDescriptors()
Returns the list of descriptors needed to compute the numerical values of the variables in the expres...
void parse(String fitnessExpression, List< String > customVarDescExpressions)
Parses the given expressions.
Settings defining the calculation of fitness.
String fitnessExpression
Formulation of the internally provided fitness.
String getExternalFitnessProvider()
Gets the pathname of the external executable file.
boolean make3DTrees
Flag requesting the generation of a 3d-tree model instead of a plain collection of 3d building blocks...
void processParameters()
Processes all parameters and initialize related objects.
boolean checkPreFitnessUIDFromInput
Flag recording that we have explicitly expressed the choice of checkPreFitnessUID.
String getExternalFitnessProviderInterpreter()
Gets the interpreter used to run the external fitness provider.
boolean useExternalFitness
Flag indication we want to use external fitness provider.
String externalExe
Pathname of an external fitness provider executable.
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
List< String > customVarDescExpressions
List of custom variable definitions read from input.
boolean checkPreFitnessUID
Flag requesting to test for uniqueness of a candidate based on the unique identifier (UID) generated ...
List< DescriptorForFitness > getDescriptors()
String interpreterExternalExe
Interpreter for the external fitness provider.
boolean makePictures
Flag controlling production of png graphics for each candidate.
boolean writeCandidatesOnDisk
Flag requesting to write a file that collects all info on an evaluated candidate, i....
void checkParameters()
Evaluate consistency of input parameters.
List< DescriptorForFitness > descriptors
The list of descriptors needed to calculate the variables that are used to calculate the fitness with...
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
Collection of parameters controlling the behavior of the software.
Map< ParametersType, RunTimeParameters > otherParameters
Collection of other parameters by type.
static boolean readYesNoTrueFalse(String s)
Reads a string searching for any common way to say either yes/true (including shorthand t/y) or no/fa...
String paramTypeName()
Returns a string defining the type the parameters collected here.
void checkOtherParameters()
Checks any of the parameter collections contained in this instance.
final String NL
New line character.
void processOtherParameters()
Processes any of the parameter collections contained in this instance.
FIT_PARAMS
Parameters pertaining the calculation of fitness (i.e., the fitness provider).