Search in sources :

Example 31 with AtomStoreImpl

use of at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl in project Alpha by alpha-asp.

the class NaiveGrounderTest method testIfGrounderGroundsRule.

/**
 * Tests if {@link NaiveGrounder#getGroundInstantiations(InternalRule, RuleGroundingOrder, Substitution, Assignment)}
 * produces ground instantiations for the rule with ID {@code ruleID} in {@code program} when {@code startingLiteral}
 * unified with the numeric instance {@code startingInstance} is used as starting literal and {@code b(1)} is assigned
 * {@code bTruth}.
 * It is asserted that ground instantiations are produced if and only if {@code expectNoGoods} is true.
 */
private void testIfGrounderGroundsRule(ASPCore2Program program, int ruleID, Literal startingLiteral, int startingInstance, ThriceTruth bTruth, boolean expectNoGoods) {
    CompiledProgram internalPrg = InternalProgram.fromNormalProgram(NORMALIZE_TRANSFORM.apply(program));
    AtomStore atomStore = new AtomStoreImpl();
    TrailAssignment currentAssignment = new TrailAssignment(atomStore);
    NaiveGrounder grounder = (NaiveGrounder) GrounderFactory.getInstance("naive", internalPrg, atomStore, p -> true, GrounderHeuristicsConfiguration.permissive(), true);
    int b = atomStore.putIfAbsent(atom("b", 1));
    currentAssignment.growForMaxAtomId();
    currentAssignment.assign(b, bTruth);
    grounder.bootstrap();
    final CompiledRule nonGroundRule = grounder.getNonGroundRule(ruleID);
    final Substitution substStartingLiteral = BasicSubstitution.specializeSubstitution(startingLiteral, new Instance(Terms.newConstant(startingInstance)), BasicSubstitution.EMPTY_SUBSTITUTION);
    final BindingResult bindingResult = grounder.getGroundInstantiations(nonGroundRule, nonGroundRule.getGroundingInfo().orderStartingFrom(startingLiteral), substStartingLiteral, currentAssignment);
    assertEquals(expectNoGoods, bindingResult.size() > 0);
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) InternalProgram(at.ac.tuwien.kr.alpha.core.programs.InternalProgram) BeforeEach(org.junit.jupiter.api.BeforeEach) Substitution(at.ac.tuwien.kr.alpha.api.grounder.Substitution) Arrays(java.util.Arrays) TrailAssignment(at.ac.tuwien.kr.alpha.core.solver.TrailAssignment) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) AnalyzedProgram(at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram) ThriceTruth(at.ac.tuwien.kr.alpha.core.solver.ThriceTruth) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Disabled(org.junit.jupiter.api.Disabled) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) Terms(at.ac.tuwien.kr.alpha.commons.terms.Terms) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) Map(java.util.Map) BindingResult(at.ac.tuwien.kr.alpha.core.grounder.instantiation.BindingResult) CompiledRule(at.ac.tuwien.kr.alpha.core.rules.CompiledRule) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Literals(at.ac.tuwien.kr.alpha.core.atoms.Literals) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) NormalizeProgramTransformation(at.ac.tuwien.kr.alpha.core.programs.transformation.NormalizeProgramTransformation) Collection(java.util.Collection) GrounderHeuristicsConfiguration(at.ac.tuwien.kr.alpha.api.config.GrounderHeuristicsConfiguration) StratifiedEvaluation(at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation) ProgramPartParser(at.ac.tuwien.kr.alpha.core.parser.ProgramPartParser) TestUtils.atom(at.ac.tuwien.kr.alpha.core.test.util.TestUtils.atom) Test(org.junit.jupiter.api.Test) List(java.util.List) Assignment(at.ac.tuwien.kr.alpha.core.common.Assignment) Instance(at.ac.tuwien.kr.alpha.commons.substitutions.Instance) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) InternalRule(at.ac.tuwien.kr.alpha.core.rules.InternalRule) Collections(java.util.Collections) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) BindingResult(at.ac.tuwien.kr.alpha.core.grounder.instantiation.BindingResult) AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) Substitution(at.ac.tuwien.kr.alpha.api.grounder.Substitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) Instance(at.ac.tuwien.kr.alpha.commons.substitutions.Instance) CompiledRule(at.ac.tuwien.kr.alpha.core.rules.CompiledRule) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) TrailAssignment(at.ac.tuwien.kr.alpha.core.solver.TrailAssignment)

Example 32 with AtomStoreImpl

use of at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl in project Alpha by alpha-asp.

the class BerkMinTest method setUp.

@BeforeEach
public void setUp() {
    AtomStore atomStore = new AtomStoreImpl();
    TestUtils.fillAtomStore(atomStore, 2);
    WritableAssignment assignment = new TrailAssignment(atomStore);
    assignment.growForMaxAtomId();
    this.berkmin = new BerkMin(assignment, new PseudoChoiceManager(assignment, new NaiveNoGoodStore(assignment)), new Random());
}
Also used : AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) Random(java.util.Random) NaiveNoGoodStore(at.ac.tuwien.kr.alpha.core.solver.NaiveNoGoodStore) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) WritableAssignment(at.ac.tuwien.kr.alpha.core.solver.WritableAssignment) TrailAssignment(at.ac.tuwien.kr.alpha.core.solver.TrailAssignment) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)32 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)26 TrailAssignment (at.ac.tuwien.kr.alpha.core.solver.TrailAssignment)23 Test (org.junit.jupiter.api.Test)20 BasicAtom (at.ac.tuwien.kr.alpha.api.programs.atoms.BasicAtom)13 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)12 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)11 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)10 WritableAssignment (at.ac.tuwien.kr.alpha.core.solver.WritableAssignment)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)9 WorkingMemory (at.ac.tuwien.kr.alpha.core.grounder.WorkingMemory)9 LinkedHashSet (java.util.LinkedHashSet)9 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)8 BasicSubstitution (at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution)8 Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)7 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)7 StratifiedEvaluation (at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation)7 NoGood (at.ac.tuwien.kr.alpha.core.common.NoGood)6 NaiveGrounder (at.ac.tuwien.kr.alpha.core.grounder.NaiveGrounder)6