$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,
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 CUTRULE.extension = "";
167 CUTRULE.definingRegex = new HashSet<String>(Arrays.asList(
168 "^CTR.*"));
169
170 //------------------------------------
171
172 FR_PARAM.extension = "";
173 FR_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
174 "^" + ParametersType.FR_PARAMS.getKeywordRoot() + ".*"));
175
176 //------------------------------------
177
178 COMP_MAP.extension = "";
179 COMP_MAP.definingRegex = new HashSet<String>(Arrays.asList(
180 "^RCN .*", "^RBO .*", "^CAP .*"));
181
182 //------------------------------------
183
184 GO_PARAM.extension = "";
185 GO_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
186 "^" + ParametersType.GO_PARAMS.getKeywordRoot() + ".*"));
187
188 //------------------------------------
189
190 GE_PARAM.extension = "";
191 GE_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
192 "^" + ParametersType.GE_PARAMS.getKeywordRoot() + ".*"));
193
194 //------------------------------------
195
196 CLG_PARAM.extension = "";
197 CLG_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
198 "^" + ParametersType.GLH_PARAMS.getKeywordRoot() + ".*"));
199
200 //------------------------------------
201
202 GI_PARAM.extension = "";
203 GI_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
204 "^" + ParametersType.ISO_PARAMS.getKeywordRoot() + ".*"));
205
206 B3D_PARAM.extension = "";
207 B3D_PARAM.definingRegex = new HashSet<String>(Arrays.asList(
208 "^" + ParametersType.MMB_PARAM.getKeywordRoot() + ".*"));
209
210 //------------------------------------
211
212 TXT.extension = "";
213
214 //------------------------------------
215
216 GRAPHTXT.extension = "txt";
217
218 //------------------------------------
219
220 GENSUMMARY.extension = "txt";
221 GENSUMMARY.definingRegex = new HashSet<String>(Arrays.asList(
223 // WARNING: format of the GENSUMMARY is expected by methods such as
224 // DenoptimIO.readPopulationMembersTraces
225 // Any change of format should could cause the need to change those
226 // methods.
227 }
228
232 public enum DataKind {GRAPH, VERTEX, GA_RUN, FSE_RUN, GA_PARAM, FSE_PARAM,
233 FR_PARAM, GO_PARAM, CLG_PARAM, GE_PARAM, GI_PARAM, COMP_MAP, B3D_PARAM,
234 FRG_RUN, FRG_PARAM}
235
236//------------------------------------------------------------------------------
237
246 public static FileFormat fromString(String extension, DataKind kind) {
247 FileFormat ff = null;
248 switch (extension.toUpperCase())
249 {
250 case "SDF":
251 switch (kind)
252 {
253 case GRAPH:
254 ff = GRAPHSDF;
255 break;
256 case VERTEX:
257 ff = VRTXSDF;
258 break;
259 default:
260 ff = MOLSDF;
261 break;
262 }
263 break;
264 case "JSON":
265 switch (kind)
266 {
267 case GRAPH:
268 ff = GRAPHJSON;
269 break;
270 case VERTEX:
271 ff = VRTXJSON;
272 break;
273 default:
274 break;
275 }
276 break;
277
278 case "TXT":
279 switch (kind)
280 {
281 case GRAPH:
282 ff = GRAPHTXT;
283 break;
284 default:
285 break;
286 }
287 break;
288
289 case "":
290 switch (kind)
291 {
292 case GA_RUN:
293 ff = GA_RUN;
294 break;
295 case FSE_RUN:
296 ff = FSE_RUN;
297 break;
298 case GA_PARAM:
299 ff = GA_PARAM;
300 break;
301 case FRG_RUN:
302 ff = FRG_RUN;
303 break;
304 case FRG_PARAM:
305 ff = FRG_PARAM;
306 break;
307 case FSE_PARAM:
308 ff = FSE_PARAM;
309 break;
310 case FR_PARAM:
311 ff = FR_PARAM;
312 break;
313 case GO_PARAM:
314 ff = GO_PARAM;
315 break;
316 case GE_PARAM:
317 ff = GE_PARAM;
318 break;
319 case CLG_PARAM:
320 ff = CLG_PARAM;
321 break;
322 case GI_PARAM:
323 ff = GI_PARAM;
324 break;
325 case COMP_MAP:
326 ff = COMP_MAP;
327 break;
328 case B3D_PARAM:
329 ff = B3D_PARAM;
330 break;
331 default:
332 break;
333 }
334 break;
335 }
336 return ff;
337 }
338
339//------------------------------------------------------------------------------
340
345 public static FileFormat[] getSDFFormats()
346 {
347 FileFormat[] a = {
348 // GraphSDF must come before Vertex SDF
353 return a;
354 }
355
356//------------------------------------------------------------------------------
357
363 {
364 FileFormat[] a = {
370 // GA must come after others that might use GA parameters, for example
371 // the setting of the random seed)
377 return a;
378 }
379
380//------------------------------------------------------------------------------
381
387 public static FileFormat[] getTXTFormats()
388 {
389 FileFormat[] a = {
393 FileFormat.TXT
394 };
395 return a;
396 }
397
398//------------------------------------------------------------------------------
399
403 public boolean isFolder()
404 {
405 return isFolder;
406 }
407
408//------------------------------------------------------------------------------
409
416 public String getSampleEndRegex()
417 {
418 return endOfSampleRegex;
419 }
420
421//------------------------------------------------------------------------------
422
427 public Set<String> getDefiningRegex()
428 {
429 return definingRegex;
430 }
431
432//------------------------------------------------------------------------------
433
438 public Set<String> getNegatingRegex()
439 {
440 return negatingRegex;
441 }
442
443//------------------------------------------------------------------------------
444
445 public String getExtension()
446 {
447 return extension;
448 }
449
450//------------------------------------------------------------------------------
451
452}
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.
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.