$darkmode
DENOPTIM
GraphListsHandlerParameters.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.programs.graphlisthandler;
20
21import java.io.File;
22import java.lang.reflect.Field;
23import java.util.ArrayList;
24
25import denoptim.exception.DENOPTIMException;
26import denoptim.files.FileFormat;
27import denoptim.files.FileUtils;
28import denoptim.graph.DGraph;
29import denoptim.io.DenoptimIO;
30import denoptim.programs.RunTimeParameters;
31
32
40{
44 private String inGraphsFileA = null;
45 private String inGraphsFileB = null;
46
50 protected ArrayList<DGraph> inGraphsA =
51 new ArrayList<DGraph>();
52
56 protected ArrayList<DGraph> inGraphsB =
57 new ArrayList<DGraph>();
58
62 private String outGraphsFile = null;
64
65//-----------------------------------------------------------------------------
66
71 {
73 }
74
75//-----------------------------------------------------------------------------
76
77 public String getOutFile()
78 {
79 return outGraphsFile;
80 }
81
82//-----------------------------------------------------------------------------
83
85 {
86 return outGraphsFormat;
87 }
88
89//-----------------------------------------------------------------------------
90
98 public void interpretKeyword(String key, String value)
100 {
101 String msg = "";
102 switch (key.toUpperCase())
103 {
104 case "WORKDIR=":
105 workDir = value;
106 break;
107 case "INPUTGRAPHS-A=":
108 inGraphsFileA = value;
109 break;
110 case "INPUTGRAPHS-B=":
111 inGraphsFileB = value;
112 break;
113 case "OUTPUTGRAPHS=":
114 outGraphsFile = value;
115 break;
116 case "OUTPUTGRAPHSFORMAT=":
117 outGraphsFormat = FileFormat.valueOf(value.toUpperCase());
118 break;
119 case "LOGFILE=":
120 logFile = value;
121 break;
122 case "VERBOSITY=":
123 try
124 {
125 verbosity = Integer.parseInt(value);
126 }
127 catch (Throwable t)
128 {
129 msg = "Unable to understand value " + key + "'" + value + "'";
130 throw new DENOPTIMException(msg);
131 }
132 break;
133 default:
134 msg = "Keyword " + key + " is not a known GraphListHandler-"
135 + "related keyword. Check input files.";
136 throw new DENOPTIMException(msg);
137 }
138 }
139
140//------------------------------------------------------------------------------
141
148 public String getPrintedList()
149 {
150 StringBuilder sb = new StringBuilder(1024);
151 sb.append(" " + paramTypeName() + " ").append(NL);
152 for (Field f : this.getClass().getDeclaredFields())
153 {
154 try
155 {
156 sb.append(f.getName()).append(" = ").append(
157 f.get(this)).append(NL);
158 }
159 catch (Throwable t)
160 {
161 sb.append("ERROR! Unable to print " + paramTypeName()
162 + " parameters. Cause: " + t);
163 break;
164 }
165 }
166 for (RunTimeParameters otherCollector : otherParameters.values())
167 {
168 sb.append(otherCollector.getPrintedList());
169 }
170 return sb.toString();
171 }
172
173//------------------------------------------------------------------------------
174
181 {
182 String msg = "";
183 if (!workDir.equals(".") && !FileUtils.checkExists(workDir))
184 {
185 msg = "Directory " + workDir + " not found. Please specify an "
186 + "existing directory.";
187 throw new DENOPTIMException(msg);
188 }
189
190 if (inGraphsFileA == null || inGraphsFileB == null)
191 {
192 msg = "Input file with graphs to edit not define. Check you input.";
193 throw new DENOPTIMException(msg);
194 }
195 else if (inGraphsFileA != null
197 {
198 msg = "File with input graphs not found. Check " + inGraphsFileA;
199 throw new DENOPTIMException(msg);
200 }
201 else if (inGraphsFileB != null
203 {
204 msg = "File with input graphs not found. Check " + inGraphsFileB;
205 throw new DENOPTIMException(msg);
206 }
207
209 {
210 msg = "Ouput file '" + outGraphsFile + "' exists aleary!";
211 throw new DENOPTIMException(msg);
212 }
213
215 }
216
217//------------------------------------------------------------------------------
218
224 {
226
227 if (outGraphsFile == null)
228 {
229 outGraphsFile = "graphListHandler.output" ;
231 {
232 String msg = "Ouput file '" + outGraphsFile +
233 "' exists aleary!";
234 throw new DENOPTIMException(msg);
235 }
236 }
237
238 try
239 {
244 }
245 catch (Throwable t)
246 {
247 throw new Error("Cannot read in graphs from " + inGraphsFileA +" or "
248 + inGraphsFileB);
249 }
250 }
251
252//------------------------------------------------------------------------------
253
254}
static boolean checkExists(String fileName)
Definition: FileUtils.java:241
Utility methods for input/output.
static ArrayList< DGraph > readDENOPTIMGraphsFromFile(File inFile)
Reads a list of <DGraphs from file.
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.
void processParameters()
Processes all parameters and initialize related objects.
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
File formats identified by DENOPTIM.
Definition: FileFormat.java:32
GLH_PARAMS
Parameters controlling the stand-alone management of list of graphs.