$darkmode
DENOPTIM
FileFormat.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2022 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.files;
20
21import java.util.Arrays;
22import java.util.HashSet;
23import java.util.Set;
24
25import denoptim.constants.DENOPTIMConstants;
26import denoptim.programs.RunTimeParameters.ParametersType;
27
32public enum FileFormat {
33
35 GRAPHJSON, GRAPHSDF, VRTXJSON, VRTXSDF, MOLSDF,
36 FSE_RUN, GA_RUN,
37
38 GA_PARAM, FSE_PARAM, FR_PARAM, COMP_MAP, GO_PARAM, CLG_PARAM, GE_PARAM,
39 GI_PARAM, B3D_PARAM, FRG_RUN, FRG_PARAM, CUTRULE, M2G_PARAM,
40
41 TXT, GRAPHTXT, GENSUMMARY,
43
44 private String extension = "";
45
53 private Set<String> definingRegex = new HashSet<String>();
54
60 private Set<String> negatingRegex = new HashSet<String>();
61
67 private String endOfSampleRegex = null;
68
69 private Boolean isFolder = false;
70
71 static {
72 GRAPHSDF.extension = "sdf";
73 GRAPHSDF.definingRegex = new HashSet<String>(Arrays.asList(
74 "^> *<" + DENOPTIMConstants.GRAPHTAG + ">.*",
75 "^> *<" + DENOPTIMConstants.GRAPHJSONTAG + ">.*"
76 ));
77 GRAPHSDF.negatingRegex = new HashSet<String>(Arrays.asList(
78 "^> *<" + DENOPTIMConstants.FITNESSTAG + ">.*",
79 "^> *<" + DENOPTIMConstants.MOLERRORTAG + ">.*",
80 "^> *<" + DENOPTIMConstants.UNIQUEIDTAG + ">.*",
81 "^> *<" + DENOPTIMConstants.VERTEXJSONTAG + ">.*"
82 ));
83 GRAPHSDF.endOfSampleRegex = "\\$\\$\\$\\$";
84
85 //------------------------------------
86
87 CANDIDATESDF.extension = "sdf";
88 CANDIDATESDF.definingRegex = new HashSet<String>(Arrays.asList(
89 "^> *<" + DENOPTIMConstants.FITNESSTAG + ">.*",
90 "^> *<" + DENOPTIMConstants.MOLERRORTAG + ">.*",
91 "^> *<" + DENOPTIMConstants.UNIQUEIDTAG + ">.*",
92 "^> *<" + DENOPTIMConstants.GRAPHJSONTAG + ">.*"
93 ));
94 CANDIDATESDF.endOfSampleRegex = "\\$\\$\\$\\$";
95
96 //------------------------------------
97
98 //TODO
99 GRAPHJSON.extension = "json";
100
101 //------------------------------------
102
103 //TODO
104 VRTXJSON.extension = "json";
105
106 //------------------------------------
107
108 VRTXSDF.extension = "sdf";
109 VRTXSDF.definingRegex = new HashSet<String>(Arrays.asList(
110 "^> *<" + DENOPTIMConstants.APSTAG+">.*"));
111 VRTXSDF.negatingRegex = new HashSet<String>(Arrays.asList(
112 "^> *<" + DENOPTIMConstants.FITNESSTAG + ">.*",
113 "^> *<" + DENOPTIMConstants.MOLERRORTAG + ">.*",
114 "^> *<" + DENOPTIMConstants.UNIQUEIDTAG + ">.*",
115 "^> *<" + DENOPTIMConstants.GRAPHJSONTAG + ">.*"
116 ));
117 VRTXSDF.endOfSampleRegex = "\\$\\$\\$\\$";
118
119 //------------------------------------
120
121 MOLSDF.extension = "sdf";
122 MOLSDF.negatingRegex = new HashSet<String>(Arrays.asList(
123 "^> *<" + DENOPTIMConstants.FITNESSTAG + ">.*",
124 "^> *<" + DENOPTIMConstants.APSTAG+">.*",
125 "^> *<" + DENOPTIMConstants.MOLERRORTAG + ">.*",
126 "^> *<" + DENOPTIMConstants.UNIQUEIDTAG + ">.*",
127 "^> *<" + DENOPTIMConstants.GRAPHJSONTAG + ">.*"
128 ));
129 MOLSDF.endOfSampleRegex = "\\$\\$\\$\\$";
130
131 //------------------------------------
132
133 FSE_RUN.extension = "";
134 FSE_RUN.isFolder = true;
135
136 //------------------------------------
137
138 FRG_RUN.extension = "";
139 FRG_RUN.isFolder = true;
140
141 //------------------------------------
142
143 GA_RUN.extension = "";
144 GA_RUN.isFolder = true;
145
146 //------------------------------------
147
148 GA_PARAM.extension = "";
149 GA_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
150 "^" + ParametersType.GA_PARAMS.getKeywordRoot() + ".*"));
151
152 //------------------------------------
153
154 FSE_PARAM.extension = "";
155 FSE_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
156 "^" + ParametersType.CEBL_PARAMS.getKeywordRoot() + ".*"));
157
158 //------------------------------------
159
160 FRG_PARAM.extension = "";
161 FRG_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
162 "^" + ParametersType.FRG_PARAMS.getKeywordRoot() + ".*"));
163
164 //------------------------------------
165
166 M2G_PARAM.extension = "";
167 M2G_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
168 "^" + ParametersType.M2G_PARAMS.getKeywordRoot() + ".*"));
169
170 //------------------------------------
171
172 CUTRULE.extension = "";
173 CUTRULE.definingRegex = new HashSet<String>(Arrays.asList(
174 "^CTR.*"));
175
176 //------------------------------------
177
178 FR_PARAM.extension = "";
179 FR_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
180 "^" + ParametersType.FR_PARAMS.getKeywordRoot() + ".*"));
181
182 //------------------------------------
183
184 COMP_MAP.extension = "";
185 COMP_MAP.definingRegex = new HashSet<String>(Arrays.asList(
186 "^RCN .*", "^RBO .*", "^CAP .*"));
187
188 //------------------------------------
189
190 GO_PARAM.extension = "";
191 GO_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
192 "^" + ParametersType.GO_PARAMS.getKeywordRoot() + ".*"));
193
194 //------------------------------------
195
196 GE_PARAM.extension = "";
197 GE_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
198 "^" + ParametersType.GE_PARAMS.getKeywordRoot() + ".*"));
199
200 //------------------------------------
201
202 CLG_PARAM.extension = "";
203 CLG_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
204 "^" + ParametersType.GLH_PARAMS.getKeywordRoot() + ".*"));
205
206 //------------------------------------
207
208 GI_PARAM.extension = "";
209 GI_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
210 "^" + ParametersType.ISO_PARAMS.getKeywordRoot() + ".*"));
211
212 B3D_PARAM.extension = "";
213 B3D_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
214 "^" + ParametersType.MMB_PARAM.getKeywordRoot() + ".*"));
215
216 //------------------------------------
217
218 TXT.extension = "";
219
220 //------------------------------------
221
222 GRAPHTXT.extension = "txt";
223
224 //------------------------------------
225
226 GENSUMMARY.extension = "txt";
227 GENSUMMARY.definingRegex = new HashSet<String>(Arrays.asList(
229 // WARNING: format of the GENSUMMARY is expected by methods such as
230 // DenoptimIO.readPopulationMembersTraces
231 // Any change of format should could cause the need to change those
232 // methods.
233 }
234
238 public enum DataKind {GRAPH, VERTEX, GA_RUN, FSE_RUN, GA_PARAM, FSE_PARAM,
239 FR_PARAM, GO_PARAM, CLG_PARAM, GE_PARAM, GI_PARAM, COMP_MAP, B3D_PARAM,
241 FRG_RUN, FRG_PARAM}
242
243//------------------------------------------------------------------------------
244
253 public static FileFormat fromString(String extension, DataKind kind) {
254 FileFormat ff = null;
255 switch (extension.toUpperCase())
256 {
257 case "SDF":
258 switch (kind)
259 {
260 case GRAPH:
261 ff = GRAPHSDF;
262 break;
263 case VERTEX:
264 ff = VRTXSDF;
265 break;
266 default:
267 ff = MOLSDF;
268 break;
269 }
270 break;
271 case "JSON":
272 switch (kind)
273 {
274 case GRAPH:
275 ff = GRAPHJSON;
276 break;
277 case VERTEX:
278 ff = VRTXJSON;
279 break;
280 default:
281 break;
282 }
283 break;
284
285 case "TXT":
286 switch (kind)
287 {
288 case GRAPH:
289 ff = GRAPHTXT;
290 break;
291 default:
292 break;
293 }
294 break;
295
296 case "":
297 switch (kind)
298 {
299 case GA_RUN:
300 ff = GA_RUN;
301 break;
302 case FSE_RUN:
303 ff = FSE_RUN;
304 break;
305 case GA_PARAM:
306 ff = GA_PARAM;
307 break;
308 case M2G_PARAM:
309 ff = M2G_PARAM;
310 case FRG_RUN:
311 ff = FRG_RUN;
312 break;
313 case FRG_PARAM:
314 ff = FRG_PARAM;
315 break;
316 case FSE_PARAM:
317 ff = FSE_PARAM;
318 break;
319 case FR_PARAM:
320 ff = FR_PARAM;
321 break;
322 case GO_PARAM:
323 ff = GO_PARAM;
324 break;
325 case GE_PARAM:
326 ff = GE_PARAM;
327 break;
328 case CLG_PARAM:
329 ff = CLG_PARAM;
330 break;
331 case GI_PARAM:
332 ff = GI_PARAM;
333 break;
334 case COMP_MAP:
335 ff = COMP_MAP;
336 break;
337 case B3D_PARAM:
338 ff = B3D_PARAM;
339 break;
340 default:
341 break;
342 }
343 break;
344 }
345 return ff;
346 }
347
348//------------------------------------------------------------------------------
349
354 public static FileFormat[] getSDFFormats()
355 {
356 FileFormat[] a = {
357 // GraphSDF must come before Vertex SDF
362 return a;
363 }
364
365//------------------------------------------------------------------------------
366
372 {
373 FileFormat[] a = {
379 // GA must come after others that might use GA parameters, for example
380 // the setting of the random seed)
387 return a;
388 }
389
390//------------------------------------------------------------------------------
391
397 public static FileFormat[] getTXTFormats()
398 {
399 FileFormat[] a = {
403 FileFormat.TXT
404 };
405 return a;
406 }
407
408//------------------------------------------------------------------------------
409
413 public boolean isFolder()
414 {
415 return isFolder;
416 }
417
418//------------------------------------------------------------------------------
419
426 public String getSampleEndRegex()
427 {
428 return endOfSampleRegex;
429 }
430
431//------------------------------------------------------------------------------
432
437 public Set<String> getDefiningRegex()
438 {
439 return definingRegex;
440 }
441
442//------------------------------------------------------------------------------
443
448 public Set<String> getNegatingRegex()
449 {
450 return negatingRegex;
451 }
452
453//------------------------------------------------------------------------------
454
455 public String getExtension()
456 {
457 return extension;
458 }
459
460//------------------------------------------------------------------------------
461
462}
General set of constants used in DENOPTIM.
static final String GRAPHTAG
SDF tag containing graph encoding.
static final String VERTEXJSONTAG
SDF tag containing vertex encoding in JSON format.
static final String APSTAG
SDF tag defining attachment points.
static final String GAGENSUMMARYHEADER
Header of text files collection generation details.
static final String UNIQUEIDTAG
SDF tag containing the unique identifier of a candidate.
static final String GRAPHJSONTAG
SDF tag containing graph encoding in JSON format.
static final String MOLERRORTAG
SDF tag containing errors during execution of molecule specific tasks.
static final String FITNESSTAG
SDF tag containing the fitness of a candidate.
The kind of data found in a file.
File formats identified by DENOPTIM.
Definition: FileFormat.java:32
Set< String > getDefiningRegex()
Returns the list of regex strings that allow identification of a file.
static FileFormat[] getParameterFormats()
Returns the collection of file formats with input parameters.
Set< String > getNegatingRegex()
Returns the list of regex strings that exclude a file format.
static FileFormat[] getSDFFormats()
Returns the collection of file formats using SDF syntax.
String getSampleEndRegex()
In identifying a text file we read as many lines as possible until we match the "end-of-sample" strin...
static FileFormat[] getTXTFormats()
Returns the collection of file formats restricted to TXT files (excluded parameter files)
static FileFormat fromString(String extension, DataKind kind)
Gets the FileFormat from file extension and kind of data.
GO_PARAMS
Parameters controlling stand-alone run of genetic operators.
FR_PARAMS
Parameters controlling a stand-alone fitness evaluation run.
M2G_PARAMS
Parameters controlling molecule-to-graph conversion.
CEBL_PARAMS
Parameters pertaining the combinatorial exploration by layer.
ISO_PARAMS
Parameters controlling the stand-alone detection of graph isomorphism.
FRG_PARAMS
Parameters controlling the fragmenter.
MMB_PARAM
Parameters pertaining the construction of three-dimensional molecular models using the Tinker-based m...
GLH_PARAMS
Parameters controlling the stand-alone management of list of graphs.
GA_PARAMS
Parameters pertaining the genetic algorithm.
GE_PARAMS
Parameters controlling the stand-alone editing of graphs.