use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class SolverTests method instanceEnumerationMultipleIdentifiers.
@RegressionTest
public void instanceEnumerationMultipleIdentifiers(RegressionTestConfig cfg) {
Set<AnswerSet> answerSets = buildSolverForRegressionTest("# enumeration_predicate_is enum." + "dom(a). dom(b). dom(c). dom(d)." + "p(X) :- dom(X)." + "unique_position1(Term,Pos) :- p(Term), enum(id,Term,Pos)." + "unique_position2(Term,Pos) :- p(Term), enum(otherid,Term,Pos)." + "wrong_double_occurrence :- unique_position(T1,P), unique_position(T2,P), T1 != T2." + "wrong_double_occurrence :- unique_position2(T1,P), unique_position(T2,P), T1 != T2.", cfg).collectSet();
// Since enumeration depends on evaluation, we do not know which unique_position is actually assigned.
// Check manually that there is one answer set, wrong_double_occurrence has not been derived, and enum yielded a unique position for each term.
assertEquals(1, answerSets.size());
AnswerSet answerSet = answerSets.iterator().next();
assertPropositionalPredicateFalse(answerSet, Predicates.getPredicate("wrong_double_occurrence", 0));
SortedSet<Atom> positions = answerSet.getPredicateInstances(Predicates.getPredicate("unique_position1", 2));
assertEnumerationPositions(positions, 4);
SortedSet<Atom> positions2 = answerSet.getPredicateInstances(Predicates.getPredicate("unique_position2", 2));
assertEnumerationPositions(positions2, 4);
}
use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class SolverTests method testObjectProgram.
@RegressionTest
public void testObjectProgram(RegressionTestConfig cfg) {
final Thingy thingy = new Thingy();
final Atom fact = Atoms.newBasicAtom(Predicates.getPredicate("foo", 1), Terms.newConstant(thingy));
final InputProgram program = new InputProgram(Collections.emptyList(), Collections.singletonList(fact), new InlineDirectivesImpl());
assertEquals(singleton(new AnswerSetBuilder().predicate("foo").instance(thingy).build()), collectRegressionTestAnswerSets(program, cfg));
}
use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class SolverTests method assertEnumerationPositions.
private void assertEnumerationPositions(SortedSet<Atom> positions, int numPositions) {
assertEquals(numPositions, positions.size());
boolean[] usedPositions = new boolean[numPositions];
for (Atom position : positions) {
@SuppressWarnings("unchecked") Integer atomPos = ((ConstantTerm<Integer>) position.getTerms().get(1)).getObject() - 1;
assertTrue(atomPos < numPositions);
usedPositions[atomPos] = true;
}
for (int i = 0; i < numPositions; i++) {
assertTrue(usedPositions[i]);
}
}
use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class ThreeColouringRandomGraphTest method createEdges.
private List<Atom> createEdges(int vertices, int edges) {
Random rand = new Random(0);
List<Atom> facts = new ArrayList<>(edges);
for (int i = 0; i < edges; i++) {
int v1 = 0;
int v2 = 0;
while (v1 == v2) {
v1 = rand.nextInt(vertices);
v2 = rand.nextInt(vertices);
}
facts.add(fact("e", v1, v2));
facts.add(fact("e", v2, v1));
}
return facts;
}
use of at.ac.tuwien.kr.alpha.api.programs.atoms.Atom in project Alpha by alpha-asp.
the class ThreeColouringWheelTest method createColors.
private List<Atom> createColors(String... colours) {
List<Atom> facts = new ArrayList<>(colours.length);
Predicate predicate = Predicates.getPredicate("c", 1);
for (String colour : colours) {
List<Term> terms = new ArrayList<>(1);
terms.add(Terms.newConstant(colour));
facts.add(Atoms.newBasicAtom(predicate, terms));
}
return facts;
}
Aggregations