Search in sources :

Example 1 with ANDCondition

use of aima.core.agent.impl.aprog.simplerule.ANDCondition in project aima-java by aimacode.

the class RuleTest method testANDRule.

@Test
public void testANDRule() {
    Rule r = new Rule(new ANDCondition(new EQUALCondition(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true), new EQUALCondition(ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)), ACTION_EMERGENCY_BRAKING);
    Assert.assertEquals(ACTION_EMERGENCY_BRAKING, r.getAction());
    Assert.assertEquals("if [car-in-front-is-braking==true && car-in-front-tires-smoking==true] then Action[name==emergency-braking].", r.toString());
    Assert.assertEquals(false, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true)));
    Assert.assertEquals(false, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)));
    Assert.assertEquals(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true, ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)));
    Assert.assertEquals(false, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, false, ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)));
    Assert.assertEquals(false, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true, ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, false)));
}
Also used : ANDCondition(aima.core.agent.impl.aprog.simplerule.ANDCondition) DynamicPercept(aima.core.agent.impl.DynamicPercept) EQUALCondition(aima.core.agent.impl.aprog.simplerule.EQUALCondition) Rule(aima.core.agent.impl.aprog.simplerule.Rule) Test(org.junit.Test)

Example 2 with ANDCondition

use of aima.core.agent.impl.aprog.simplerule.ANDCondition in project aima-java by aimacode.

the class ModelBasedReflexVacuumAgent method getRuleSet.

//
// PRIVATE METHODS
//
private static Set<Rule> getRuleSet() {
    // Note: Using a LinkedHashSet so that the iteration order (i.e. implied
    // precedence) of rules can be guaranteed.
    Set<Rule> rules = new LinkedHashSet<Rule>();
    rules.add(new Rule(new ANDCondition(new EQUALCondition(ATTRIBUTE_STATE_LOCATION_A, VacuumEnvironment.LocationState.Clean), new EQUALCondition(ATTRIBUTE_STATE_LOCATION_B, VacuumEnvironment.LocationState.Clean)), NoOpAction.NO_OP));
    rules.add(new Rule(new EQUALCondition(ATTRIBUTE_CURRENT_STATE, VacuumEnvironment.LocationState.Dirty), VacuumEnvironment.ACTION_SUCK));
    rules.add(new Rule(new EQUALCondition(ATTRIBUTE_CURRENT_LOCATION, VacuumEnvironment.LOCATION_A), VacuumEnvironment.ACTION_MOVE_RIGHT));
    rules.add(new Rule(new EQUALCondition(ATTRIBUTE_CURRENT_LOCATION, VacuumEnvironment.LOCATION_B), VacuumEnvironment.ACTION_MOVE_LEFT));
    return rules;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ANDCondition(aima.core.agent.impl.aprog.simplerule.ANDCondition) EQUALCondition(aima.core.agent.impl.aprog.simplerule.EQUALCondition) Rule(aima.core.agent.impl.aprog.simplerule.Rule)

Aggregations

ANDCondition (aima.core.agent.impl.aprog.simplerule.ANDCondition)2 EQUALCondition (aima.core.agent.impl.aprog.simplerule.EQUALCondition)2 Rule (aima.core.agent.impl.aprog.simplerule.Rule)2 DynamicPercept (aima.core.agent.impl.DynamicPercept)1 LinkedHashSet (java.util.LinkedHashSet)1 Test (org.junit.Test)1