use of at.ac.tuwien.kr.alpha.core.atoms.EnumerationLiteral in project Alpha by alpha-asp.
the class LiteralInstantiatorTest method instantiateEnumLiteral.
@Test
public void instantiateEnumLiteral() {
VariableTerm enumTerm = Terms.newVariable("E");
VariableTerm idTerm = Terms.newVariable("X");
VariableTerm indexTerm = Terms.newVariable("I");
EnumerationAtom enumAtom = new EnumerationAtom(enumTerm, idTerm, indexTerm);
EnumerationLiteral lit = new EnumerationLiteral(enumAtom);
Substitution substitution = new BasicSubstitution();
substitution.put(enumTerm, Terms.newSymbolicConstant("enum1"));
substitution.put(idTerm, Terms.newSymbolicConstant("someElement"));
LiteralInstantiator instantiator = new LiteralInstantiator(new WorkingMemoryBasedInstantiationStrategy(null));
LiteralInstantiationResult result = instantiator.instantiateLiteral(lit, substitution);
assertEquals(LiteralInstantiationResult.Type.CONTINUE, result.getType());
List<ImmutablePair<Substitution, AssignmentStatus>> resultSubstitutions = result.getSubstitutions();
assertEquals(1, resultSubstitutions.size());
assertEquals(AssignmentStatus.TRUE, resultSubstitutions.get(0).right);
assertTrue(resultSubstitutions.get(0).left.isVariableSet(indexTerm));
}
use of at.ac.tuwien.kr.alpha.core.atoms.EnumerationLiteral in project Alpha by alpha-asp.
the class LiteralInstantiator method instantiateBasicLiteral.
/**
* Calculates substitutions for a given literal that is not a {@link FixedInterpretationLiteral} or {@link EnumerationLiteral}.
* If applying the given partial substitution to the literal already grounds the literal, the resulting ground literal is verified based on
* this instantiators {@link LiteralInstantiationStrategy}. If the literal is only partially ground after applying the partial substitution,
* ground substitutions are looked up using the instantiators {@link LiteralInstantiationStrategy}. This method assumes that the partial
* substitution has <emph>not</emph> been applied to the passed literal.
*
* @param lit
* @param partialSubstitution
*/
private LiteralInstantiationResult instantiateBasicLiteral(Literal lit, Substitution partialSubstitution) {
LOGGER.trace("Instantiating basic literal: {}", lit);
List<ImmutablePair<Substitution, AssignmentStatus>> substitutions;
Literal substitutedLiteral = lit.substitute(partialSubstitution);
LOGGER.trace("Substituted literal is {}", substitutedLiteral);
if (substitutedLiteral.isGround()) {
LOGGER.trace("Literal {} is already ground, checking truth", substitutedLiteral);
// Lit seems to be a basic literal, so its satisfiability w.r.t.
// partialSubstitution is decided based on knownInstances by the
// instantiationStrategy.
AssignmentStatus truthForLiteral = this.instantiationStrategy.getTruthForGroundLiteral(substitutedLiteral);
if (truthForLiteral == AssignmentStatus.FALSE) {
return LiteralInstantiationResult.stopBinding();
} else {
return LiteralInstantiationResult.continueBinding(partialSubstitution, truthForLiteral);
}
} else {
LOGGER.trace("Handling non-ground literal {}", substitutedLiteral);
if (substitutedLiteral.isNegated()) {
return LiteralInstantiationResult.maybePushBack();
}
// Query instantiationStrategy for acceptable substitutions.
// Note: getAcceptedSubstitutions will only give substitutions where the
// resulting ground atom is true or unassigned, false atoms are internally
// discarded.
substitutions = this.instantiationStrategy.getAcceptedSubstitutions(substitutedLiteral, partialSubstitution);
LOGGER.trace("Got {} substitutions from instantiation strategy for {}", substitutions.size(), substitutedLiteral);
return substitutions.isEmpty() ? LiteralInstantiationResult.maybePushBack() : LiteralInstantiationResult.continueBinding(substitutions);
}
}
Aggregations