$darkmode
DENOPTIM
FRParameters.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.programs.fitnessevaluator;
20
21import java.io.File;
22import java.lang.reflect.Field;
23import java.util.logging.Level;
24
25import denoptim.exception.DENOPTIMException;
26import denoptim.files.FileFormat;
27import denoptim.files.FileUtils;
28import denoptim.logging.StaticLogger;
29import denoptim.programs.RunTimeParameters;
30
31
38public class FRParameters extends RunTimeParameters
39{
43 private File inpFile = null;
44
48 private File outFile = new File("output.sdf");
49
53 protected boolean addTemplatesToLibraries = false;
54
59 private int walltime = 5;
60
61//-----------------------------------------------------------------------------
62
67 public FRParameters()
68 {
70 }
71
72//-----------------------------------------------------------------------------
73
74 public File getInputFile()
75 {
76 return inpFile;
77 }
78
79//-----------------------------------------------------------------------------
80
81 public File getOutputFile()
82 {
83 return outFile;
84 }
85
86//-----------------------------------------------------------------------------
87
95 public void interpretKeyword(String key, String value)
97 {
98 String msg = "";
99 switch (key.toUpperCase())
100 {
101 case "WORKDIR=":
102 workDir = value;
103 break;
104 case "INPUT=":
105 inpFile = new File(value);
106 break;
107 case "OUTPUT=":
108 outFile = new File(value);
109 break;
110 case "WALLTIME=":
111 walltime = Integer.parseInt(value);
112 break;
113 case "EXTRACTTEMPLATES":
115 break;
116 case "VERBOSITY=":
117 try
118 {
119 verbosity = Integer.parseInt(value);
120 }
121 catch (Throwable t)
122 {
123 msg = "Unable to understand value " + key + "'" + value + "'";
124 throw new DENOPTIMException(msg);
125 }
126 break;
127 default:
128 msg = "Keyword " + key + " is not a known "
129 + "related keyword for FitnessRunner. Check input files.";
130 throw new DENOPTIMException(msg);
131 }
132 }
133
134//-----------------------------------------------------------------------------
135
142 {
143 String msg = "";
144 if (!workDir.equals(".") && !FileUtils.checkExists(workDir))
145 {
146 msg = "Directory '" + workDir + "' not found. Please specify an "
147 + "existing directory.";
148 throw new DENOPTIMException(msg);
149 }
150
151 if (inpFile != null && !inpFile.exists())
152 {
153 msg = "File with input data not found. Check " + inpFile;
154 throw new DENOPTIMException(msg);
155 }
156
157 if (outFile != null && outFile.exists())
158 {
159 msg = "File meant for output ("
160 + outFile.getAbsolutePath()
161 + ")already exists and we do not overwrite.";
162 throw new DENOPTIMException(msg);
163 }
165 }
166
167//----------------------------------------------------------------------------
168
175 {
178
179 StaticLogger.appLogger.log(Level.INFO, "Output files associated with "
180 + "the current run are located in " + workDir);
181 }
182
183//------------------------------------------------------------------------------
184
191 public String getPrintedList()
192 {
193 StringBuilder sb = new StringBuilder(1024);
194 sb.append(" " + paramTypeName() + " ").append(NL);
195 for (Field f : this.getClass().getDeclaredFields())
196 {
197 try
198 {
199 sb.append(f.getName()).append(" = ").append(
200 f.get(this)).append(NL);
201 }
202 catch (Throwable t)
203 {
204 sb.append("ERROR! Unable to print " + paramTypeName()
205 + " parameters. Cause: " + t);
206 break;
207 }
208 }
209 for (RunTimeParameters otherCollector : otherParameters.values())
210 {
211 sb.append(otherCollector.getPrintedList());
212 }
213 return sb.toString();
214 }
215
216//----------------------------------------------------------------------------
217
223 public long getWallTime()
224 {
225 return walltime;
226 }
227
228//----------------------------------------------------------------------------
229
230}
static boolean checkExists(String fileName)
Definition: FileUtils.java:241
static void addToRecentFiles(String fileName, FileFormat ff)
Appends an entry to the list of recent files.
Definition: FileUtils.java:67
Logger class for DENOPTIM.
static final Logger appLogger
Collection of parameters controlling the behavior of the software.
Map< ParametersType, RunTimeParameters > otherParameters
Collection of other parameters by type.
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.
int verbosity
Verbosity level for logger.
Parameters controlling execution of FitnessRunner.
File outFile
File where the results of the fitness evaluation will be printed.
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
boolean addTemplatesToLibraries
Flag controlling attempt to add templates to building block libraries.
File inpFile
File with input for fitness provider.
void checkParameters()
Evaluate consistency of input parameters.
void processParameters()
Processes all parameters and initialize related objects.
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
long getWallTime()
Returns the maximum number of seconds to wait for the fitness provider to deliver a result.
int walltime
The maximum number of seconds we wait for the fitness provider to return a result.
File formats identified by DENOPTIM.
Definition: FileFormat.java:32
FR_PARAMS
Parameters controlling a stand-alone fitness evaluation run.