Search in sources :

Example 1 with DynamicPercept

use of aima.core.agent.impl.DynamicPercept in project aima-java by aimacode.

the class RuleTest method testNOTRule.

@Test
public void testNOTRule() {
    Rule r = new Rule(new NOTCondition(new EQUALCondition(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true)), ACTION_INITIATE_BRAKING);
    Assert.assertEquals(ACTION_INITIATE_BRAKING, r.getAction());
    Assert.assertEquals("if ![car-in-front-is-braking==true] then Action[name==initiate-braking].", r.toString());
    Assert.assertEquals(false, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true)));
    Assert.assertEquals(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, false)));
    Assert.assertEquals(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_INDICATING, true)));
}
Also used : NOTCondition(aima.core.agent.impl.aprog.simplerule.NOTCondition) 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 DynamicPercept

use of aima.core.agent.impl.DynamicPercept 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 3 with DynamicPercept

use of aima.core.agent.impl.DynamicPercept in project aima-java by aimacode.

the class RuleTest method testORRule.

@Test
public void testORRule() {
    Rule r = new Rule(new ORCondition(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(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true)));
    Assert.assertEquals(true, 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(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, false, 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, false)));
    Assert.assertEquals(false, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, false, ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, false)));
}
Also used : DynamicPercept(aima.core.agent.impl.DynamicPercept) EQUALCondition(aima.core.agent.impl.aprog.simplerule.EQUALCondition) Rule(aima.core.agent.impl.aprog.simplerule.Rule) ORCondition(aima.core.agent.impl.aprog.simplerule.ORCondition) Test(org.junit.Test)

Example 4 with DynamicPercept

use of aima.core.agent.impl.DynamicPercept in project aima-java by aimacode.

the class RuleTest method testEQUALRule.

@Test
public void testEQUALRule() {
    Rule r = new Rule(new EQUALCondition(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true), ACTION_INITIATE_BRAKING);
    Assert.assertEquals(ACTION_INITIATE_BRAKING, r.getAction());
    Assert.assertEquals("if car-in-front-is-braking==true then Action[name==initiate-braking].", r.toString());
    Assert.assertEquals(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true)));
    Assert.assertEquals(false, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, false)));
    Assert.assertEquals(false, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_INDICATING, true)));
}
Also used : 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 5 with DynamicPercept

use of aima.core.agent.impl.DynamicPercept in project aima-java by aimacode.

the class DynamicPerceptTest method testToString.

@Test
public void testToString() {
    DynamicPercept p = new DynamicPercept("key1", "value1");
    Assert.assertEquals("Percept[key1==value1]", p.toString());
    p = new DynamicPercept("key1", "value1", "key2", "value2");
    Assert.assertEquals("Percept[key1==value1, key2==value2]", p.toString());
}
Also used : DynamicPercept(aima.core.agent.impl.DynamicPercept) Test(org.junit.Test)

Aggregations

DynamicPercept (aima.core.agent.impl.DynamicPercept)12 Test (org.junit.Test)9 EQUALCondition (aima.core.agent.impl.aprog.simplerule.EQUALCondition)4 Rule (aima.core.agent.impl.aprog.simplerule.Rule)4 Percept (aima.core.agent.Percept)3 ArrayList (java.util.ArrayList)3 Action (aima.core.agent.Action)1 DynamicAction (aima.core.agent.impl.DynamicAction)1 NoOpAction (aima.core.agent.impl.NoOpAction)1 TableDrivenAgentProgram (aima.core.agent.impl.aprog.TableDrivenAgentProgram)1 ANDCondition (aima.core.agent.impl.aprog.simplerule.ANDCondition)1 NOTCondition (aima.core.agent.impl.aprog.simplerule.NOTCondition)1 ORCondition (aima.core.agent.impl.aprog.simplerule.ORCondition)1 MockAgent (aima.test.core.unit.agent.impl.MockAgent)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Before (org.junit.Before)1