Esempio n. 1
0
    public void GenericSetContainsRelationIfEquals()
    {
        Domain domain = Utils.roverWorldDomainFirstLevel();

        WorldState worldState = new WorldState(domain);

        EntityType entityTypeRover = new EntityType("ROVER");
        Entity     entityRover     = new Entity(entityTypeRover, "ROVER");

        worldState.addEntity(entityRover);

        Entity wayPointAlpha = new Entity(new EntityType("WAYPOINT"), "WAYPOINT1");
        Entity wayPointBravo = new Entity(new EntityType("WAYPOINT"), "WAYPOINT2");

        worldState.addEntity(wayPointAlpha);
        worldState.addEntity(wayPointBravo);

        BinaryRelation isConnected1 = domain.generateRelationFromPredicateName("IS_CONNECTED_TO", wayPointAlpha, wayPointBravo, RelationValue.TRUE);

        worldState.addRelation(isConnected1);

        BinaryRelation isAtAlpha = domain.generateRelationFromPredicateName("AT", entityRover, wayPointAlpha, RelationValue.TRUE);

        worldState.addRelation(isAtAlpha);

        Action actionMove = worldState.Domain.getAction("MOVE");

        foreach (IRelation precondition in actionMove.PreConditions)
        {
            Assert.IsTrue(worldState.Relations.Contains(precondition));
        }
    }
Esempio n. 2
0
    public void getPossibleActionsReturnsMoveActionIfisConnected()
    {
        Domain domain = Utils.roverWorldDomainFirstLevel();

        WorldState worldState = new WorldState(domain);

        EntityType entityTypeRover = new EntityType("ROVER");
        Entity     entityRover     = new Entity(entityTypeRover, "ROVER");

        worldState.addEntity(entityRover);

        Entity wayPointAlpha = new Entity(new EntityType("WAYPOINT"), "WAYPOINT1");
        Entity wayPointBravo = new Entity(new EntityType("WAYPOINT"), "WAYPOINT2");

        worldState.addEntity(wayPointAlpha);
        worldState.addEntity(wayPointBravo);

        BinaryRelation isConnected1 = domain.generateRelationFromPredicateName("IS_CONNECTED_TO", wayPointAlpha, wayPointBravo, RelationValue.TRUE);

        worldState.addRelation(isConnected1);

        BinaryRelation isAtAlpha = domain.generateRelationFromPredicateName("AT", entityRover, wayPointAlpha, RelationValue.TRUE);

        worldState.addRelation(isAtAlpha);

        Action actionMove = worldState.Domain.getAction("MOVE");
        Action actionIdle = worldState.Domain.getAction("IDLE");

        HashSet <Action> performableActions = new HashSet <Action>();

        performableActions.Add(actionMove);
        performableActions.Add(actionIdle);

        CollectionAssert.AreEquivalent(performableActions, worldState.getPossibleActions());
    }
Esempio n. 3
0
    public void CloneReturnsEqualWorldState()
    {
        Domain domain = Utils.roverWorldDomainThirdLevel();

        WorldState worldState = new WorldState(domain);

        Entity entityRover = new Entity(new EntityType("ROVER"), "ROVER");

        worldState.addEntity(entityRover);

        Entity entityWaypoint = new Entity(new EntityType("WAYPOINT"), "WAYPOINT");

        worldState.addEntity(entityWaypoint);

        Entity entityObjective = new Entity(new EntityType("OBJECTIVE"), "OBJECTIVE");

        worldState.addEntity(entityObjective);

        BinaryRelation roverIsAtWaypoint = domain.generateRelationFromPredicateName("AT", entityRover, entityWaypoint, RelationValue.TRUE);
        BinaryRelation objectiveIsVisibleFromWaypoint = domain.generateRelationFromPredicateName("IS_VISIBLE", entityObjective, entityWaypoint, RelationValue.TRUE);

        worldState.addRelation(roverIsAtWaypoint);
        worldState.addRelation(objectiveIsVisibleFromWaypoint);

        WorldState clonedWorldState = worldState.Clone();

        Assert.AreEqual(worldState, clonedWorldState);
    }
Esempio n. 4
0
    public void BinaryRelationSourceMustBeAnExistingEntity()
    {
        Domain     domain    = new Domain();
        EntityType character = new EntityType("CHARACTER");

        domain.addEntityType(character);

        EntityType location = new EntityType("LOCATION");

        domain.addEntityType(location);

        BinaryPredicate isAt = new BinaryPredicate(character, "IS_AT", location);

        domain.addPredicate(isAt);

        WorldState worldState = new WorldState(domain);
        Entity     john       = new Entity(character, "JOHN");
        // worldState.addEntity(john);

        Entity school = new Entity(location, "SCHOOL");

        worldState.addEntity(school);

        BinaryRelation johnIsAtSchool = new BinaryRelation(john, isAt, school, RelationValue.TRUE);

        Assert.That(() => worldState.addRelation(johnIsAtSchool), Throws.ArgumentException);
    }
Esempio n. 5
0
    private void DescribeObjectState()
    {
        Text myText = GameObject.Find("Content").GetComponent <Text>();

        Domain     domainFirstLevel     = Utils.roverWorldDomainFirstLevel();
        WorldState worldStateFirstLevel = Utils.roverWorldStateFirstLevel(domainFirstLevel);

        foreach (IRelation r in worldStateFirstLevel.Relations)
        {
            if (r.GetType() == typeof(BinaryRelation))
            {
                BinaryRelation rel = r as BinaryRelation;
                if (rel.Source.ToString() == selectedObject.name || rel.Destination.ToString() == selectedObject.name)
                {
                    BinaryPredicate pred = r as BinaryPredicate;
                    myText.text += pred.Description + "\n";
                }
            }
            else
            {
                UnaryRelation rel = r as UnaryRelation;
                if (rel.Source.ToString() == selectedObject.name)
                {
                    BinaryPredicate pred = r as BinaryPredicate;
                    myText.text += pred.Description + "\n";
                }
            }
        }

        myText.text += "ciaoooooo";
    }
Esempio n. 6
0
    public void getPossibleActionsReturnsTakeImageActionIfCanTakeImage()
    {
        Domain domain = Utils.roverWorldDomainFirstLevel();

        WorldState worldState = new WorldState(domain);

        Entity entityRover = new Entity(new EntityType("ROVER"), "ROVER");

        worldState.addEntity(entityRover);

        Entity entityWaypoint = new Entity(new EntityType("WAYPOINT"), "WAYPOINT");

        worldState.addEntity(entityWaypoint);

        Entity entityObjective = new Entity(new EntityType("OBJECTIVE"), "OBJECTIVE");

        worldState.addEntity(entityObjective);

        BinaryRelation roverIsAtWaypoint = domain.generateRelationFromPredicateName("AT", entityRover, entityWaypoint, RelationValue.TRUE);
        BinaryRelation objectiveIsVisibleFromWaypoint = domain.generateRelationFromPredicateName("IS_VISIBLE", entityObjective, entityWaypoint, RelationValue.TRUE);

        worldState.addRelation(roverIsAtWaypoint);
        worldState.addRelation(objectiveIsVisibleFromWaypoint);

        Action actionTakeImage = worldState.Domain.getAction("TAKE_IMAGE");
        Action actionIdle      = worldState.Domain.getAction("IDLE");

        HashSet <Action> performableActions = new HashSet <Action>();

        performableActions.Add(actionTakeImage);
        performableActions.Add(actionIdle);

        CollectionAssert.AreEquivalent(performableActions, worldState.getPossibleActions());
    }
Esempio n. 7
0
    public void canPerformActionReturnsTrueForAppliableAction()
    {
        Domain domain = this.getSimpleMoveDomain();

        WorldState worldState = new WorldState(domain);

        EntityType entityTypeRover = new EntityType("ROVER");
        Entity     entityRover     = new Entity(entityTypeRover, "ROVER");

        worldState.addEntity(entityRover);

        Entity wayPoint1 = new Entity(new EntityType("WAYPOINT"), "WAYPOINT1");
        Entity wayPoint2 = new Entity(new EntityType("WAYPOINT"), "WAYPOINT2");

        worldState.addEntity(wayPoint1);
        worldState.addEntity(wayPoint2);

        BinaryRelation isConnected1 = domain.generateRelationFromPredicateName("IS_CONNECTED_TO", wayPoint1, wayPoint2, RelationValue.TRUE);

        worldState.addRelation(isConnected1);

        BinaryRelation isAt1 = domain.generateRelationFromPredicateName("AT", entityRover, wayPoint1, RelationValue.TRUE);

        worldState.addRelation(isAt1);

        Action actionMove = worldState.Domain.getAction("MOVE");

        Assert.IsTrue(worldState.canPerformAction(actionMove));
    }
Esempio n. 8
0
    public void ActionConditionsEntitiesMustBeInParameters()
    {
        EntityType sourceEntityType1 = new EntityType("CHARACTER");

        EntityType destinationEntityType1 = new EntityType("ARTIFACT");

        Entity sourceEntity1 = new Entity(sourceEntityType1, "JOHN");

        Entity destinationEntity1 = new Entity(destinationEntityType1, "APPLE");

        BinaryPredicate bp1 = new BinaryPredicate(sourceEntityType1, "PICK_UP", destinationEntityType1);

        BinaryRelation br1 = new BinaryRelation(sourceEntity1, bp1, destinationEntity1, RelationValue.TRUE);

        HashSet <ActionParameter> parametersAction1 = new HashSet <ActionParameter>();
        // parametersAction1.Add(sourceEntity1);
        // parametersAction1.Add(destinationEntity1);

        HashSet <IRelation> preconditionsAction1 = new HashSet <IRelation>();

        preconditionsAction1.Add(br1);
        HashSet <IRelation> postconditionsAction1 = new HashSet <IRelation>();

        postconditionsAction1.Add(br1);

        Assert.That(() => new Action(preconditionsAction1, "PICK_UP", parametersAction1, postconditionsAction1), Throws.ArgumentException);
    }
Esempio n. 9
0
    public void thirdLODRoverCanDropImageIfPreconditionsAreSatisfied()
    {
        Domain domain = Utils.roverWorldDomainThirdLevel();

        WorldState worldState = new WorldState(domain);

        EntityType entityTypeRover = new EntityType("ROVER");
        Entity     entityRover     = new Entity(entityTypeRover, "ROVER");

        worldState.addEntity(entityRover);

        EntityType entityTypeBattery = new EntityType("BATTERY");
        Entity     entityBattery1    = new Entity(entityTypeBattery, "BATTERY");

        worldState.addEntity(entityBattery1);

        EntityType entityTypeWheel = new EntityType("WHEEL");
        Entity     entityWheels    = new Entity(entityTypeWheel, "WHEELS");

        worldState.addEntity(entityWheels);

        Entity wayPointAlpha = new Entity(new EntityType("WAYPOINT"), "WAYPOINT");

        worldState.addEntity(wayPointAlpha);

        Entity entitySample = new Entity(new EntityType("SAMPLE"), "SAMPLE");

        worldState.addEntity(entitySample);

        UnaryRelation  wayPointIsDroppingDock = domain.generateRelationFromPredicateName("IS_DROPPING_DOCK", wayPointAlpha, RelationValue.TRUE);
        BinaryRelation roverIsAtWaypoint      = domain.generateRelationFromPredicateName("AT", entityRover, wayPointAlpha, RelationValue.TRUE);
        BinaryRelation roverCarriesSample     = domain.generateRelationFromPredicateName("CARRY", entityRover, entitySample, RelationValue.TRUE);

        worldState.addRelation(wayPointIsDroppingDock);
        worldState.addRelation(roverIsAtWaypoint);
        worldState.addRelation(roverCarriesSample);

        BinaryPredicate predicateHasBattery      = new BinaryPredicate(entityTypeRover, "HAS", entityTypeBattery);
        BinaryRelation  relationRoverHasBattery1 = new BinaryRelation(entityRover, predicateHasBattery, entityBattery1, RelationValue.TRUE);

        worldState.addRelation(relationRoverHasBattery1);

        BinaryPredicate predicateHasWheels     = new BinaryPredicate(entityTypeRover, "HAS", entityTypeWheel);
        BinaryRelation  relationRoverHasWheels = new BinaryRelation(entityRover, predicateHasWheels, entityWheels, RelationValue.TRUE);

        worldState.addRelation(relationRoverHasWheels);

        UnaryRelation batteryCharged = domain.generateRelationFromPredicateName("BATTERY_CHARGED", entityBattery1, RelationValue.TRUE);

        worldState.addRelation(batteryCharged);

        UnaryRelation wheelsInflated = domain.generateRelationFromPredicateName("WHEELS_INFLATED", entityWheels, RelationValue.TRUE);

        worldState.addRelation(wheelsInflated);

        Action actionDropSample = worldState.Domain.getAction("DROP_SAMPLE");

        Assert.True(worldState.getPossibleActions().Contains(actionDropSample));
    }
Esempio n. 10
0
    public void ActionPreconditionsMustBeExistingPredicates()
    {
        Domain domain = new Domain();

        EntityType rover = new EntityType("ROVER");

        domain.addEntityType(rover);

        EntityType wayPoint = new EntityType("WAYPOINT");

        domain.addEntityType(wayPoint);

        //(can-move ?from-waypoint ?to-waypoint)
        BinaryPredicate isConnectedTo = new BinaryPredicate(wayPoint, "IS_CONNECTED_TO", wayPoint);
        // domain.addPredicate(isConnectedTo);
        //(been-at ?rover ?waypoint)
        BinaryPredicate beenAt = new BinaryPredicate(rover, "BEEN_AT", wayPoint);
        // domain.addPredicate(beenAt);
        //(at ?rover ?waypoint)
        BinaryPredicate at = new BinaryPredicate(rover, "AT", wayPoint);
        // domain.addPredicate(at);
        //              MOVE ACTION
        // Parameters
        Entity curiosity    = new Entity(rover, "ROVER");
        Entity fromWayPoint = new Entity(wayPoint, "WAYPOINT1");
        Entity toWayPoint   = new Entity(wayPoint, "WAYPOINT2");

        HashSet <ActionParameter> moveActionParameters = new HashSet <ActionParameter>();

        moveActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE));
        moveActionParameters.Add(new ActionParameter(fromWayPoint, ActionParameterRole.PASSIVE));
        moveActionParameters.Add(new ActionParameter(toWayPoint, ActionParameterRole.PASSIVE));

        // Preconditions
        HashSet <IRelation> moveActionPreconditions = new HashSet <IRelation>();
        BinaryRelation      roverAtfromWP           = new BinaryRelation(curiosity, at, fromWayPoint, RelationValue.TRUE);

        moveActionPreconditions.Add(roverAtfromWP);
        BinaryRelation isConnectedFromWP1ToWP2 = new BinaryRelation(fromWayPoint, isConnectedTo, toWayPoint, RelationValue.TRUE);

        moveActionPreconditions.Add(isConnectedFromWP1ToWP2);

        // Postconditions
        HashSet <IRelation> moveActionPostconditions = new HashSet <IRelation>();
        BinaryRelation      notRoverAtFromWP         = new BinaryRelation(curiosity, at, fromWayPoint, RelationValue.FALSE);

        moveActionPostconditions.Add(notRoverAtFromWP);
        BinaryRelation roverAtToWP = new BinaryRelation(curiosity, at, toWayPoint, RelationValue.TRUE);

        moveActionPostconditions.Add(roverAtToWP);
        BinaryRelation roverBeenAtToWP = new BinaryRelation(curiosity, beenAt, toWayPoint, RelationValue.TRUE);

        moveActionPostconditions.Add(roverBeenAtToWP);

        Action moveAction = new Action(moveActionPreconditions, "MOVE", moveActionParameters, moveActionPostconditions);

        Assert.That(() => domain.addAction(moveAction), Throws.ArgumentException);
    }
Esempio n. 11
0
 public BinaryRelationPredicate(BinaryRelation relation, Term first, Term second)
 {
     Debug.Assert(relation != null);
     Debug.Assert(first != null);
     Debug.Assert(second != null);
     this.relation = relation;
     this.first    = first;
     this.second   = second;
 }
Esempio n. 12
0
    public void thirdLODRoverCanTakeImageIfPreconditionsAreSatisfied()
    {
        Domain domain = Utils.roverWorldDomainThirdLevel();

        WorldState worldState = new WorldState(domain);

        EntityType entityTypeRover = new EntityType("ROVER");
        Entity     entityRover     = new Entity(entityTypeRover, "ROVER");

        worldState.addEntity(entityRover);

        EntityType entityTypeBattery = new EntityType("BATTERY");
        Entity     entityBattery1    = new Entity(entityTypeBattery, "BATTERY");

        worldState.addEntity(entityBattery1);

        EntityType entityTypeWheel = new EntityType("WHEEL");
        Entity     entityWheels    = new Entity(entityTypeWheel, "WHEELS");

        worldState.addEntity(entityWheels);

        Entity wayPointAlpha = new Entity(new EntityType("WAYPOINT"), "WAYPOINT");

        worldState.addEntity(wayPointAlpha);

        Entity entityObjective = new Entity(new EntityType("OBJECTIVE"), "OBJECTIVE");

        worldState.addEntity(entityObjective);

        BinaryRelation roverIsAtWaypoint = domain.generateRelationFromPredicateName("AT", entityRover, wayPointAlpha, RelationValue.TRUE);
        BinaryRelation objectiveIsVisibleFromWaypoint = domain.generateRelationFromPredicateName("IS_VISIBLE", entityObjective, wayPointAlpha, RelationValue.TRUE);

        worldState.addRelation(roverIsAtWaypoint);
        worldState.addRelation(objectiveIsVisibleFromWaypoint);

        BinaryPredicate predicateHasBattery      = new BinaryPredicate(entityTypeRover, "HAS", entityTypeBattery);
        BinaryRelation  relationRoverHasBattery1 = new BinaryRelation(entityRover, predicateHasBattery, entityBattery1, RelationValue.TRUE);

        worldState.addRelation(relationRoverHasBattery1);

        BinaryPredicate predicateHasWheels     = new BinaryPredicate(entityTypeRover, "HAS", entityTypeWheel);
        BinaryRelation  relationRoverHasWheels = new BinaryRelation(entityRover, predicateHasWheels, entityWheels, RelationValue.TRUE);

        worldState.addRelation(relationRoverHasWheels);

        UnaryRelation batteryCharged = domain.generateRelationFromPredicateName("BATTERY_CHARGED", entityBattery1, RelationValue.TRUE);

        worldState.addRelation(batteryCharged);

        UnaryRelation wheelsInflated = domain.generateRelationFromPredicateName("WHEELS_INFLATED", entityWheels, RelationValue.TRUE);

        worldState.addRelation(wheelsInflated);

        Action actionTakeImage = worldState.Domain.getAction("TAKE_IMAGE");

        Assert.True(worldState.getPossibleActions().Contains(actionTakeImage));
    }
Esempio n. 13
0
    public static WorldState roverWorldStateSecondLevel(Domain domain)
    {
        WorldState detailedState = roverWorldStateFirstLevel(domain);

        Entity wayPoint1 = detailedState.getEntity("WAYPOINT1");
        Entity wayPoint2 = detailedState.getEntity("WAYPOINT2");
        Entity wayPoint3 = detailedState.getEntity("WAYPOINT3");
        Entity wayPoint4 = detailedState.getEntity("WAYPOINT4");
        Entity wayPoint5 = detailedState.getEntity("WAYPOINT5");
        Entity wayPoint6 = detailedState.getEntity("WAYPOINT6");
        Entity wayPoint7 = detailedState.getEntity("WAYPOINT7");
        Entity wayPoint8 = detailedState.getEntity("WAYPOINT8");
        Entity wayPoint9 = detailedState.getEntity("WAYPOINT9");

        BinaryRelation relationObstacleBetween4and3 = detailedState.Domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint4, wayPoint3, RelationValue.TRUE);
        BinaryRelation relationObstacleBetween8and4 = detailedState.Domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint8, wayPoint4, RelationValue.TRUE);
        BinaryRelation relationObstacleBetween6and8 = detailedState.Domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint6, wayPoint8, RelationValue.TRUE);
        BinaryRelation relationObstacleBetween3and6 = detailedState.Domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint3, wayPoint6, RelationValue.TRUE);

        detailedState.addRelation(relationObstacleBetween4and3);
        detailedState.addRelation(relationObstacleBetween8and4);
        detailedState.addRelation(relationObstacleBetween6and8);
        detailedState.addRelation(relationObstacleBetween3and6);

        BinaryRelation relationNotObstacleBetween1and5 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint1, wayPoint5, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween2and5 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint2, wayPoint5, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween4and8 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint4, wayPoint8, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween5and1 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint5, wayPoint1, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween6and3 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint6, wayPoint3, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween9and1 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint9, wayPoint1, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween1and9 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint1, wayPoint9, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween3and4 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint3, wayPoint4, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween4and9 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint4, wayPoint9, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween5and2 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint5, wayPoint2, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween6and7 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint6, wayPoint7, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween7and6 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint7, wayPoint6, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween8and6 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint8, wayPoint6, RelationValue.FALSE);
        BinaryRelation relationNotObstacleBetween9and4 = domain.generateRelationFromPredicateName("OBSTACLE_BETWEEN", wayPoint9, wayPoint4, RelationValue.FALSE);

        detailedState.addRelation(relationNotObstacleBetween1and5);
        detailedState.addRelation(relationNotObstacleBetween2and5);
        detailedState.addRelation(relationNotObstacleBetween4and8);
        detailedState.addRelation(relationNotObstacleBetween5and1);
        detailedState.addRelation(relationNotObstacleBetween6and3);
        detailedState.addRelation(relationNotObstacleBetween9and1);
        detailedState.addRelation(relationNotObstacleBetween1and9);
        detailedState.addRelation(relationNotObstacleBetween3and4);
        detailedState.addRelation(relationNotObstacleBetween4and9);
        detailedState.addRelation(relationNotObstacleBetween5and2);
        detailedState.addRelation(relationNotObstacleBetween6and7);
        detailedState.addRelation(relationNotObstacleBetween7and6);
        detailedState.addRelation(relationNotObstacleBetween8and6);
        detailedState.addRelation(relationNotObstacleBetween9and4);

        return(detailedState);
    }
Esempio n. 14
0
        /// <summary>
        /// Creates a domain constraint restricting an attribute to be greater than the MetricDomain max value - 1
        /// </summary>
        /// <returns></returns>
        public static DomainConstraint MaxValueConstraint(GKOAttribute attribute, GKOIntDomain metricDomain)
        {
            BinaryRelation   lessOrEquals  = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.LessOrEqualsN);
            DomainConstraint maxConstraint = new DomainConstraint("Metric max value constraint", lessOrEquals, false);

            maxConstraint.DomainRelationParts.Add(new AttributeDomainRelationPart(new ComponentFilter(), attribute));
            maxConstraint.DomainRelationParts.Add(new MetricDomainRelationPart(metricDomain.MaxValue, metricDomain));

            return(maxConstraint);
        }
Esempio n. 15
0
    public static WorldState roverWorldStateThirdLevel(Domain domain)
    {
        WorldState detailedState = roverWorldStateSecondLevel(domain);

        EntityType entityTypeRover   = new EntityType("ROVER");
        EntityType entityTypeBattery = new EntityType("BATTERY");
        EntityType entityTypeWheel   = new EntityType("WHEEL");

        Entity entityBatteryRover1 = new Entity(entityTypeBattery, "BATTERY_ROVER1");
        Entity entityBatteryRover2 = new Entity(entityTypeBattery, "BATTERY_ROVER2");

        Entity entityWheelsRover1 = new Entity(entityTypeWheel, "WHEELS_ROVER1");
        Entity entityWheelsRover2 = new Entity(entityTypeWheel, "WHEELS_ROVER2");

        detailedState.addEntity(entityBatteryRover1);
        detailedState.addEntity(entityBatteryRover2);

        detailedState.addEntity(entityWheelsRover1);
        detailedState.addEntity(entityWheelsRover2);

        // Rovers have their respective batteries
        BinaryPredicate predicateHasBattery = new BinaryPredicate(entityTypeRover, "HAS", entityTypeBattery);

        BinaryRelation relationRover1HasBattery1 = new BinaryRelation(detailedState.getEntity("ROVER1"), predicateHasBattery, entityBatteryRover1, RelationValue.TRUE);
        BinaryRelation relationRover2HasBattery2 = new BinaryRelation(detailedState.getEntity("ROVER2"), predicateHasBattery, entityBatteryRover2, RelationValue.TRUE);

        detailedState.addRelation(relationRover1HasBattery1);
        detailedState.addRelation(relationRover2HasBattery2);

        // the batteries are charged
        UnaryRelation relationBatteryRover1IsCharged = detailedState.Domain.generateRelationFromPredicateName("BATTERY_CHARGED", entityBatteryRover1, RelationValue.TRUE);
        UnaryRelation relationBatteryRover2IsCharged = detailedState.Domain.generateRelationFromPredicateName("BATTERY_CHARGED", entityBatteryRover2, RelationValue.TRUE);

        detailedState.addRelation(relationBatteryRover1IsCharged);
        detailedState.addRelation(relationBatteryRover2IsCharged);

        // Rovers have their respective wheels
        BinaryPredicate predicateHasWheels = new BinaryPredicate(entityTypeRover, "HAS", entityTypeWheel);

        BinaryRelation relationRover1HasWheels1 = new BinaryRelation(detailedState.getEntity("ROVER1"), predicateHasWheels, entityWheelsRover1, RelationValue.TRUE);
        BinaryRelation relationRover2HasWheels2 = new BinaryRelation(detailedState.getEntity("ROVER2"), predicateHasWheels, entityWheelsRover2, RelationValue.TRUE);

        detailedState.addRelation(relationRover1HasWheels1);
        detailedState.addRelation(relationRover2HasWheels2);

        // the wheels are inflated
        UnaryRelation relationWheelsRover1Inflated = detailedState.Domain.generateRelationFromPredicateName("WHEELS_INFLATED", entityWheelsRover1, RelationValue.TRUE);
        UnaryRelation relationWheelsRover2Inflated = detailedState.Domain.generateRelationFromPredicateName("WHEELS_INFLATED", entityWheelsRover2, RelationValue.TRUE);

        detailedState.addRelation(relationWheelsRover1Inflated);
        detailedState.addRelation(relationWheelsRover2Inflated);

        return(detailedState);
    }
Esempio n. 16
0
    public int GetHashCode(IRelation relation)
    {
        int hashCode = relation.Source.GetHashCode() * 17;

        hashCode += relation.Predicate.GetHashCode() * 17;
        if (relation.GetType() == typeof(BinaryRelation))
        {
            BinaryRelation binaryRelation = relation as BinaryRelation;
            hashCode += binaryRelation.Destination.GetHashCode() * 17;
        }
        return(hashCode);
    }
Esempio n. 17
0
    public void equalsReturnsFalseIfEntitiesAreNotEqual()
    {
        Domain domain = Utils.roverWorldDomainThirdLevel();

        WorldState worldState1 = new WorldState(domain);

        Entity entityRover1 = new Entity(new EntityType("ROVER"), "ROVER");

        worldState1.addEntity(entityRover1);

        Entity entityWaypoint1 = new Entity(new EntityType("WAYPOINT"), "WAYPOINT");

        worldState1.addEntity(entityWaypoint1);

        Entity entityObjective1 = new Entity(new EntityType("OBJECTIVE"), "OBJECTIVE");

        worldState1.addEntity(entityObjective1);

        BinaryRelation roverIsAtWaypoint1 = domain.generateRelationFromPredicateName("AT", entityRover1, entityWaypoint1, RelationValue.TRUE);
        BinaryRelation objectiveIsVisibleFromWaypoint1 = domain.generateRelationFromPredicateName("IS_VISIBLE", entityObjective1, entityWaypoint1, RelationValue.TRUE);

        worldState1.addRelation(roverIsAtWaypoint1);
        worldState1.addRelation(objectiveIsVisibleFromWaypoint1);

        Domain domain2 = Utils.roverWorldDomainThirdLevel();

        WorldState worldState2 = new WorldState(domain2);

        Entity entityRover2 = new Entity(new EntityType("ROVER"), "ROVER");

        worldState2.addEntity(entityRover2);

        Entity entityWaypoint2 = new Entity(new EntityType("WAYPOINT"), "WAYPOINT");

        worldState2.addEntity(entityWaypoint2);

        Entity entityObjective2 = new Entity(new EntityType("OBJECTIVE"), "OBJECTIVE");

        worldState2.addEntity(entityObjective2);

        Entity entitySample2 = new Entity(new EntityType("SAMPLE"), "SAMPLE");

        worldState2.addEntity(entitySample2);

        BinaryRelation roverIsAtWaypoint2 = domain.generateRelationFromPredicateName("AT", entityRover2, entityWaypoint2, RelationValue.TRUE);
        BinaryRelation objectiveIsVisibleFromWaypoint2 = domain.generateRelationFromPredicateName("IS_VISIBLE", entityObjective2, entityWaypoint2, RelationValue.TRUE);

        worldState2.addRelation(roverIsAtWaypoint2);
        worldState2.addRelation(objectiveIsVisibleFromWaypoint2);

        Assert.AreNotEqual(worldState1, worldState2);
    }
Esempio n. 18
0
    public void CloneReturnsEqualBinaryRelation()
    {
        EntityType entityTypeRover = new EntityType("ROVER");
        Entity     entityRover     = new Entity(entityTypeRover, "ROVER");

        EntityType entityTypeWaypoint = new EntityType("WAYPOINT");
        Entity     entityWaypoint     = new Entity(entityTypeWaypoint, "WAYPOINT");

        BinaryPredicate predicateRoverisAtWaypoint      = new BinaryPredicate(entityTypeRover, "IS_AT", entityTypeWaypoint);
        BinaryRelation  relationRoverIsAtWaypoint       = new BinaryRelation(entityRover, predicateRoverisAtWaypoint, entityWaypoint, RelationValue.TRUE);
        BinaryRelation  relationClonedRoverIsAtWaypoint = relationRoverIsAtWaypoint.Clone() as BinaryRelation;

        Assert.AreEqual(relationRoverIsAtWaypoint, relationClonedRoverIsAtWaypoint);
    }
Esempio n. 19
0
        /// <summary>
        /// Creates a domain constraint restricting the start of an interval to be before (or equal) to its end
        /// </summary>
        /// <param name="startAttribute">The start of interval attribute </param>
        /// <param name="endAttribute">The end of interval attribute </param>
        /// <param name="allowZeroIntervals">Specifies whether to use "Less than" or "Less or equals" relations, which enables/disables the generation of zero-length intervals</param>
        /// <returns></returns>
        public static DomainConstraint IntervalStartBeforeEndConstraint(GKOAttribute startAttribute, GKOAttribute endAttribute, bool allowZeroIntervals)
        {
            BinaryRelation   relation           = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, allowZeroIntervals ? MetricRelationNames.LessOrEquals : MetricRelationNames.LessThan);
            DomainConstraint intervalConstraint = new DomainConstraint("Interval start/end constraint", relation, false);

            intervalConstraint.DomainRelationParts.Add(new AttributeDomainRelationPart(new ComponentFilter(), startAttribute));
            intervalConstraint.DomainRelationParts.Add(new AttributeDomainRelationPart(
                                                           new ComponentFilter()
            {
                SameAsDomainRelationPartNr = 1
            },
                                                           endAttribute));

            return(intervalConstraint);
        }
Esempio n. 20
0
        /// <summary>
        /// Cretes a new domain constraint which constraints which requires a relation between the matched components.
        /// </summary>
        /// <param name="name">The unique name of the domain constraint.</param>
        /// <param name="requiredRelation">The relation between the matched components.</param>
        /// <param name="canBeViolated">Set to true for soft constraint, false for hard constraint</param>
        /// <param name="comp1Attribute">The attribute to constraint for the first component</param>
        /// <param name="comp2Attribute">The attribute to constraint for the second component</param>
        public PaToMetricDomainConstraint(string name, BinaryRelation requiredRelation, bool canBeViolated, GKOAttribute comp1Attribute, GKOAttribute comp2Attribute)
            : base(name, requiredRelation, canBeViolated)
        {
            if (requiredRelation.RelationFamily != StructuralRelationsManager.IntervalAlgebra)
            {
                throw new ArgumentNullException("The required relation has to be from the Interval Algebra!");
            }
            if (comp1Attribute == null || comp2Attribute == null)
            {
                throw new ArgumentNullException("All attributes should be set!");
            }

            this.Comp1Attribute = comp1Attribute;
            this.Comp2Attribute = comp2Attribute;
        }
Esempio n. 21
0
    public void ActionsAreNotEqualIfNamesAreNotEqual()
    {
        EntityType sourceEntityType1 = new EntityType("CHARACTER");
        EntityType sourceEntityType2 = new EntityType("CHARACTER");

        EntityType destinationEntityType1 = new EntityType("ARTIFACT");
        EntityType destinationEntityType2 = new EntityType("ARTIFACT");

        Entity sourceEntity1 = new Entity(sourceEntityType1, "JOHN");
        Entity sourceEntity2 = new Entity(sourceEntityType2, "JOHN");

        Entity destinationEntity1 = new Entity(destinationEntityType1, "APPLE");
        Entity destinationEntity2 = new Entity(destinationEntityType2, "APPLE");

        BinaryPredicate bp1 = new BinaryPredicate(sourceEntityType1, "PICK_UP", destinationEntityType1);
        BinaryPredicate bp2 = new BinaryPredicate(sourceEntityType2, "PICK_UP", destinationEntityType2);

        BinaryRelation br1 = new BinaryRelation(sourceEntity1, bp1, destinationEntity1, RelationValue.TRUE);
        BinaryRelation br2 = new BinaryRelation(sourceEntity2, bp2, destinationEntity2, RelationValue.TRUE);

        HashSet <ActionParameter> parametersAction1 = new HashSet <ActionParameter>();

        parametersAction1.Add(new ActionParameter(sourceEntity1, ActionParameterRole.ACTIVE));
        parametersAction1.Add(new ActionParameter(destinationEntity1, ActionParameterRole.PASSIVE));
        HashSet <IRelation> preconditionsAction1 = new HashSet <IRelation>();

        preconditionsAction1.Add(br1);
        HashSet <IRelation> postconditionsAction1 = new HashSet <IRelation>();

        postconditionsAction1.Add(br1);

        Action a1 = new Action(preconditionsAction1, "PICK_UP", parametersAction1, postconditionsAction1);

        HashSet <ActionParameter> parametersAction2 = new HashSet <ActionParameter>();

        parametersAction2.Add(new ActionParameter(sourceEntity2, ActionParameterRole.ACTIVE));
        parametersAction2.Add(new ActionParameter(destinationEntity2, ActionParameterRole.PASSIVE));
        HashSet <IRelation> preconditionsAction2 = new HashSet <IRelation>();

        preconditionsAction2.Add(br2);
        HashSet <IRelation> postconditionsAction2 = new HashSet <IRelation>();

        postconditionsAction2.Add(br2);

        Action a2 = new Action(preconditionsAction2, "PICK_UP2", parametersAction2, postconditionsAction2);

        Assert.False(a1.Equals(a2) || a1.GetHashCode() == a2.GetHashCode());
    }
Esempio n. 22
0
    public void CloneReturnsEqualAction()
    {
        EntityType rover    = new EntityType("ROVER");
        EntityType wayPoint = new EntityType("WAYPOINT");

        Entity curiosity    = new Entity(rover, "ROVER");
        Entity fromWayPoint = new Entity(wayPoint, "WAYPOINT1");
        Entity toWayPoint   = new Entity(wayPoint, "WAYPOINT2");

        BinaryPredicate isConnectedTo = new BinaryPredicate(wayPoint, "IS_CONNECTED_TO", wayPoint);
        BinaryPredicate at            = new BinaryPredicate(rover, "AT", wayPoint);
        BinaryPredicate beenAt        = new BinaryPredicate(rover, "BEEN_AT", wayPoint);

        HashSet <ActionParameter> moveActionParameters = new HashSet <ActionParameter>();

        moveActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE));
        moveActionParameters.Add(new ActionParameter(fromWayPoint, ActionParameterRole.PASSIVE));
        moveActionParameters.Add(new ActionParameter(toWayPoint, ActionParameterRole.PASSIVE));

        // Preconditions
        HashSet <IRelation> moveActionPreconditions = new HashSet <IRelation>();
        BinaryRelation      roverAtfromWP           = new BinaryRelation(curiosity, at, fromWayPoint, RelationValue.TRUE);

        moveActionPreconditions.Add(roverAtfromWP);
        BinaryRelation isConnectedFromWP1ToWP2 = new BinaryRelation(fromWayPoint, isConnectedTo, toWayPoint, RelationValue.TRUE);

        moveActionPreconditions.Add(isConnectedFromWP1ToWP2);

        // Postconditions
        HashSet <IRelation> moveActionPostconditions = new HashSet <IRelation>();
        BinaryRelation      notRoverAtFromWP         = new BinaryRelation(curiosity, at, fromWayPoint, RelationValue.FALSE);

        moveActionPostconditions.Add(notRoverAtFromWP);
        BinaryRelation roverAtToWP = new BinaryRelation(curiosity, at, toWayPoint, RelationValue.TRUE);

        moveActionPostconditions.Add(roverAtToWP);
        BinaryRelation roverBeenAtToWP = new BinaryRelation(curiosity, beenAt, toWayPoint, RelationValue.TRUE);

        moveActionPostconditions.Add(roverBeenAtToWP);

        Action moveAction       = new Action(moveActionPreconditions, "MOVE", moveActionParameters, moveActionPostconditions);
        Action clonedMoveAction = moveAction.Clone();

        Assert.AreEqual(moveAction, clonedMoveAction);
    }
        public void EmptyObjects()
        {
            var ast = new BinaryRelation()
            {
                Left = new BinaryRelation()
                {
                    Left = new Term(),
                    Right = new Term()
                },
                Operator = BinaryOperators.Equality,
                Right = new UnaryRelation()
                {
                    Expression = new Term()
                }
            };

            var flat = Helper.GetFlatTree(ast);
            Assert.AreEqual(6, flat.Count);
        }
Esempio n. 24
0
        public DomainConstraint TransformConstraint()
        {
            DomainConstraint    metricDomainConstraint = null;
            QualitativeRelation requiredRelation       = this.allowedRelations[0] as QualitativeRelation;

            // The metric relations that might be needed
            BinaryRelation lessThanRelation    = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.LessThan);
            BinaryRelation greaterThanRelation = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.GreaterThan);
            BinaryRelation equalsRelation      = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.Equals);

            switch (requiredRelation.Name)
            {
            case PointsAlgebraRelationNames.After:
                // A After B	 |  A.Attr > B.Attr
                metricDomainConstraint = new DomainConstraint(this.Name, greaterThanRelation, this.CanBeViolated);
                break;

            case PointsAlgebraRelationNames.Before:
                // A Before B	 |  A.Attr < B.Attr
                metricDomainConstraint = new DomainConstraint(this.Name, lessThanRelation, this.CanBeViolated);
                break;

            case PointsAlgebraRelationNames.Equals:
                // A Equals B	 |  A.Attr = B.Attr
                metricDomainConstraint = new DomainConstraint(this.Name, equalsRelation, this.CanBeViolated);
                break;
            }

            // Setting the relation parts
            if (metricDomainConstraint != null)
            {
                AttributeDomainRelationPart attrComp1Part = this.GenerateRelationPart(this.DomainRelationParts[0], this.Comp1Attribute);
                AttributeDomainRelationPart attrComp2Part = this.GenerateRelationPart(this.DomainRelationParts[1], this.Comp2Attribute);

                metricDomainConstraint.DomainRelationParts = new List <IDomainRelationPart>()
                {
                    attrComp1Part, attrComp2Part
                };
            }

            return(metricDomainConstraint);
        }
Esempio n. 25
0
        /// <summary>
        /// Cretes a new domain constraint which requires a relation to hold between the matched components.
        /// </summary>
        /// <param name="name">The unique name of the domain constraint.</param>
        /// <param name="requiredRelation">The relation between the matched components.</param>
        /// <param name="canBeViolated">Set to true for soft constraint, false for hard constraint</param>
        public DomainConstraint(string name, BinaryRelation requiredRelation, bool canBeViolated)
        {
            this.DomainRelationParts = new List <IDomainRelationPart>();
            this.allowedRelations    = new List <BinaryRelation>();

            if (requiredRelation == null)
            {
                throw new ArgumentNullException("The required relation must be set!");
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("The name of the domain constraint is required!");
            }
            else
            {
                this.allowedRelations.Add(requiredRelation);
                this.Name          = name;
                this.CanBeViolated = canBeViolated;
            }
        }
Esempio n. 26
0
    public static Domain roverWorldDomainSecondLevel()
    {
        Domain domain = roverWorldDomainFirstLevel();

        EntityType entityTypeWayPoint = domain.getEntityType("WAYPOINT");

        BinaryPredicate predicateObstacleBetween = new BinaryPredicate(entityTypeWayPoint, "OBSTACLE_BETWEEN", entityTypeWayPoint);

        domain.addPredicate(predicateObstacleBetween);

        Entity fromWayPoint = new Entity(entityTypeWayPoint, "WAYPOINT1");
        Entity toWayPoint   = new Entity(entityTypeWayPoint, "WAYPOINT2");

        BinaryRelation relationNotObstacleBetween = new BinaryRelation(fromWayPoint, predicateObstacleBetween, toWayPoint, RelationValue.FALSE);

        Action moveAction = domain.getAction("MOVE");

        moveAction.PreConditions.Add(relationNotObstacleBetween);

        return(domain);
    }
Esempio n. 27
0
    public void GetActionReturnsCorrectAction()
    {
        Domain domain = new Domain();

        EntityType sourceEntityType1      = new EntityType("CHARACTER");
        EntityType destinationEntityType1 = new EntityType("ARTIFACT");

        domain.addEntityType(sourceEntityType1);
        domain.addEntityType(destinationEntityType1);

        Entity sourceEntity1      = new Entity(sourceEntityType1, "JOHN");
        Entity destinationEntity1 = new Entity(destinationEntityType1, "APPLE");

        BinaryPredicate bp1 = new BinaryPredicate(sourceEntityType1, "PICK_UP", destinationEntityType1);

        domain.addPredicate(bp1);

        BinaryRelation br1 = new BinaryRelation(sourceEntity1, bp1, destinationEntity1, RelationValue.TRUE);

        HashSet <ActionParameter> parametersAction1 = new HashSet <ActionParameter>();

        parametersAction1.Add(new ActionParameter(sourceEntity1, ActionParameterRole.ACTIVE));
        parametersAction1.Add(new ActionParameter(destinationEntity1, ActionParameterRole.PASSIVE));

        HashSet <IRelation> preconditionsAction1 = new HashSet <IRelation>();

        preconditionsAction1.Add(br1);
        HashSet <IRelation> postconditionsAction1 = new HashSet <IRelation>();

        postconditionsAction1.Add(br1);

        Action action = new Action(preconditionsAction1, "PICK_UP", parametersAction1, postconditionsAction1);

        domain.addAction(action);

        object getAction = domain.getAction("PICK_UP");

        Assert.AreEqual(action, getAction);
    }
Esempio n. 28
0
    public bool Equals(IRelation x, IRelation y)
    {
        if (y == null && x == null)
        {
            return(true);
        }
        else if (x == null | y == null)
        {
            return(false);
        }

        if (x.GetType() != y.GetType())
        {
            return(false);
        }

        if (x.Source.Equals(y.Source) == false)
        {
            return(false);
        }

        if (x.Predicate.Equals(y.Predicate) == false)
        {
            return(false);
        }

        if (x.GetType() == typeof(BinaryRelation) &&
            y.GetType() == typeof(BinaryRelation))
        {
            BinaryRelation binaryRelationx = x as BinaryRelation;
            BinaryRelation binaryRelationy = y as BinaryRelation;
            if (binaryRelationx.Destination.Equals(binaryRelationy.Destination) == false)
            {
                return(false);
            }
        }

        return(true);
    }
Esempio n. 29
0
    public void BinaryRelationsAreNotEqualIfDestinationsAreNotEqual()
    {
        EntityType sourceEntityType1 = new EntityType("CHARACTER");
        EntityType sourceEntityType2 = new EntityType("CHARACTER");

        EntityType destinationEntityType1 = new EntityType("ARTIFACT");
        EntityType destinationEntityType2 = new EntityType("ARTIFACT");

        Entity sourceEntity1 = new Entity(sourceEntityType1, "JOHN");
        Entity sourceEntity2 = new Entity(sourceEntityType2, "JOHN");

        Entity destinationEntity1 = new Entity(destinationEntityType1, "APPLE");
        Entity destinationEntity2 = new Entity(destinationEntityType2, "APPLE2");

        BinaryPredicate bp1 = new BinaryPredicate(sourceEntityType1, "PICK_UP", destinationEntityType1);
        BinaryPredicate bp2 = new BinaryPredicate(sourceEntityType2, "PICK_UP", destinationEntityType2);

        BinaryRelation br1 = new BinaryRelation(sourceEntity1, bp1, destinationEntity1, RelationValue.TRUE);
        BinaryRelation br2 = new BinaryRelation(sourceEntity2, bp2, destinationEntity2, RelationValue.TRUE);

        Assert.False(br1.Equals(br2) || br1.GetHashCode() == br2.GetHashCode());
    }
Esempio n. 30
0
    public void getPossibleActionsReturnsTakeSampleActionIfCanTakeSample()
    {
        Domain domain = Utils.roverWorldDomainFirstLevel();

        WorldState worldState = new WorldState(domain);

        Entity entityRover = new Entity(new EntityType("ROVER"), "ROVER");

        worldState.addEntity(entityRover);

        Entity entityWaypoint = new Entity(new EntityType("WAYPOINT"), "WAYPOINT");

        worldState.addEntity(entityWaypoint);

        Entity entitySample = new Entity(new EntityType("SAMPLE"), "SAMPLE");

        worldState.addEntity(entitySample);

        BinaryRelation sampleIsInWaypoint = domain.generateRelationFromPredicateName("IS_IN", entitySample, entityWaypoint, RelationValue.TRUE);
        BinaryRelation roverIsAtWaypoint  = domain.generateRelationFromPredicateName("AT", entityRover, entityWaypoint, RelationValue.TRUE);
        UnaryRelation  roverIsEmpty       = domain.generateRelationFromPredicateName("IS_EMPTY", entityRover, RelationValue.TRUE);

        worldState.addRelation(sampleIsInWaypoint);
        worldState.addRelation(roverIsAtWaypoint);
        worldState.addRelation(roverIsEmpty);

        Action actionTakeSample = worldState.Domain.getAction("TAKE_SAMPLE");
        Action actionIdle       = worldState.Domain.getAction("IDLE");

        HashSet <Action> performableActions = new HashSet <Action>();

        performableActions.Add(actionTakeSample);
        performableActions.Add(actionIdle);

        CollectionAssert.AreEquivalent(performableActions, worldState.getPossibleActions());
    }
Esempio n. 31
0
    public void getPossibleActionsReturnsDropSampleActionIfCanDropSample()
    {
        Domain domain = Utils.roverWorldDomainFirstLevel();

        WorldState worldState = new WorldState(domain);

        Entity entityRover = new Entity(new EntityType("ROVER"), "ROVER");

        worldState.addEntity(entityRover);

        Entity entityWaypoint = new Entity(new EntityType("WAYPOINT"), "WAYPOINT");

        worldState.addEntity(entityWaypoint);

        Entity entitySample = new Entity(new EntityType("SAMPLE"), "SAMPLE");

        worldState.addEntity(entitySample);

        UnaryRelation  wayPointIsDroppingDock = domain.generateRelationFromPredicateName("IS_DROPPING_DOCK", entityWaypoint, RelationValue.TRUE);
        BinaryRelation roverIsAtWaypoint      = domain.generateRelationFromPredicateName("AT", entityRover, entityWaypoint, RelationValue.TRUE);
        BinaryRelation roverCarriesSample     = domain.generateRelationFromPredicateName("CARRY", entityRover, entitySample, RelationValue.TRUE);

        worldState.addRelation(wayPointIsDroppingDock);
        worldState.addRelation(roverIsAtWaypoint);
        worldState.addRelation(roverCarriesSample);

        Action actionDropSample = worldState.Domain.getAction("DROP_SAMPLE");
        Action actionIdle       = worldState.Domain.getAction("IDLE");

        HashSet <Action> performableActions = new HashSet <Action>();

        performableActions.Add(actionDropSample);
        performableActions.Add(actionIdle);

        CollectionAssert.AreEquivalent(performableActions, worldState.getPossibleActions());
    }
        public void UnaryRelationAndBinaryRelationNestingOrder()
        {
            const string str = "(\"\") != (NotExist g::zVBLdNY = m::3U1Fe)";

            var ast = new BinaryRelation()
            {
                ExpressionType = ExpressionTypes.BinaryRelation,
                Left = new Term()
                {
                    ExpressionType = ExpressionTypes.String,
                    Value = string.Empty
                },
                Operator = BinaryOperators.Inequality,
                Right = new BinaryRelation()
                {
                    ExpressionType = ExpressionTypes.BinaryRelation,
                    Left = new UnaryRelation()
                    {
                        ExpressionType = ExpressionTypes.UnaryRelation,
                        Operator = UnaryOperators.NotExist,
                        Expression = new Term()
                        {
                            ExpressionType = ExpressionTypes.SystemObject,
                            ObjectType = "g",
                            Value = "zVBLdNY"
                        }
                    },
                    Operator = BinaryOperators.Equality,
                    Right = new Term()
                    {
                        ExpressionType = ExpressionTypes.SystemObject,
                        ObjectType = "m",
                        Value = "3U1Fe"
                    }
                }
            };

            var parsed = LanguageGrammar.ParseExpression.Parse(str);
            Assert.AreEqual(ast, parsed);
        }