$darkmode
DENOPTIM
CEBLParameters.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.combinatorial;
20
21import java.io.File;
22import java.lang.reflect.Field;
23import java.text.SimpleDateFormat;
24import java.util.ArrayList;
25import java.util.Date;
26import java.util.logging.Level;
27
28import denoptim.combinatorial.CEBLUtils;
29import denoptim.combinatorial.CheckPoint;
30import denoptim.constants.DENOPTIMConstants;
31import denoptim.exception.DENOPTIMException;
32import denoptim.files.FileFormat;
33import denoptim.files.FileUtils;
34import denoptim.fitness.FitnessParameters;
35import denoptim.graph.DGraph;
36import denoptim.io.DenoptimIO;
37import denoptim.logging.StaticLogger;
38import denoptim.programs.RunTimeParameters;
39
40
49{
53 private String rootGraphsFile = null;
54
59 private boolean useGivenRoots = false;
60
64 private ArrayList<DGraph> rootGraphs;
65
69 private String uidFile = "UID.txt";
70
75 private boolean runFitnessTask = false;
76
81 private String dbRootDir = ".";
82
86 private int numCPU = 1;
87
91 private long maxWait = 600000L; //Default 10 min
92
96 private long waitStep = 5000L; //Default 5 sec
97
102 private int maxLevel = 2;
103
108 private int chkptStep = 100;
109
113 private CheckPoint chkpt = null;
114
118 private String chkptFile = null;
119
123 private boolean chkptRestart = false;
124
131 private boolean prepareChkAndSerForTests = false;
132
133//-----------------------------------------------------------------------------
134
139 {
141 }
142
143//-----------------------------------------------------------------------------
144
145 public ArrayList<DGraph> getRootGraphs()
146 {
147 return rootGraphs;
148 }
149
150//-----------------------------------------------------------------------------
151
152 public String getUIDFileName()
153 {
154 return uidFile;
155 }
156
157//-----------------------------------------------------------------------------
158
159 public boolean submitFitnessTask()
160 {
161 return runFitnessTask;
162 }
163
164//-----------------------------------------------------------------------------
165
166 public String getDBRoot()
167 {
168 return dbRootDir;
169 }
170
171//-----------------------------------------------------------------------------
172
173 public void setDBRoot(String pathname)
174 {
175 this.dbRootDir = pathname;
176 }
177
178//-----------------------------------------------------------------------------
179
180 public int getNumberOfCPU()
181 {
182 return numCPU;
183 }
184
185//-----------------------------------------------------------------------------
186
187 public long getMaxWait()
188 {
189 return maxWait;
190 }
191
192//-----------------------------------------------------------------------------
193
194 public long getWaitStep()
195 {
196 return waitStep;
197 }
198
199//-----------------------------------------------------------------------------
200
201 public int getMaxLevel()
202 {
203 return maxLevel;
204 }
205
206//-----------------------------------------------------------------------------
207
208 public boolean useGivenRoots()
209 {
210 return useGivenRoots;
211 }
212
213//-----------------------------------------------------------------------------
214
215 public int getCheckPointStep()
216 {
217 return chkptStep;
218 }
219
220//-----------------------------------------------------------------------------
221
222 public String getCheckPointName()
223 {
224 return chkptFile;
225 }
226
227//-----------------------------------------------------------------------------
228
230 {
231 return chkpt;
232 }
233
234//-----------------------------------------------------------------------------
235
236 public boolean restartFromCheckPoint()
237 {
238 return chkptRestart;
239 }
240
241//-----------------------------------------------------------------------------
242
243 public boolean prepareFilesForTests()
244 {
246 }
247
248//-----------------------------------------------------------------------------
249
256 public void interpretKeyword(String key, String value)
257 throws DENOPTIMException
258 {
259 String msg = "";
260 switch (key.toUpperCase())
261 {
262 case "WORKDIR=":
263 workDir = value;
264 break;
265 case "ROOTGRAPHS=":
266 rootGraphsFile = value;
267 useGivenRoots = true;
268 break;
269 case "UIDFILE=":
270 uidFile = value;
271 break;
272 case "RESTARTFROMCHECKPOINT=":
273 chkptFile = value;
274 chkptRestart = true;
275 break;
276 case "DEVEL-PREPAREFILESFORTESTS=":
278 break;
279 case "CHECKPOINTSTEPLENGTH=":
280 try
281 {
282 chkptStep = Integer.parseInt(value);
283 }
284 catch (Throwable t)
285 {
286 msg = "Unable to understand value " + key + "'" + value + "'";
287 throw new DENOPTIMException(msg);
288 }
289 break;
290 case "DBROOTFOLDER=":
291 //NB: this key 'DBROOTFOLDER' is hard coded also in CombinatorialExplorerByLayer
292 dbRootDir = value;
293 break;
294 case "NUMOFPROCESSORS=":
295 try
296 {
297 numCPU = Integer.parseInt(value);
298 }
299 catch (Throwable t)
300 {
301 msg = "Unable to understand value " + key + "'" + value + "'";
302 throw new DENOPTIMException(msg);
303 }
304 break;
305 case "MAXWAIT=":
306 try
307 {
308 maxWait = Long.parseLong(value, 10) * 1000L;
309 }
310 catch (Throwable t)
311 {
312 msg = "Unable to understand value " + key + "'" + value + "'";
313 throw new DENOPTIMException(msg);
314 }
315 break;
316 case "WAITSTEP=":
317 try
318 {
319 waitStep = Long.parseLong(value, 10) * 1000L;
320 }
321 catch (Throwable t)
322 {
323 msg = "Unable to understand value " + key + "'" + value + "'";
324 throw new DENOPTIMException(msg);
325 }
326 break;
327 case "MAXLEVEL=":
328 try
329 {
330 maxLevel = Integer.parseInt(value);
331 }
332 catch (Throwable t)
333 {
334 msg = "Unable to understand value " + key + "'" + value + "'";
335 throw new DENOPTIMException(msg);
336 }
337 break;
338 case "VERBOSITY=":
339 try
340 {
341 verbosity = Integer.parseInt(value);
342 }
343 catch (Throwable t)
344 {
345 msg = "Unable to understand value " + key + "'" + value + "'";
346 throw new DENOPTIMException(msg);
347 }
348 break;
349 default:
350 msg = "Keyword " + key + " is not a known FragmentSpaceExplorer-"
351 + "related keyword. Check input files.";
352 throw new DENOPTIMException(msg);
353 }
354 }
355
356//-----------------------------------------------------------------------------
357
364 {
365 String msg = "";
366
368 {
369 runFitnessTask = true;
370 } else {
371 // We ensure there is a fitness parameters because we'll take the
372 // logger and default settings from there in GraphBuildingTask
374 new FitnessParameters());
375 }
376
377 if (!workDir.equals(".") && !FileUtils.checkExists(workDir))
378 {
379 msg = "Directory '" + workDir + "' not found. Please specify an "
380 + "existing directory.";
381 throw new DENOPTIMException(msg);
382 }
383
385 {
386 msg = "Directory '" + dbRootDir + "' not found. "
387 + "Please specify an existing directory where to put "
388 + "the DB of generated DENOPTIMGraphs.";
389 throw new DENOPTIMException(msg);
390 }
391
393 {
394 msg = "File with root graphs not found. Check " + rootGraphsFile;
395 throw new DENOPTIMException(msg);
396 }
397
398 if (numCPU <= 0 )
399 {
400 msg = "Number of processors (" + numCPU + ") is not valid. "
401 + "Setting its value to 1.";
402 numCPU = 1;
403 StaticLogger.appLogger.info(msg);
404 }
405
406 if (maxLevel < 0)
407 {
408 msg = "The maximum level must be larger than zero.";
409 throw new DENOPTIMException(msg);
410 }
411
412 if (chkptFile != null && !FileUtils.checkExists(chkptFile))
413 {
414 msg = "Checkpoint file " + chkptFile + " not found. ";
415 throw new DENOPTIMException(msg);
416 }
417
418 if (chkptStep < 2)
419 {
420 msg = "The minimum acceptable value for the number of submitted "
421 + "tasks between two checkpoint files is 2. Change your "
422 + "input";
423 throw new DENOPTIMException(msg);
424 }
425
427 }
428
429//----------------------------------------------------------------------------
430
437 {
438 if (isMaster)
440
442
443 if (useGivenRoots)
444 {
445 try
446 {
448 new File(rootGraphsFile));
449 }
450 catch (Throwable t)
451 {
452 String msg = "Cannot read root graphs from " + rootGraphsFile;
453 throw new Error(msg,t);
454 }
455 }
456
457 if (chkptRestart)
458 {
460 }
461 else
462 {
463 chkpt = new CheckPoint();
464 chkptFile = workDir + ".chk";
465 }
466
467 if (isMaster)
468 {
469 StaticLogger.appLogger.log(Level.INFO, "Program log file: "
471 + "Output files associated with the current run are "
472 + "located in " + workDir);
473 }
474 }
475
476//------------------------------------------------------------------------------
477
479 {
480 String curDir = workDir;
481 String fileSep = System.getProperty("file.separator");
482 boolean success = false;
483 while (!success)
484 {
485 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmss");
486 String str = "FSE" + sdf.format(new Date());
487 workDir = curDir + fileSep + str;
489 }
491 if (dbRootDir.equals(".") || dbRootDir.equals(""))
492 {
494 }
495 logFile = workDir + ".log";
496 }
497
498//------------------------------------------------------------------------------
499
506 public String getPrintedList()
507 {
508 StringBuilder sb = new StringBuilder(1024);
509 sb.append(" " + paramTypeName() + " ").append(NL);
510 for (Field f : this.getClass().getDeclaredFields())
511 {
512 try
513 {
514 sb.append(f.getName()).append(" = ").append(
515 f.get(this)).append(NL);
516 }
517 catch (Throwable t)
518 {
519 sb.append("ERROR! Unable to print " + paramTypeName()
520 + " parameters. Cause: " + t);
521 break;
522 }
523 }
524 for (RunTimeParameters otherCollector : otherParameters.values())
525 {
526 sb.append(otherCollector.getPrintedList());
527 }
528 return sb.toString();
529 }
530
531//----------------------------------------------------------------------------
532
533}
Helper methods for the exploration of the fragment space.
Definition: CEBLUtils.java:45
static CheckPoint deserializeCheckpoint(String file)
Converts a text file into the corresponding checkpoint object.
Definition: CEBLUtils.java:237
Object collecting information needed to restart a FragSpaceExplorer job.
Definition: CheckPoint.java:40
General set of constants used in DENOPTIM.
static final String EOL
new line character
static boolean checkExists(String fileName)
Definition: FileUtils.java:241
static boolean createDirectory(String fileName)
Creates a directory.
Definition: FileUtils.java:231
static void addToRecentFiles(String fileName, FileFormat ff)
Appends an entry to the list of recent files.
Definition: FileUtils.java:67
Settings defining the calculation of fitness.
Utility methods for input/output.
static ArrayList< DGraph > readDENOPTIMGraphsFromFile(File inFile)
Reads a list of <DGraphs from file.
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.
boolean isMaster
Flag signaling this is the master collection of parameters.
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 the combinatorial algorithm for exploration of a fragment space b...
CheckPoint chkpt
Checkpoint for restarting an interrupted FSE run.
void processParameters()
Processes all parameters and initialize related objects.
ArrayList< DGraph > rootGraphs
User defined list of root graphs.
String chkptFile
Name of checkpoint file for restarting an interrupted FSE run.
boolean runFitnessTask
Flag: optionally perform an evaluation of the fitness/descriptors on each accepted graph.
void checkParameters()
Evaluate consistency of input parameters.
String rootGraphsFile
File with user defined list of root graphs.
boolean chkptRestart
Flag defining a restart from checkpoint file.
boolean prepareChkAndSerForTests
Flag requiring generation of the checkpoint files for the testing suite.
boolean useGivenRoots
Flag declaring that generation of graphs will use a given list of graphs as starting points for the e...
String dbRootDir
Folder containing DENOPTIMGraphs sorted by level and reported as Strings.
long maxWait
Maximum wait for completion of a level (millisec)
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
int maxLevel
Maximum level accepted: number of frag-frag bond from the origin (i.e., the scaffolds)
int chkptStep
Number of combinations between every check out of the current position into a checkpoint file.
long waitStep
Time step between each check for completion of a level (millisec)
File formats identified by DENOPTIM.
Definition: FileFormat.java:32
CEBL_PARAMS
Parameters pertaining the combinatorial exploration by layer.
FIT_PARAMS
Parameters pertaining the calculation of fitness (i.e., the fitness provider).