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

Phase saving, restarts, and heuristic performance logs #202

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8b69a7a
Add phase saving.
AntoniusW Sep 29, 2019
2904653
Adding restarts (default disabled).
AntoniusW Oct 5, 2019
af19a14
Enhance performance logs to show quality of heuristic decisions.
AntoniusW Oct 7, 2019
c3ac978
Add options for initial phase settings; add atom dependency to VSIDS
AntoniusW Oct 23, 2019
78b7e89
Add HeapOfRelatedChoiceAtoms recording only choice points, improve logs.
AntoniusW Nov 7, 2019
6143e82
Fix bug in AlphaHeadMustBeTrueHeuristic.
AntoniusW Nov 12, 2019
cd6ea23
Fix Luby restart sequence computation.
AntoniusW Nov 12, 2019
e83c866
Make AtomChoiceRelation a mandatory Grounder component.
AntoniusW Nov 12, 2019
ab122e3
Merge branch 'master' into phase_saving_and_restarts_merge_master
rtaupe Feb 12, 2020
a6ccf70
Fix merge ab122e3c340b1823a92b7af38e379e1e2881a441
rtaupe Feb 12, 2020
a7e66ce
Merge pull request #222 from alpha-asp/phase_saving_and_restarts_merg…
AntoniusW Feb 15, 2020
0fbb0e9
Merge branch 'master' into phase_saving_and_restarts_merge_master
rtaupe Feb 19, 2020
f922794
Merge pull request #224 from alpha-asp/phase_saving_and_restarts_merg…
AntoniusW Feb 21, 2020
689dd00
Merge branch 'master' into phase_saving_and_restarts
rtaupe Apr 24, 2020
c944b7e
Better toString in ChoiceRecorder.
AntoniusW May 1, 2020
3770706
Fix checkstyle.
AntoniusW May 2, 2020
f30057a
Add initial phase setting rules true, rest false.
AntoniusW May 2, 2020
0650096
Address review comments and use array in AtomChoiceRelation.
AntoniusW May 3, 2020
d0229b4
Remove unnecessary parameter of TrailAssignment.
AntoniusW May 4, 2020
7d992c2
Fix NullPointerException in AtomChoiceRelation.
AntoniusW May 4, 2020
48051e6
Make AtomChoiceRelation reflexive on choice atoms.
AntoniusW May 5, 2020
0589715
Clean-up logic in HeapOfActiveAtoms.
AntoniusW May 6, 2020
d9180c4
Use default PhaseInitializer in TrailAssignment.
AntoniusW May 6, 2020
4b8566a
Small polish.
AntoniusW May 7, 2020
e63651a
Use enum instead of string for default initial phase
rtaupe May 7, 2020
2e26f69
Test parsing of -ph CLI parameter
rtaupe May 7, 2020
340ae36
Small polish.
AntoniusW May 7, 2020
fdca492
Merge pull request #253 from alpha-asp/phase_saving_and_restarts_fix_…
AntoniusW May 7, 2020
4bb2cf8
Merge upstream branch phase_saving_and_restarts into local.
AntoniusW May 7, 2020
7855224
Merge branch 'master' into phase_saving_and_restarts
rtaupe May 26, 2020
e968afa
Improve cmdline description of initial_phase flag.
AntoniusW Sep 20, 2021
5d52555
Merge branch 'master' into phase_saving_and_restarts
AntoniusW Sep 21, 2021
7257348
Fix merge conflicts.
AntoniusW Sep 21, 2021
a0f87e9
Merge branch 'phase_saving_and_restarts' of github:AntoniusW/Alpha in…
AntoniusW Sep 21, 2021
2fcf5d7
Merge branch 'master' into phase_saving_and_restarts
AntoniusW Oct 4, 2021
af8a944
Refactor VSIDS implementations, extract common fields and methods.
AntoniusW Oct 6, 2021
419b819
Fix copyright statement as per review request.
AntoniusW Oct 6, 2021
8adbd2a
Merge branch 'master' into phase_saving_and_restarts
AntoniusW Dec 4, 2021
fcd2436
Modularize phase saving and fix merge.
AntoniusW Dec 5, 2021
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
19 changes: 9 additions & 10 deletions src/main/java/at/ac/tuwien/kr/alpha/AnswerSetToXlsxWriter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package at.ac.tuwien.kr.alpha;

import at.ac.tuwien.kr.alpha.api.mapper.AnswerSetToObjectMapper;
rtaupe marked this conversation as resolved.
Show resolved Hide resolved
import at.ac.tuwien.kr.alpha.api.mapper.impl.AnswerSetToWorkbookMapper;
import at.ac.tuwien.kr.alpha.common.AnswerSet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
Expand All @@ -8,16 +17,6 @@
import java.nio.file.StandardOpenOption;
import java.util.function.BiConsumer;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import at.ac.tuwien.kr.alpha.api.mapper.AnswerSetToObjectMapper;
import at.ac.tuwien.kr.alpha.api.mapper.impl.AnswerSetToWorkbookMapper;
import at.ac.tuwien.kr.alpha.common.AnswerSet;

public class AnswerSetToXlsxWriter implements BiConsumer<Integer, AnswerSet> {

private String targetBasePath;
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/at/ac/tuwien/kr/alpha/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@
*/
package at.ac.tuwien.kr.alpha;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.antlr.v4.runtime.RecognitionException;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.ac.tuwien.kr.alpha.api.Alpha;
import at.ac.tuwien.kr.alpha.common.AnswerSet;
import at.ac.tuwien.kr.alpha.common.Program;
Expand All @@ -48,6 +35,18 @@
import at.ac.tuwien.kr.alpha.config.InputConfig;
import at.ac.tuwien.kr.alpha.solver.Solver;
import at.ac.tuwien.kr.alpha.solver.SolverMaintainingStatistics;
import org.antlr.v4.runtime.RecognitionException;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Main entry point for Alpha.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
*/
package at.ac.tuwien.kr.alpha.api.mapper.impl;

import java.util.List;

import at.ac.tuwien.kr.alpha.api.mapper.AnswerSetToObjectMapper;
import at.ac.tuwien.kr.alpha.common.AnswerSet;
import at.ac.tuwien.kr.alpha.common.Predicate;
import at.ac.tuwien.kr.alpha.common.atoms.Atom;
import at.ac.tuwien.kr.alpha.common.terms.Term;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
Expand All @@ -39,11 +42,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.ac.tuwien.kr.alpha.api.mapper.AnswerSetToObjectMapper;
import at.ac.tuwien.kr.alpha.common.AnswerSet;
import at.ac.tuwien.kr.alpha.common.Predicate;
import at.ac.tuwien.kr.alpha.common.atoms.Atom;
import at.ac.tuwien.kr.alpha.common.terms.Term;
import java.util.List;

/**
* Implementation of {@link AnswerSetToObjectMapper} that generates an office open xml workbook ("excel file") from a given answer set.
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/at/ac/tuwien/kr/alpha/common/Assignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ default ThriceTruth getTruth(int atom) {
*/
Antecedent getImpliedBy(int atom);

/**
* Returns the last truth value (i.e., phase) assigned to the atom.
* @param atom the atom
* @return the last truth value.
*/
boolean getLastValue(int atom);

/**
* Determines if the given {@code noGood} is undefined in the current assignment.
*
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/at/ac/tuwien/kr/alpha/common/NoGood.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@
import java.util.stream.IntStream;

import static at.ac.tuwien.kr.alpha.Util.oops;
import static at.ac.tuwien.kr.alpha.common.Literals.*;
import static at.ac.tuwien.kr.alpha.common.NoGoodInterface.Type.*;
import static at.ac.tuwien.kr.alpha.common.Literals.atomOf;
import static at.ac.tuwien.kr.alpha.common.Literals.isNegated;
import static at.ac.tuwien.kr.alpha.common.Literals.isPositive;
import static at.ac.tuwien.kr.alpha.common.Literals.negateLiteral;
import static at.ac.tuwien.kr.alpha.common.Literals.positiveLiteral;
import static at.ac.tuwien.kr.alpha.common.NoGoodInterface.Type.INTERNAL;
import static at.ac.tuwien.kr.alpha.common.NoGoodInterface.Type.LEARNT;
import static at.ac.tuwien.kr.alpha.common.NoGoodInterface.Type.STATIC;
import static at.ac.tuwien.kr.alpha.common.NoGoodInterface.Type.SUPPORT;

public class NoGood implements NoGoodInterface, Comparable<NoGood> {
public static final int HEAD = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
import at.ac.tuwien.kr.alpha.common.terms.VariableTerm;
import at.ac.tuwien.kr.alpha.grounder.Substitution;

import java.util.*;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import static at.ac.tuwien.kr.alpha.common.terms.ArithmeticTerm.evaluateGroundTerm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class CommandLineParser {
.desc("use counting grid normalization instead of sorting circuit for #count (default: " + SystemConfig.DEFAULT_USE_NORMALIZATION_GRID + ")")
.build();
private static final Option OPT_NO_NOGOOD_DELETION = Option.builder("dnd").longOpt("disableNoGoodDeletion")
.desc("disable the deletion of (learned, little active) nogoods (default: "
.desc("disable the deletion of (learned, little active) nogoods (default: "
+ SystemConfig.DEFAULT_DISABLE_NOGOOD_DELETION + ")")
.build();
private static final Option OPT_GROUNDER_TOLERANCE_CONSTRAINTS = Option.builder("gtc").longOpt("grounderToleranceConstraints")
Expand All @@ -127,6 +127,13 @@ public class CommandLineParser {
.desc("activates the accumulator grounding strategy by disabling removal of instances from grounder memory in certain cases (default: "
+ SystemConfig.DEFAULT_GROUNDER_ACCUMULATOR_ENABLED + ")")
.build();
private static final Option OPT_ENABLE_RESTARTS = Option.builder("rs").longOpt("enableRestarts")
.desc("enable the usage of (dynamic and static) restarts (default: "
+ SystemConfig.DEFAULT_ENABLE_RESTARTS + ")")
.build();
private static final Option OPT_INITIAL_PHASE = Option.builder("ph").longOpt("initialPhase").hasArg(true).argName("initializer")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this option is only meaningful if the VSIDS_PHASE_SAVING heuristic is used, a warning should be issued if it is used in conjunction with any other heuristic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point and touches on a larger issue: what we would need is to check whether the whole set of given options actually makes sense. For the time being, I'll change the description so that it becomes clear that this only works for the VSIDS_WITH_PHASE_SAVING heuristic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to issue #302 as a condition to check eventually.

.desc("set the initial phase [ alltrue | allfalse | random ] (default: " + SystemConfig.DEFAULT_PHASE_INITIALIZER + ")")
.build();
//@formatter:on

private static final Options CLI_OPTS = new Options();
Expand Down Expand Up @@ -162,6 +169,8 @@ public class CommandLineParser {
CommandLineParser.CLI_OPTS.addOption(CommandLineParser.OPT_GROUNDER_TOLERANCE_CONSTRAINTS);
CommandLineParser.CLI_OPTS.addOption(CommandLineParser.OPT_GROUNDER_TOLERANCE_RULES);
CommandLineParser.CLI_OPTS.addOption(CommandLineParser.OPT_GROUNDER_ACCUMULATOR_ENABLED);
CommandLineParser.CLI_OPTS.addOption(CommandLineParser.OPT_ENABLE_RESTARTS);
CommandLineParser.CLI_OPTS.addOption(CommandLineParser.OPT_INITIAL_PHASE);
}

/*
Expand Down Expand Up @@ -208,6 +217,8 @@ public CommandLineParser(String cmdLineSyntax, Consumer<String> abortAction) {
this.globalOptionHandlers.put(CommandLineParser.OPT_GROUNDER_TOLERANCE_CONSTRAINTS.getOpt(), this::handleGrounderToleranceConstraints);
this.globalOptionHandlers.put(CommandLineParser.OPT_GROUNDER_TOLERANCE_RULES.getOpt(), this::handleGrounderToleranceRules);
this.globalOptionHandlers.put(CommandLineParser.OPT_GROUNDER_ACCUMULATOR_ENABLED.getOpt(), this::handleGrounderNoInstanceRemoval);
this.globalOptionHandlers.put(CommandLineParser.OPT_ENABLE_RESTARTS.getOpt(), this::handleEnableRestarts);
this.globalOptionHandlers.put(CommandLineParser.OPT_INITIAL_PHASE.getOpt(), this::handleInitialPhase);

this.inputOptionHandlers.put(CommandLineParser.OPT_NUM_ANSWER_SETS.getOpt(), this::handleNumAnswerSets);
this.inputOptionHandlers.put(CommandLineParser.OPT_INPUT.getOpt(), this::handleInput);
Expand Down Expand Up @@ -410,4 +421,11 @@ private void handleGrounderNoInstanceRemoval(Option opt, SystemConfig cfg) {
cfg.setGrounderAccumulatorEnabled(true);
}

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));
}
}
5 changes: 3 additions & 2 deletions src/main/java/at/ac/tuwien/kr/alpha/config/InputConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package at.ac.tuwien.kr.alpha.config;

import at.ac.tuwien.kr.alpha.common.Predicate;
import at.ac.tuwien.kr.alpha.common.fixedinterpretations.PredicateInterpretation;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import at.ac.tuwien.kr.alpha.api.externals.Externals;
import at.ac.tuwien.kr.alpha.common.Predicate;
import at.ac.tuwien.kr.alpha.common.fixedinterpretations.PredicateInterpretation;

public class InputConfig {

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/at/ac/tuwien/kr/alpha/config/SystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class SystemConfig {
public static final String DEFAULT_GROUNDER_TOLERANCE_CONSTRAINTS = GrounderHeuristicsConfiguration.STRICT_STRING;
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 = "random";
rtaupe marked this conversation as resolved.
Show resolved Hide resolved

private String grounderName = SystemConfig.DEFAULT_GROUNDER_NAME;
private String solverName = SystemConfig.DEFAULT_SOLVER_NAME;
Expand All @@ -79,6 +81,8 @@ public class SystemConfig {
private String grounderToleranceConstraints = DEFAULT_GROUNDER_TOLERANCE_CONSTRAINTS;
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;

public String getGrounderName() {
return this.grounderName;
Expand Down Expand Up @@ -235,4 +239,20 @@ public boolean isGrounderAccumulatorEnabled() {
public void setGrounderAccumulatorEnabled(boolean grounderAccumulatorEnabled) {
this.grounderAccumulatorEnabled = grounderAccumulatorEnabled;
}
public boolean areRestartsEnabled() {
return areRestartsEnabled;
}

public void setRestartsEnabled(boolean areRestartsEnabled) {
this.areRestartsEnabled = areRestartsEnabled;
}

public String getPhaseInitializerName() {
return phaseInitializer;
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public String toString() {
}
sb.append(" disablers: ");
for (Map.Entry<Integer, Integer> disablers : newChoiceAtoms.getRight().entrySet()) {
sb.append(disablers.getKey()).append("/").append(disablers.getValue());
sb.append(disablers.getKey()).append("/").append(disablers.getValue()).append(", ");
rtaupe marked this conversation as resolved.
Show resolved Hide resolved
}
return sb.append("]").toString();
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/at/ac/tuwien/kr/alpha/grounder/Grounder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import at.ac.tuwien.kr.alpha.common.IntIterator;
import at.ac.tuwien.kr.alpha.common.NoGood;
import at.ac.tuwien.kr.alpha.grounder.atoms.RuleAtom;
import at.ac.tuwien.kr.alpha.grounder.structure.AtomChoiceRelation;
import org.apache.commons.lang3.tuple.Pair;

import java.util.Map;
Expand Down Expand Up @@ -79,4 +80,11 @@ public interface Grounder {
* @return
*/
int register(NoGood noGood);


/**
* Returns the relation between atoms and choices in form of an {@link AtomChoiceRelation} object.
* @return the {@link AtomChoiceRelation} of the grounded program parts.
*/
AtomChoiceRelation getAtomChoiceRelation();
}
10 changes: 8 additions & 2 deletions src/main/java/at/ac/tuwien/kr/alpha/grounder/NaiveGrounder.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import at.ac.tuwien.kr.alpha.grounder.bridges.Bridge;
import at.ac.tuwien.kr.alpha.grounder.heuristics.GrounderHeuristicsConfiguration;
import at.ac.tuwien.kr.alpha.grounder.structure.AnalyzeUnjustified;
import at.ac.tuwien.kr.alpha.grounder.structure.AtomChoiceRelation;
import at.ac.tuwien.kr.alpha.grounder.structure.ProgramAnalysis;
import at.ac.tuwien.kr.alpha.grounder.transformation.CardinalityNormalization;
import at.ac.tuwien.kr.alpha.grounder.transformation.ChoiceHeadToNormal;
Expand Down Expand Up @@ -103,6 +104,7 @@ public class NaiveGrounder extends BridgedGrounder implements ProgramAnalyzingGr
private final Map<IndexedInstanceStorage, ArrayList<FirstBindingAtom>> rulesUsingPredicateWorkingMemory = new HashMap<>();
private final Map<NonGroundRule, HashSet<Substitution>> knownGroundingSubstitutions = new HashMap<>();
private final Map<Integer, NonGroundRule> knownNonGroundRules = new HashMap<>();
private final AtomChoiceRelation atomChoiceRelation = new AtomChoiceRelation();

private ArrayList<NonGroundRule> fixedRules = new ArrayList<>();
private LinkedHashSet<Atom> removeAfterObtainingNewNoGoods = new LinkedHashSet<>();
Expand Down Expand Up @@ -137,11 +139,15 @@ private NaiveGrounder(Program program, AtomStore atomStore, GrounderHeuristicsCo

final Set<NonGroundRule> uniqueGroundRulePerGroundHead = getRulesWithUniqueHead();
choiceRecorder = new ChoiceRecorder(atomStore);
noGoodGenerator = new NoGoodGenerator(atomStore, choiceRecorder, factsFromProgram, programAnalysis, uniqueGroundRulePerGroundHead);

noGoodGenerator = new NoGoodGenerator(atomStore, choiceRecorder, factsFromProgram, programAnalysis, uniqueGroundRulePerGroundHead, atomChoiceRelation);
this.debugInternalChecks = debugInternalChecks;
}

@Override
public AtomChoiceRelation getAtomChoiceRelation() {
return atomChoiceRelation;
}

private void initializeFactsAndRules(Program program) {
// initialize all facts
for (Atom fact : program.getFacts()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import at.ac.tuwien.kr.alpha.common.atoms.FixedInterpretationLiteral;
import at.ac.tuwien.kr.alpha.grounder.atoms.EnumerationAtom;
import at.ac.tuwien.kr.alpha.grounder.atoms.RuleAtom;
import at.ac.tuwien.kr.alpha.grounder.structure.AtomChoiceRelation;
import at.ac.tuwien.kr.alpha.grounder.structure.ProgramAnalysis;

import java.util.*;
Expand All @@ -52,13 +53,15 @@ public class NoGoodGenerator {
private final Map<Predicate, LinkedHashSet<Instance>> factsFromProgram;
private final ProgramAnalysis programAnalysis;
private final Set<NonGroundRule> uniqueGroundRulePerGroundHead;
private final AtomChoiceRelation atomChoiceRelation;

NoGoodGenerator(AtomStore atomStore, ChoiceRecorder recorder, Map<Predicate, LinkedHashSet<Instance>> factsFromProgram, ProgramAnalysis programAnalysis, Set<NonGroundRule> uniqueGroundRulePerGroundHead) {
NoGoodGenerator(AtomStore atomStore, ChoiceRecorder recorder, Map<Predicate, LinkedHashSet<Instance>> factsFromProgram, ProgramAnalysis programAnalysis, Set<NonGroundRule> uniqueGroundRulePerGroundHead, AtomChoiceRelation atomChoiceRelation) {
this.atomStore = atomStore;
this.choiceRecorder = recorder;
this.factsFromProgram = factsFromProgram;
this.programAnalysis = programAnalysis;
this.uniqueGroundRulePerGroundHead = uniqueGroundRulePerGroundHead;
this.atomChoiceRelation = atomChoiceRelation;
}

/**
Expand Down Expand Up @@ -126,6 +129,15 @@ List<NoGood> generateNoGoodsFromGroundSubstitution(final NonGroundRule nonGround
result.addAll(choiceRecorder.generateChoiceNoGoods(posLiterals, negLiterals, bodyRepresentingLiteral));
}

// Record atom-choiceAtom relationships for rules that are choice points.
if (!negLiterals.isEmpty()) {
rtaupe marked this conversation as resolved.
Show resolved Hide resolved
atomChoiceRelation.growForMaxAtomId(atomStore.getMaxAtomId());
atomChoiceRelation.addRelation(headId, atomOf(bodyRepresentingLiteral));
for (Integer negLiteral : negLiterals) {
atomChoiceRelation.addRelation(atomOf(negLiteral), atomOf(bodyRepresentingLiteral));
}
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import at.ac.tuwien.kr.alpha.common.Assignment;
import at.ac.tuwien.kr.alpha.common.atoms.Atom;
import at.ac.tuwien.kr.alpha.common.atoms.Literal;
import at.ac.tuwien.kr.alpha.grounder.structure.AtomChoiceRelation;

import java.util.Set;

Expand Down Expand Up @@ -32,4 +33,10 @@ public interface ProgramAnalyzingGrounder extends Grounder {
* @return the corresponding NonGroundRule.
*/
NonGroundRule getNonGroundRule(Integer ruleId);

/**
* Provides relationship information between atoms and choice points influencing their truth values.
* @return the {@link AtomChoiceRelation}.
*/
AtomChoiceRelation getAtomChoiceRelation();
rtaupe marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@
import at.ac.tuwien.kr.alpha.common.atoms.Literal;
import at.ac.tuwien.kr.alpha.common.terms.VariableTerm;

import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
* Provides the grounder with information on the order to ground the literals in the body of a rule.
Expand Down
Loading