$darkmode
DENOPTIM
GraphEditor.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.grapheditor;
20
21import java.io.File;
22import java.util.ArrayList;
23import java.util.List;
24
25import denoptim.fragspace.FragmentSpaceParameters;
26import denoptim.graph.DGraph;
27import denoptim.io.DenoptimIO;
28import denoptim.programs.RunTimeParameters.ParametersType;
29import denoptim.task.ProgramTask;
30
31
38public class GraphEditor extends ProgramTask
39{
40
41//------------------------------------------------------------------------------
42
48 public GraphEditor(File configFile, File workDir)
49 {
50 super(configFile,workDir);
51 }
52
53//------------------------------------------------------------------------------
54
55 @Override
56 public void runProgram() throws Throwable
57 {
58 GraphEdParameters geParams = new GraphEdParameters();
59 geParams.readParameterFile(configFilePathName.getAbsolutePath());
60 geParams.checkParameters();
61 geParams.processParameters();
62 geParams.startProgramSpecificLogger(loggerIdentifier, false); //to STDOUT
63 geParams.printParameters();
64
65 // We might need the fragment space to read the input graphs with
66 // string-based encoding. Therefore, we read the graph after.
67 geParams.readInputGraphs();
68
71 {
72 fsParams = (FragmentSpaceParameters)geParams.getParameters(
74 }
75
76 List<DGraph> modGraphs = new ArrayList<DGraph>();
77 for (DGraph graph : geParams.getInputGraphs())
78 {
79 DGraph modGraph = graph.editGraph(
80 geParams.getGraphEditTasks(),
81 geParams.symmetryFlag(),
82 fsParams.getFragmentSpace(),
83 geParams.getLogger());
84 modGraphs.add(modGraph);
85 }
86 DenoptimIO.writeGraphsToFile(new File(geParams.getOutFile()),
87 geParams.getOutFormat(), modGraphs, geParams.getLogger(),
88 geParams.getRandomizer());
89 }
90
91//-----------------------------------------------------------------------------
92
93}
Parameters defining the fragment space.
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:102
DGraph editGraph(ArrayList< GraphEdit > edits, boolean symmetry, FragmentSpace fragSpace, Logger logger)
Edit this graph according to a given list of edit tasks.
Definition: DGraph.java:6453
Utility methods for input/output.
static File writeGraphsToFile(File file, FileFormat format, List< DGraph > modGraphs, Logger logger, Randomizer randomizer)
Writes the graphs to file.
Logger startProgramSpecificLogger(String loggerIdentifier)
Starts a logger with the given name.
boolean containsParameters(ParametersType type)
RunTimeParameters getParameters(ParametersType type)
void readParameterFile(String infile)
Read the parameter TXT file line by line and interpret its content.
Logger getLogger()
Get the name of the program specific logger.
void printParameters()
Print all parameters.
Randomizer getRandomizer()
Returns the current program-specific randomizer.
Parameters controlling execution of GraphEditor.
void checkParameters()
Evaluate consistency of input parameters.
void processParameters()
Processes all parameters and initialize related objects.
GraphEditor(File configFile, File workDir)
Creates and configures the program task.
Task structure for any of the main programs in the denoptim project, such as genetic algorithm and co...
String loggerIdentifier
Identifier of this program's logger.
File configFilePathName
File containing configuration parameters for the program task.
File workDir
The file system location where we want to be placed when doing the work.
Definition: Task.java:78
FS_PARAMS
Parameters pertaining the definition of the fragment space.