Skip to content

Commit

Permalink
Use enum instead of string for default initial phase
Browse files Browse the repository at this point in the history
  • Loading branch information
rtaupe committed May 7, 2020
1 parent 4b8566a commit e63651a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2016-2020, the Alpha Team.
* All rights reserved.
*
Expand Down Expand Up @@ -426,7 +426,13 @@ private void handleEnableRestarts(Option opt, SystemConfig cfg) {
cfg.setRestartsEnabled(true);
}

private void handleInitialPhase(Option opt, SystemConfig cfg) {
cfg.setPhaseInitializer(opt.getValue(SystemConfig.DEFAULT_PHASE_INITIALIZER));
private void handleInitialPhase(Option opt, SystemConfig cfg) throws ParseException {
String initialPhase = opt.getValue(SystemConfig.DEFAULT_PHASE_INITIALIZER.name());
try {
cfg.setPhaseInitializerName(initialPhase);
} catch (IllegalArgumentException e) {
throw new ParseException("Unknown initial phase: " + initialPhase + ". Please try one of the following: "
+ PhaseInitializerFactory.InitialPhase.listAllowedValues());
}
}
}
16 changes: 10 additions & 6 deletions src/main/java/at/ac/tuwien/kr/alpha/config/SystemConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2019, the Alpha Team.
/*
* Copyright (c) 2019-2020, the Alpha Team.
* All rights reserved.
*
* Additional changes made by Siemens.
Expand Down Expand Up @@ -62,7 +62,7 @@ public class SystemConfig {
public static final String DEFAULT_GROUNDER_TOLERANCE_RULES = GrounderHeuristicsConfiguration.STRICT_STRING;
public static final boolean DEFAULT_GROUNDER_ACCUMULATOR_ENABLED = false;
public static final boolean DEFAULT_ENABLE_RESTARTS = false;
public static final String DEFAULT_PHASE_INITIALIZER = PhaseInitializerFactory.InitialPhase.RULESTRUEATOMSFALSE.name().toLowerCase();
public static final PhaseInitializerFactory.InitialPhase DEFAULT_PHASE_INITIALIZER = PhaseInitializerFactory.InitialPhase.RULESTRUEATOMSFALSE;

private String grounderName = SystemConfig.DEFAULT_GROUNDER_NAME;
private String solverName = SystemConfig.DEFAULT_SOLVER_NAME;
Expand All @@ -83,7 +83,7 @@ public class SystemConfig {
private String grounderToleranceRules = DEFAULT_GROUNDER_TOLERANCE_RULES;
private boolean grounderAccumulatorEnabled = DEFAULT_GROUNDER_ACCUMULATOR_ENABLED;
private boolean areRestartsEnabled = SystemConfig.DEFAULT_ENABLE_RESTARTS;
private String phaseInitializer = SystemConfig.DEFAULT_PHASE_INITIALIZER;
private PhaseInitializerFactory.InitialPhase phaseInitializer = SystemConfig.DEFAULT_PHASE_INITIALIZER;

public String getGrounderName() {
return this.grounderName;
Expand Down Expand Up @@ -248,12 +248,16 @@ public void setRestartsEnabled(boolean areRestartsEnabled) {
this.areRestartsEnabled = areRestartsEnabled;
}

public String getPhaseInitializerName() {
public PhaseInitializerFactory.InitialPhase getPhaseInitializer() {
return phaseInitializer;
}

public void setPhaseInitializer(String phaseInitializer) {
public void setPhaseInitializer(PhaseInitializerFactory.InitialPhase phaseInitializer) {
this.phaseInitializer = phaseInitializer;
}

public void setPhaseInitializerName(String phaseInitializerName) {
this.phaseInitializer = PhaseInitializerFactory.InitialPhase.valueOf(phaseInitializerName.toUpperCase());
}

}
6 changes: 3 additions & 3 deletions src/main/java/at/ac/tuwien/kr/alpha/solver/SolverFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2016-2017, the Alpha Team.
/*
* Copyright (c) 2016-2020, the Alpha Team.
* All rights reserved.
*
* Additional changes made by Siemens.
Expand Down Expand Up @@ -44,7 +44,7 @@ public static Solver getInstance(SystemConfig config, AtomStore atomStore, Groun
final boolean debugInternalChecks = config.isDebugInternalChecks();
final HeuristicsConfiguration heuristicsConfiguration = buildHeuristicsConfiguration(config);
final PhaseInitializerFactory.PhaseInitializer phaseInitializer =
PhaseInitializerFactory.getInstance(config.getPhaseInitializerName(), random, atomStore);
PhaseInitializerFactory.getInstance(config.getPhaseInitializer(), random, atomStore);
final WritableAssignment assignment = new TrailAssignment(atomStore, phaseInitializer, debugInternalChecks);

NoGoodStore store;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/*
* Copyright (c) 2019-2020, the Alpha Team.
* All rights reserved.
*
* Additional changes made by Siemens.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1) Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2) Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package at.ac.tuwien.kr.alpha.solver.heuristics;

import at.ac.tuwien.kr.alpha.common.AtomStore;
Expand Down Expand Up @@ -30,8 +57,7 @@ public abstract static class PhaseInitializer {
public abstract boolean getNextInitialPhase(int atom);
}

public static PhaseInitializer getInstance(String phaseInitializerName, Random random, AtomStore atomStore) {
InitialPhase initialPhase = InitialPhase.valueOf(phaseInitializerName.toUpperCase());
public static PhaseInitializer getInstance(InitialPhase initialPhase, Random random, AtomStore atomStore) {
switch (initialPhase) {
case ALLTRUE:
return getPhaseInitializerAllTrue();
Expand All @@ -42,7 +68,7 @@ public static PhaseInitializer getInstance(String phaseInitializerName, Random r
case RULESTRUEATOMSFALSE:
return getPhaseInitializerRulesTrueRestFalse(atomStore);
default:
throw new IllegalArgumentException("Unknown phase initializer requested:" + phaseInitializerName);
throw new IllegalArgumentException("Unknown phase initializer requested:" + initialPhase);
}
}

Expand Down

0 comments on commit e63651a

Please sign in to comment.