Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Refactor - Disentangle domain setup and run configuration #104

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/java/nl/uu/cs/ape/APE.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
import nl.uu.cs.ape.configuration.APERunConfig;
import nl.uu.cs.ape.configuration.tags.validation.ValidationResults;
import nl.uu.cs.ape.constraints.ConstraintTemplate;
import nl.uu.cs.ape.domain.APEDimensionsException;
import nl.uu.cs.ape.domain.APEDomainSetup;
import nl.uu.cs.ape.domain.OWLReader;
import nl.uu.cs.ape.models.MappingsException;
import nl.uu.cs.ape.models.enums.SynthesisFlag;
import nl.uu.cs.ape.models.logic.constructs.TaxonomyPredicate;
import nl.uu.cs.ape.solver.SynthesisEngine;
import nl.uu.cs.ape.solver.domainconfiguration.APEDimensionsException;
import nl.uu.cs.ape.solver.domainconfiguration.Domain;
import nl.uu.cs.ape.solver.minisat.SATSynthesisEngine;
import nl.uu.cs.ape.solver.solutionStructure.SolutionWorkflow;
import nl.uu.cs.ape.solver.solutionStructure.SolutionsList;
import nl.uu.cs.ape.solver.solutionStructure.cwl.DefaultCWLCreator;
import nl.uu.cs.ape.utils.APEFiles;
import nl.uu.cs.ape.utils.APEUtils;
import nl.uu.cs.ape.utils.OWLReader;

/**
* The {@code APE} class is the main class of the library and is supposed to be
Expand All @@ -52,7 +52,7 @@ public class APE implements APEInterface {
private final APECoreConfig config;

/** Object containing general APE encoding. */
private APEDomainSetup apeDomainSetup;
private Domain apeDomainSetup;

/**
* Create instance of the APE solver.
Expand Down Expand Up @@ -125,7 +125,7 @@ private boolean setupDomain() throws APEDimensionsException, IOException, OWLOnt
* Encode the taxonomies as objects - generate the list of all types / modules
* occurring in the taxonomies defining their submodules/subtypes
*/
apeDomainSetup = new APEDomainSetup(config);
apeDomainSetup = new Domain(config);

OWLReader owlReader = new OWLReader(apeDomainSetup, config.getOntologyFile());
boolean ontologyRead = owlReader.readOntology();
Expand Down Expand Up @@ -185,7 +185,7 @@ public APECoreConfig getConfig() {
* @return The object that contains all crucial information about the domain
* (e.g. list of tools, data types, constraint factory, etc.)
*/
public APEDomainSetup getDomainSetup() {
public Domain getDomainSetup() {
return apeDomainSetup;
}

Expand Down Expand Up @@ -284,7 +284,7 @@ public SolutionsList runSynthesis(APERunConfig runConfig) throws IOException, JS
* file.
* @throws JSONException Error in configuration object.
*/
private SolutionsList runSynthesis(JSONObject runConfigJson, APEDomainSetup apeDomainSetup)
private SolutionsList runSynthesis(JSONObject runConfigJson, Domain apeDomainSetup)
throws IOException, JSONException, APEConfigException {
apeDomainSetup.clearConstraints();
APERunConfig runConfig = new APERunConfig(runConfigJson, apeDomainSetup);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nl/uu/cs/ape/APEInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import nl.uu.cs.ape.configuration.APECoreConfig;
import nl.uu.cs.ape.configuration.APERunConfig;
import nl.uu.cs.ape.constraints.ConstraintTemplate;
import nl.uu.cs.ape.domain.APEDomainSetup;
import nl.uu.cs.ape.models.logic.constructs.TaxonomyPredicate;
import nl.uu.cs.ape.solver.domainconfiguration.Domain;
import nl.uu.cs.ape.solver.solutionStructure.SolutionsList;

/**
Expand Down Expand Up @@ -45,7 +45,7 @@ public interface APEInterface {
* @return The object that contains all crucial information about the domain
* (e.g. list of tools, data types, constraint factory, etc.)
*/
public APEDomainSetup getDomainSetup();
public Domain getDomainSetup();

/**
* Returns all the taxonomy elements that are subclasses of the given element.
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/nl/uu/cs/ape/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ public class Main {
* The entry point of application when the library is used in a Command Line
* Interface (CLI).
*
* @param args APE expects at most one (1) argument: The absolute or relative
* path to the configuration file.
* @param args APE expects at most two (2) arguments: <br/>
* <br/>
* (1) the absolute or relative path to the configuration file.<br/>
* <br/>
* (2) the maximum number of solutions to be returned.
*
* Note: If no arguments are provided, the default configuration
* file on location ./config.json is used.
*
*/
public static void main(String[] args) {
String path;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nl/uu/cs/ape/automaton/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Block {
* States that comprise this block. Number of stater correspond to the max
* number of inputs or outputs.
*/
private List<State> typeStates;
private final List<State> typeStates;

/**
* Order number of the block in the solution.
Expand All @@ -27,7 +27,7 @@ public class Block {
* @param blockNumber The block number.
*/
public Block(int blockNumber) {
typeStates = new ArrayList<State>();
typeStates = new ArrayList<>();
this.blockNumber = blockNumber;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/nl/uu/cs/ape/automaton/ModuleAutomaton.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class ModuleAutomaton implements Automaton {

private List<State> moduleStates;
private final List<State> moduleStates = new ArrayList<>();

/**
* Generate the Module State automatons based on the defined length.
Expand All @@ -31,7 +31,6 @@ public class ModuleAutomaton implements Automaton {
* modules).
*/
public ModuleAutomaton(int automataBound, int inputBranching, int outputBranching) {
moduleStates = new ArrayList<State>();
automataBound = Math.max(automataBound, 1);

for (int i = 1; i <= automataBound; i++) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/nl/uu/cs/ape/automaton/State.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nl.uu.cs.ape.automaton;

import nl.uu.cs.ape.models.enums.AtomType;
import nl.uu.cs.ape.models.logic.constructs.PredicateLabel;
import nl.uu.cs.ape.models.logic.constructs.Predicate;

/***
* The {@code State} class is used to represent the states in module and type
Expand All @@ -15,7 +15,7 @@
*
* @author Vedran Kasalica
*/
public class State implements PredicateLabel, StateInterface {
public class State implements Predicate, StateInterface {

/** Unique name of the state */
private final String stateName;
Expand Down Expand Up @@ -98,7 +98,7 @@ public boolean equals(Object obj) {
* before than, equal to, or after than the specified State.
*/
@Override
public int compareTo(PredicateLabel other) {
public int compareTo(Predicate other) {
if (!(other instanceof State)) {
return this.getPredicateID().compareTo(other.getPredicateID());
}
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/nl/uu/cs/ape/automaton/TypeAutomaton.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public class TypeAutomaton implements Automaton {
* Blocks of data types that are being added to the memory (usually outputs from
* the tools, apart from the initial workflow input).
*/
private List<Block> memoryTypesAutomaton;
private final List<Block> memoryTypesAutomaton = new ArrayList<>();

/**
* Blocks of data types that are being used by tools from the memory (inputs to
* the tools).
*/
private List<Block> usedTypesAutomaton;
private final List<Block> usedTypesAutomaton = new ArrayList<>();

/**
* State is used in order to represent no state.
Expand All @@ -54,8 +54,6 @@ public class TypeAutomaton implements Automaton {
* modules)
*/
public TypeAutomaton(int automataBound, int inputBranching, int outputBranching) {
memoryTypesAutomaton = new ArrayList<Block>();
usedTypesAutomaton = new ArrayList<Block>();
nullState = new State(null, null, -1, inputBranching, outputBranching);

automataBound = automataBound < 1 ? 1 : automataBound;
Expand Down Expand Up @@ -224,7 +222,7 @@ public Block getMemoryTypesBlock(int i) {
* @return List of memory States.
*/
public List<State> getMemoryStatesUntilBlockNo(int maxBlockNo) {
List<State> untilStates = new ArrayList<State>();
List<State> untilStates = new ArrayList<>();
for (int i = 0; i <= maxBlockNo && i < this.usedTypesAutomaton.size(); i++) {
Block currBlock = this.getMemoryTypesBlock(i);
for (State currState : currBlock.getStates()) {
Expand All @@ -244,7 +242,7 @@ public List<State> getMemoryStatesUntilBlockNo(int maxBlockNo) {
* @return List of Type States.
*/
public List<State> getAllStatesUntilBlockNo(int maxBlockNo) {
List<State> untilStates = new ArrayList<State>();
List<State> untilStates = new ArrayList<>();
for (int i = 0; i <= maxBlockNo && i < this.usedTypesAutomaton.size(); i++) {
Block currBlock = this.usedTypesAutomaton.get(i);
for (State currState : currBlock.getStates()) {
Expand All @@ -268,7 +266,7 @@ public List<State> getAllStatesUntilBlockNo(int maxBlockNo) {
* @return List of Memory Type States.
*/
public List<State> getAllMemoryStatesUntilBlockNo(int maxBlockNo) {
List<State> untilStates = new ArrayList<State>();
List<State> untilStates = new ArrayList<>();
for (int i = 0; i <= maxBlockNo && i < this.usedTypesAutomaton.size(); i++) {
Block currBlock = this.memoryTypesAutomaton.get(i);
for (State currState : currBlock.getStates()) {
Expand All @@ -287,7 +285,7 @@ public List<State> getAllMemoryStatesUntilBlockNo(int maxBlockNo) {
* @return List of memory States.
*/
public List<State> getMemoryStatesAfterBlockNo(int minBlockNo) {
List<State> afterStates = new ArrayList<State>();
List<State> afterStates = new ArrayList<>();
for (int i = minBlockNo + 1; i < this.memoryTypesAutomaton.size(); i++) {
Block currBlock = this.getMemoryTypesBlock(i);
for (State currState : currBlock.getStates()) {
Expand All @@ -307,7 +305,7 @@ public List<State> getMemoryStatesAfterBlockNo(int minBlockNo) {
* @return List of Used States.
*/
public List<State> getUsedStatesAfterBlockNo(int minBlockNo) {
List<State> afterStates = new ArrayList<State>();
List<State> afterStates = new ArrayList<>();
for (int i = minBlockNo + 1; i < this.usedTypesAutomaton.size(); i++) {
Block currBlock = this.usedTypesAutomaton.get(i);
for (State currState : currBlock.getStates()) {
Expand All @@ -324,7 +322,7 @@ public List<State> getUsedStatesAfterBlockNo(int minBlockNo) {
*/
@Override
public List<State> getAllStates() {
List<State> allStates = new ArrayList<State>();
List<State> allStates = new ArrayList<>();
for (Block currBlock : getAllBlocks()) {
for (State currState : currBlock.getStates()) {
allStates.add(currState);
Expand All @@ -339,7 +337,7 @@ public List<State> getAllStates() {
* @return List of memory type states.
*/
public List<State> getAllMemoryTypesStates() {
List<State> allMemoryStates = new ArrayList<State>();
List<State> allMemoryStates = new ArrayList<>();
for (Block currBlock : getMemoryTypesBlocks()) {
for (State currState : currBlock.getStates()) {
allMemoryStates.add(currState);
Expand All @@ -354,7 +352,7 @@ public List<State> getAllMemoryTypesStates() {
* @return List of used type states.
*/
public List<State> getAllUsedTypesStates() {
List<State> allUsedStates = new ArrayList<State>();
List<State> allUsedStates = new ArrayList<>();
for (Block currBlock : getUsedTypesBlocks()) {
for (State currState : currBlock.getStates()) {
allUsedStates.add(currState);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nl/uu/cs/ape/configuration/APECoreConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import nl.uu.cs.ape.configuration.tags.APEConfigTags;
import nl.uu.cs.ape.configuration.tags.APEConfigTagFactory.TAGS.*;
import nl.uu.cs.ape.configuration.tags.validation.ValidationResults;
import nl.uu.cs.ape.domain.APEDimensionsException;
import nl.uu.cs.ape.solver.domainconfiguration.APEDimensionsException;
import nl.uu.cs.ape.utils.APEFiles;
import nl.uu.cs.ape.utils.APEUtils;
import nl.uu.cs.ape.domain.OWLReader;
import nl.uu.cs.ape.utils.OWLReader;

import java.io.File;
import java.io.IOException;
Expand Down
41 changes: 11 additions & 30 deletions src/main/java/nl/uu/cs/ape/configuration/APERunConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import nl.uu.cs.ape.configuration.tags.APEConfigTags;
import nl.uu.cs.ape.configuration.tags.APEConfigTagFactory.TAGS.*;
import nl.uu.cs.ape.configuration.tags.validation.ValidationResults;
import nl.uu.cs.ape.domain.APEDomainSetup;
import nl.uu.cs.ape.models.Range;
import nl.uu.cs.ape.models.Type;
import nl.uu.cs.ape.models.enums.ConfigEnum;
import nl.uu.cs.ape.models.enums.SolverType;
import nl.uu.cs.ape.solver.domainconfiguration.Domain;

import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -99,12 +99,12 @@ public class APERunConfig {
/**
* Input types of the workflow.
*/
private final APEConfigDependentTag.One<List<Type>, APEDomainSetup> PROGRAM_INPUTS = new APEConfigTagFactory.TAGS.PROGRAM_INPUTS(
private final APEConfigDependentTag.One<List<Type>, Domain> PROGRAM_INPUTS = new APEConfigTagFactory.TAGS.PROGRAM_INPUTS(
this::getApeDomainSetup);
/**
* Output types of the workflow.
*/
private final APEConfigDependentTag.One<List<Type>, APEDomainSetup> PROGRAM_OUTPUTS = new APEConfigTagFactory.TAGS.PROGRAM_OUTPUTS(
private final APEConfigDependentTag.One<List<Type>, Domain> PROGRAM_OUTPUTS = new APEConfigTagFactory.TAGS.PROGRAM_OUTPUTS(
this::getApeDomainSetup);
/**
* All the Tags specified in this class. Should be in correct order of
Expand Down Expand Up @@ -153,10 +153,7 @@ public class APERunConfig {
* Object containing domain information needed for the execution.
*/
@Getter
private APEDomainSetup apeDomainSetup;

/** Solver type that should be used (SAT). */
private SolverType solverType = SolverType.SAT;
private Domain apeDomainSetup;

/**
* Constructor used to implement the Builder Pattern.
Expand Down Expand Up @@ -189,10 +186,10 @@ private APERunConfig(Builder builder) {

/**
* Private constructor used by
* {@link APERunConfig#validate(JSONObject config, APEDomainSetup setup)}
* {@link APERunConfig#validate(JSONObject config, Domain setup)}
* to create an empty instance.
*/
private APERunConfig(APEDomainSetup setup) {
private APERunConfig(Domain setup) {
this.apeDomainSetup = setup;
}

Expand All @@ -206,7 +203,7 @@ private APERunConfig(APEDomainSetup setup) {
* @param setup the domain setup
* @return the validation results
*/
public static ValidationResults validate(JSONObject json, APEDomainSetup setup) {
public static ValidationResults validate(JSONObject json, Domain setup) {
APERunConfig dummy = new APERunConfig(setup);
ValidationResults results = new ValidationResults();
for (APEConfigTag<?> tag : dummy.all_tags) {
Expand All @@ -229,7 +226,7 @@ public static ValidationResults validate(JSONObject json, APEDomainSetup setup)
* @throws JSONException Error in parsing the configuration file.
* @throws APEConfigException Error in setting up the the configuration.
*/
public APERunConfig(JSONObject runConfiguration, APEDomainSetup apeDomainSetup)
public APERunConfig(JSONObject runConfiguration, Domain apeDomainSetup)
throws IOException, JSONException, APEConfigException {

/* JSONObject must have been parsed correctly. */
Expand Down Expand Up @@ -577,22 +574,6 @@ public void setSolutionLength(int solutionMinLength, int solutionMaxLength) {
this.SOLUTION_LENGTH_RANGE.setValue(Range.of(solutionMinLength, solutionMaxLength));
}

/**
* Gets the Solver type that should be used for solving.
*
* @return {@link SolverType} that corresponds to the solver type
*/
public SolverType getSolverType() {
return this.solverType;
}

/**
* @param solverType the solverType to set
*/
public void setSolverType(SolverType solverType) {
this.solverType = solverType;
}

/**
* Creates interface for the min length of {@link APERunConfig}.
*/
Expand Down Expand Up @@ -624,7 +605,7 @@ public interface IMaxNoSolutionsStage {
* Creates interface to setup the domain of {@link APERunConfig}.
*/
public interface IApeDomainSetupStage {
IBuildStage withApeDomainSetup(APEDomainSetup apeDomainSetup);
IBuildStage withApeDomainSetup(Domain apeDomainSetup);
}

/**
Expand Down Expand Up @@ -671,7 +652,7 @@ public static final class Builder implements ISolutionMinLengthStage, ISolutionM
private int solutionMinLength;
private int solutionMaxLength;
private int maxNoSolutions;
private APEDomainSetup apeDomainSetup;
private Domain apeDomainSetup;
private JSONArray constraintsJSON;
private boolean toolSeqRepeat;
private String solutionDirPath;
Expand Down Expand Up @@ -708,7 +689,7 @@ public IApeDomainSetupStage withMaxNoSolutions(int maxNoSolutions) {
}

@Override
public IBuildStage withApeDomainSetup(APEDomainSetup apeDomainSetup) {
public IBuildStage withApeDomainSetup(Domain apeDomainSetup) {
this.apeDomainSetup = apeDomainSetup;
return this;
}
Expand Down
Loading
Loading