public void AddPostconditionChangesThePostconditionsOfTheAction() { Domain domain = Utils.roverWorldDomainThirdLevel(); Action moveAction = domain.getAction("MOVE"); HashSet <IRelation> expectedPostconditions = new HashSet <IRelation>(); foreach (IRelation r in moveAction.PostConditions) { expectedPostconditions.Add(r.Clone()); } EntityType entityTypeBattery = new EntityType("BATTERY"); EntityType entityTypeWheel = new EntityType("WHEEL"); UnaryPredicate predicateBatteryCharged = new UnaryPredicate(entityTypeBattery, "BATTERY_CHARGED"); UnaryPredicate predicateWheelsInflated = new UnaryPredicate(entityTypeWheel, "WHEELS_INFLATED"); UnaryRelation relationBatteryCharged = new UnaryRelation(new Entity(entityTypeBattery, "BATTERY"), predicateBatteryCharged, RelationValue.TRUE); UnaryRelation relationWheelsInflated = new UnaryRelation(new Entity(entityTypeWheel, "WHEELS"), predicateWheelsInflated, RelationValue.TRUE); expectedPostconditions.Add(relationBatteryCharged); expectedPostconditions.Add(relationWheelsInflated); moveAction.addPostcondition(relationBatteryCharged); moveAction.addPostcondition(relationWheelsInflated); Assert.AreEqual(moveAction.PostConditions, expectedPostconditions); }
public void CloneReturnsEqualUnaryPredicate() { UnaryPredicate up1 = new UnaryPredicate(new EntityType("CHARACTER"), "IS_RICH"); UnaryPredicate up2 = up1.Clone() as UnaryPredicate; Assert.AreEqual(up1, up2); }
public void AddParameterChangesTheParametersOfTheAction() { Domain domain = Utils.roverWorldDomainFirstLevel(); Action moveAction = domain.getAction("MOVE"); HashSet <Entity> expectedParameters = new HashSet <Entity>(); foreach (Entity e in moveAction.Parameters) { expectedParameters.Add(e.Clone()); } EntityType entityTypeBattery = new EntityType("BATTERY"); EntityType entityTypeWheel = new EntityType("WHEEL"); UnaryPredicate predicateBatteryCharged = new UnaryPredicate(entityTypeBattery, "BATTERY_CHARGED"); UnaryPredicate predicateWheelsInflated = new UnaryPredicate(entityTypeWheel, "WHEELS_INFLATED"); Entity entityBattery = new Entity(entityTypeBattery, "BATTERY"); Entity entityWheels = new Entity(entityTypeWheel, "WHEELS"); expectedParameters.Add(entityBattery); expectedParameters.Add(entityWheels); moveAction.addParameter(new ActionParameter(entityBattery, ActionParameterRole.PASSIVE)); moveAction.addParameter(new ActionParameter(entityWheels, ActionParameterRole.PASSIVE)); Assert.AreEqual(moveAction.Parameters, expectedParameters); }
protected override void DoProcess(SQLProcessorAggregator aggregator, UnaryPredicate <ValueExpression> obj, StringBuilder builder, Boolean negationActive) { var op = negationActive ? this._negatedOperator : this._operator; if (UnaryOperatorOrientation.BeforeExpression == this._orientation) { builder.Append(op).Append(SQLConstants.TOKEN_SEPARATOR); } var exp = obj.Expression; var isQuery = exp is QueryExpression; if (isQuery) { builder.Append(SQLConstants.OPEN_PARENTHESIS); } aggregator.Process(exp, builder); if (isQuery) { builder.Append(SQLConstants.CLOSE_PARENTHESIS); } if (UnaryOperatorOrientation.AfterExpression == this._orientation) { builder.Append(SQLConstants.TOKEN_SEPARATOR).Append(op); } }
public static UnaryPredicate <Arg> Not1Pred <Arg>(UnaryPredicate <Arg> func) { return(delegate(Arg arg) { return !func(arg); }); }
public void UnaryPredicatesAreEqualIfAllAttributesAreEqual() { EntityType character = new EntityType("CHARACTER"); UnaryPredicate up1 = new UnaryPredicate(character, "IS_RICH"); UnaryPredicate up2 = new UnaryPredicate(character, "IS_RICH"); Assert.True(up1.Equals(up2) && up1.GetHashCode() == up2.GetHashCode()); }
public void UnaryPredicatesAreNotEqualIfNameIsNotEqual() { EntityType character = new EntityType("CHARACTER"); UnaryPredicate up1 = new UnaryPredicate(character, "IS_RICH"); UnaryPredicate up2 = new UnaryPredicate(character, "IS_RICH2"); Assert.False(up1.Equals(up2)); }
public void CloneReturnsEqualUnaryRelation() { EntityType entityTyperRover = new EntityType("ROVER"); Entity entityRover = new Entity(entityTyperRover, "ROVER"); UnaryPredicate predicateRoverisEmpty = new UnaryPredicate(entityTyperRover, "IS_EMPTY"); UnaryRelation relationRoverIsEmpty = new UnaryRelation(entityRover, predicateRoverisEmpty, RelationValue.TRUE); UnaryRelation relationClonedRoverIsEmpty = relationRoverIsEmpty.Clone() as UnaryRelation; Assert.AreEqual(relationRoverIsEmpty, relationClonedRoverIsEmpty); }
public void UnaryPredicateCanOnlyBeOfExistingType() { Domain domain = new Domain(); EntityType character = new EntityType("CHARACTER"); // domain.addEntityType(character); UnaryPredicate up = new UnaryPredicate(character, "RICH"); Assert.That(() => domain.addPredicate(up), Throws.ArgumentException); }
public static int FindIf(int [] arr, int first, int last, UnaryPredicate op) { for (; first != last; ++first) { if (op(arr[first])) { return(first); } } return(-1); }
public void equalsReturnsFalseIfPredicatesAreNotEqual() { Domain domain = Utils.roverWorldDomainThirdLevel(); Domain domain2 = Utils.roverWorldDomainThirdLevel(); UnaryPredicate predicateDifference = new UnaryPredicate(new EntityType("ROVER"), "DIFFERENT_PREDICATE"); domain2.addPredicate(predicateDifference); Assert.AreNotEqual(domain, domain2); }
public override bool Equals(object obj) { if (obj is UnaryPredicate) { UnaryPredicate that = obj as UnaryPredicate; return(this.Letter == that.Letter); } throw new EngineException("UnaryPredicate compared to non-UnaryPredicate."); }
public void UnaryRelationSourceMustBeOfCorrectPredicateType() { EntityType character = new EntityType("CHARACTER"); Entity john = new Entity(character, "JOHN"); EntityType location = new EntityType("LOCATION"); Entity school = new Entity(location, "SCHOOL"); UnaryPredicate isRich = new UnaryPredicate(character, "RICH"); Assert.That(() => new UnaryRelation(school, isRich, RelationValue.TRUE), Throws.ArgumentException); }
public static int FindCounerIf(int[] arr, int first, int last, UnaryPredicate op) { int counter = 0; for (; first != last; ++first) { if (op(arr[first])) { ++counter; } } return(counter); }
public void IsPartitionedTest3() { int[] data = { 2, 7, 4, 6 }; UnaryPredicate <int> isEven = delegate(int x) { return(x % 2 == 0); }; using (IInputIterator <int> inputIterator = new InputIterator <int>(data)) { Assert.IsFalse(Algorithm.IsPartitioned(inputIterator, isEven)); } }
public void UnaryPredicateMustBeUnique() { Domain domain = new Domain(); EntityType character = new EntityType("CHARACTER"); domain.addEntityType(character); UnaryPredicate up = new UnaryPredicate(character, "RICH"); domain.addPredicate(up); UnaryPredicate up2 = new UnaryPredicate(character, "RICH"); Assert.That(() => domain.addPredicate(up2), Throws.ArgumentException); }
public void UnaryRelationsAreNotEqualIfNameIsNotEqual() { EntityType entityType1 = new EntityType("CHARACTER"); EntityType entityType2 = new EntityType("CHARACTER"); Entity entity1 = new Entity(entityType1, "JOHN"); Entity entity2 = new Entity(entityType2, "JOHN2"); UnaryPredicate up1 = new UnaryPredicate(entityType1, "IS_RICH"); UnaryPredicate up2 = new UnaryPredicate(entityType2, "IS_RICH"); UnaryRelation ur1 = new UnaryRelation(entity1, up1, RelationValue.TRUE); UnaryRelation ur2 = new UnaryRelation(entity2, up2, RelationValue.TRUE); Assert.False(ur1.Equals(ur2) || ur1.GetHashCode() == ur2.GetHashCode()); }
public void UnaryRelationsAreEqualIfAllAttributesAreEqual() { EntityType entityType1 = new EntityType("CHARACTER"); EntityType entityType2 = new EntityType("CHARACTER"); Entity entity1 = new Entity(entityType1, "JOHN"); Entity entity2 = new Entity(entityType2, "JOHN"); UnaryPredicate up1 = new UnaryPredicate(entityType1, "IS_RICH"); UnaryPredicate up2 = new UnaryPredicate(entityType2, "IS_RICH"); UnaryRelation ur1 = new UnaryRelation(entity1, up1, RelationValue.TRUE); UnaryRelation ur2 = new UnaryRelation(entity2, up2, RelationValue.TRUE); Assert.True(ur1.Equals(ur2) && ur1.GetHashCode() == ur2.GetHashCode()); }
public void UnaryRelationPredicateMustBeAnExistingPredicate() { Domain domain = new Domain(); EntityType character = new EntityType("CHARACTER"); domain.addEntityType(character); UnaryPredicate rich = new UnaryPredicate(character, "RICH"); // domain.addPredicate(rich); WorldState worldState = new WorldState(domain); Entity john = new Entity(character, "JOHN"); worldState.addEntity(john); UnaryRelation johnIsRich = new UnaryRelation(john, rich, RelationValue.TRUE); Assert.That(() => worldState.addRelation(johnIsRich), Throws.ArgumentException); }
public void PartitionTest() { int[] data = { 0, 1, 2, 3 }; UnaryPredicate <int> isEven = delegate(int x) { return(x % 2 == 0); }; using (ForwardIterator <int> inputIterator = new ForwardIterator <int>(data)) { Algorithm.Partition(inputIterator, isEven); bool isCorrectData = (inputIterator[0] == 0 && inputIterator[1] == 2 && inputIterator[2] == 1 && inputIterator[3] == 3); Assert.IsTrue(isCorrectData); } }
public void PartitionCopyTest() { int[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; IList <int> trueList = new List <int>(); IList <int> falseList = new List <int>(); UnaryPredicate <int> isEven = delegate(int x) { return(x % 2 == 0); }; using (ForwardIterator <int> inputIterator = new ForwardIterator <int>(data)) { using (IOutputIterator <int> trueOutputIterator = new BackInsertIterator <int>(trueList)) { using (IOutputIterator <int> falseOutputIterator = new BackInsertIterator <int>(falseList)) { Algorithm.PartitionCopy(inputIterator, trueOutputIterator, falseOutputIterator, isEven); bool isEvenCorrect = (trueList[0] == 0 && trueList[1] == 2 && trueList[2] == 4 && trueList[3] == 6 && trueList[4] == 8); bool isOddCorrect = (falseList[0] == 1 && falseList[1] == 3 && falseList[2] == 5 && falseList[3] == 7 && falseList[4] == 9); Assert.IsTrue(isEvenCorrect && isOddCorrect); } } } }
public static Domain roverWorldDomainFirstLevel() { Domain domain = new Domain(); EntityType rover = new EntityType("ROVER"); domain.addEntityType(rover); EntityType wayPoint = new EntityType("WAYPOINT"); domain.addEntityType(wayPoint); EntityType sample = new EntityType("SAMPLE"); domain.addEntityType(sample); EntityType objective = new EntityType("OBJECTIVE"); domain.addEntityType(objective); //(can-move ?from-waypoint ?to-waypoint) BinaryPredicate isConnectedTo = new BinaryPredicate(wayPoint, "IS_CONNECTED_TO", wayPoint, "is connected to"); domain.addPredicate(isConnectedTo); //(is-visible ?objective ?waypoint) BinaryPredicate isVisible = new BinaryPredicate(objective, "IS_VISIBLE", wayPoint, "is visible"); domain.addPredicate(isVisible); //(is-in ?sample ?waypoint) BinaryPredicate isIn = new BinaryPredicate(sample, "IS_IN", wayPoint, "is in"); domain.addPredicate(isIn); //(been-at ?rover ?waypoint) BinaryPredicate beenAt = new BinaryPredicate(rover, "BEEN_AT", wayPoint, "has been at"); domain.addPredicate(beenAt); //(carry ?rover ?sample) BinaryPredicate carry = new BinaryPredicate(rover, "CARRY", sample, "is carrying"); domain.addPredicate(carry); //(at ?rover ?waypoint) BinaryPredicate at = new BinaryPredicate(rover, "AT", wayPoint, "is at"); domain.addPredicate(at); //(is-dropping-dock ?waypoint) UnaryPredicate isDroppingDock = new UnaryPredicate(wayPoint, "IS_DROPPING_DOCK", "is dropping the dock"); domain.addPredicate(isDroppingDock); //(taken-image ?objective) UnaryPredicate takenImage = new UnaryPredicate(objective, "TAKEN_IMAGE", "is taking an image"); domain.addPredicate(takenImage); //(stored-sample ?sample) UnaryPredicate storedSample = new UnaryPredicate(sample, "STORED_SAMPLE", "has stored the sample"); domain.addPredicate(storedSample); //(empty ?rover) UnaryPredicate isEmpty = new UnaryPredicate(rover, "IS_EMPTY", "is empty"); domain.addPredicate(isEmpty); Entity curiosity = new Entity(rover, "ROVER"); // IDLE ACTION Action actionIdle = new Action(new HashSet <IRelation>(), "IDLE", new HashSet <ActionParameter>() { new ActionParameter(curiosity, ActionParameterRole.ACTIVE) }, new HashSet <IRelation>()); domain.addAction(actionIdle); // MOVE ACTION // Parameters 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); domain.addAction(moveAction); // TAKE SAMPLE ACTION // Parameters Entity ESample = new Entity(sample, "SAMPLE"); Entity EWayPoint = new Entity(wayPoint, "WAYPOINT"); HashSet <ActionParameter> takeSampleActionParameters = new HashSet <ActionParameter>(); takeSampleActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE)); takeSampleActionParameters.Add(new ActionParameter(ESample, ActionParameterRole.PASSIVE)); takeSampleActionParameters.Add(new ActionParameter(EWayPoint, ActionParameterRole.PASSIVE)); // Preconditions HashSet <IRelation> takeSampleActPreconditions = new HashSet <IRelation>(); BinaryRelation sampleIsInWayPoint = new BinaryRelation(ESample, isIn, EWayPoint, RelationValue.TRUE); takeSampleActPreconditions.Add(sampleIsInWayPoint); BinaryRelation roverIsAtWayPoint = new BinaryRelation(curiosity, at, EWayPoint, RelationValue.TRUE); takeSampleActPreconditions.Add(roverIsAtWayPoint); UnaryRelation roverIsEmpty = new UnaryRelation(curiosity, isEmpty, RelationValue.TRUE); takeSampleActPreconditions.Add(roverIsEmpty); // Postconditions HashSet <IRelation> takeSampleActPostconditions = new HashSet <IRelation>(); BinaryRelation sampleIsNotInWayPoint = new BinaryRelation(ESample, isIn, EWayPoint, RelationValue.FALSE); takeSampleActPostconditions.Add(sampleIsNotInWayPoint); UnaryRelation roverIsNotEmpty = new UnaryRelation(curiosity, isEmpty, RelationValue.FALSE); takeSampleActPostconditions.Add(roverIsNotEmpty); BinaryRelation roverCarriesSample = new BinaryRelation(curiosity, carry, ESample, RelationValue.TRUE); takeSampleActPostconditions.Add(roverCarriesSample); Action takeSampleAction = new Action(takeSampleActPreconditions, "TAKE_SAMPLE", takeSampleActionParameters, takeSampleActPostconditions); domain.addAction(takeSampleAction); // DROP SAMPLE ACTION // Parameters HashSet <ActionParameter> dropSampleActionParameters = new HashSet <ActionParameter>(); dropSampleActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE)); dropSampleActionParameters.Add(new ActionParameter(ESample, ActionParameterRole.PASSIVE)); dropSampleActionParameters.Add(new ActionParameter(EWayPoint, ActionParameterRole.PASSIVE)); // Preconditions HashSet <IRelation> dropSampleActPreconditions = new HashSet <IRelation>(); UnaryRelation wayPointIsDroppingDock = new UnaryRelation(EWayPoint, isDroppingDock, RelationValue.TRUE); dropSampleActPreconditions.Add(wayPointIsDroppingDock); dropSampleActPreconditions.Add(roverIsAtWayPoint); dropSampleActPreconditions.Add(roverCarriesSample); // Postconditions HashSet <IRelation> dropSampActPostconditions = new HashSet <IRelation>(); dropSampActPostconditions.Add(sampleIsInWayPoint); dropSampActPostconditions.Add(roverIsEmpty); BinaryRelation notRoverCarriesSample = new BinaryRelation(curiosity, carry, ESample, RelationValue.FALSE); dropSampActPostconditions.Add(notRoverCarriesSample); Action dropSampleAction = new Action(dropSampleActPreconditions, "DROP_SAMPLE", dropSampleActionParameters, dropSampActPostconditions); domain.addAction(dropSampleAction); // TAKE IMAGE ACTION // Parameters Entity EObjective = new Entity(objective, "OBJECTIVE"); HashSet <ActionParameter> takeImageActionParameters = new HashSet <ActionParameter>(); takeImageActionParameters.Add(new ActionParameter(curiosity, ActionParameterRole.ACTIVE)); takeImageActionParameters.Add(new ActionParameter(EObjective, ActionParameterRole.PASSIVE)); takeImageActionParameters.Add(new ActionParameter(EWayPoint, ActionParameterRole.PASSIVE)); // Preconditions HashSet <IRelation> takeImageActionPreconditions = new HashSet <IRelation>(); takeImageActionPreconditions.Add(roverIsAtWayPoint); BinaryRelation objectiveIsVisibleFromWayPoint = new BinaryRelation(EObjective, isVisible, EWayPoint, RelationValue.TRUE); takeImageActionPreconditions.Add(objectiveIsVisibleFromWayPoint); // Postconditions HashSet <IRelation> takeImageActionPostconditions = new HashSet <IRelation>(); UnaryRelation roverHasTakenImageOfObjective = new UnaryRelation(EObjective, takenImage, RelationValue.TRUE); takeImageActionPostconditions.Add(roverHasTakenImageOfObjective); Action takeImageAction = new Action(takeImageActionPreconditions, "TAKE_IMAGE", takeImageActionParameters, takeImageActionPostconditions); domain.addAction(takeImageAction); return(domain); }
public static Domain roverWorldDomainThirdLevel() { Domain domain = roverWorldDomainSecondLevel(); EntityType entityTypeBattery = new EntityType("BATTERY"); domain.addEntityType(entityTypeBattery); EntityType entityTypeWheel = new EntityType("WHEEL"); domain.addEntityType(entityTypeWheel); UnaryPredicate predicateBatteryCharged = new UnaryPredicate(entityTypeBattery, "BATTERY_CHARGED"); domain.addPredicate(predicateBatteryCharged); UnaryPredicate predicateWheelsInflated = new UnaryPredicate(entityTypeWheel, "WHEELS_INFLATED"); domain.addPredicate(predicateWheelsInflated); EntityType entityTypeRover = domain.getEntityType("ROVER"); BinaryPredicate predicateHasBattery = new BinaryPredicate(entityTypeRover, "HAS", entityTypeBattery); domain.addPredicate(predicateHasBattery); BinaryPredicate predicateHasWheels = new BinaryPredicate(entityTypeRover, "HAS", entityTypeWheel); domain.addPredicate(predicateHasWheels); HashSet <ActionParameter> actionChargeParameters = new HashSet <ActionParameter>(); Entity entityRover = new Entity(entityTypeRover, "ROVER"); Entity entityBattery = new Entity(entityTypeBattery, "BATTERY"); actionChargeParameters.Add(new ActionParameter(entityRover, ActionParameterRole.ACTIVE)); actionChargeParameters.Add(new ActionParameter(entityBattery, ActionParameterRole.PASSIVE)); HashSet <IRelation> actionChargePreconditions = new HashSet <IRelation>(); BinaryRelation relationRoverHasBattery = new BinaryRelation(entityRover, predicateHasBattery, entityBattery, RelationValue.TRUE); actionChargePreconditions.Add(relationRoverHasBattery); UnaryRelation relationBatteryDischarged = new UnaryRelation(entityBattery, predicateBatteryCharged, RelationValue.FALSE); actionChargePreconditions.Add(relationBatteryDischarged); HashSet <IRelation> actionChargePostconditions = new HashSet <IRelation>(); UnaryRelation relationBatteryCharged = new UnaryRelation(entityBattery, predicateBatteryCharged, RelationValue.TRUE); actionChargePostconditions.Add(relationBatteryCharged); Action actionChargeBattery = new Action(actionChargePreconditions, "CHARGE_BATTERY", actionChargeParameters, actionChargePostconditions); domain.addAction(actionChargeBattery); HashSet <IRelation> actionDischargePreconditions = new HashSet <IRelation>(); actionDischargePreconditions.Add(relationRoverHasBattery); actionDischargePreconditions.Add(relationBatteryCharged); HashSet <IRelation> actionDischargePostconditions = new HashSet <IRelation>(); actionDischargePostconditions.Add(relationBatteryDischarged); Action actionDischargeBattery = new Action(actionDischargePreconditions, "DISCHARGE_BATTERY", actionChargeParameters, actionDischargePostconditions); domain.addAction(actionDischargeBattery); HashSet <ActionParameter> actionInflateParameters = new HashSet <ActionParameter>(); Entity entityWheels = new Entity(entityTypeWheel, "WHEELS"); actionInflateParameters.Add(new ActionParameter(entityRover, ActionParameterRole.ACTIVE)); actionInflateParameters.Add(new ActionParameter(entityWheels, ActionParameterRole.PASSIVE)); HashSet <IRelation> actionInflatePreconditions = new HashSet <IRelation>(); BinaryRelation relationRoverHasWheels = new BinaryRelation(entityRover, predicateHasWheels, entityWheels, RelationValue.TRUE); actionInflatePreconditions.Add(relationRoverHasWheels); UnaryRelation relationWheelsDeflated = new UnaryRelation(entityWheels, predicateWheelsInflated, RelationValue.FALSE); actionInflatePreconditions.Add(relationWheelsDeflated); HashSet <IRelation> actionInflatePostconditions = new HashSet <IRelation>(); UnaryRelation relationWheelsInflated = new UnaryRelation(entityWheels, predicateWheelsInflated, RelationValue.TRUE); actionInflatePostconditions.Add(relationWheelsInflated); Action actionInflate = new Action(actionInflatePreconditions, "INFLATE_WHEELS", actionInflateParameters, actionInflatePostconditions); domain.addAction(actionInflate); HashSet <IRelation> actionDeflatePreconditions = new HashSet <IRelation>(); actionDeflatePreconditions.Add(relationRoverHasWheels); actionDeflatePreconditions.Add(relationWheelsInflated); HashSet <IRelation> actionDeflatePostconditions = new HashSet <IRelation>(); actionDeflatePostconditions.Add(relationWheelsDeflated); Action actionDeflate = new Action(actionDeflatePreconditions, "DEFLATE_WHEELS", actionInflateParameters, actionDeflatePostconditions); domain.addAction(actionDeflate); Action moveAction = domain.getAction("MOVE"); ActionParameter actionParameterBattery = new ActionParameter(entityBattery, ActionParameterRole.PASSIVE); ActionParameter actionParameterWheels = new ActionParameter(entityWheels, ActionParameterRole.PASSIVE); moveAction.addParameter(actionParameterBattery); moveAction.addParameter(actionParameterWheels); moveAction.addPrecondition(relationRoverHasBattery); moveAction.addPrecondition(relationRoverHasWheels); moveAction.addPrecondition(relationBatteryCharged); moveAction.addPrecondition(relationWheelsInflated); Action takeSampleAction = domain.getAction("TAKE_SAMPLE"); takeSampleAction.addParameter(actionParameterBattery); takeSampleAction.addPrecondition(relationRoverHasBattery); takeSampleAction.addPrecondition(relationBatteryCharged); Action dropSampleAction = domain.getAction("DROP_SAMPLE"); dropSampleAction.addParameter(actionParameterBattery); dropSampleAction.addPrecondition(relationRoverHasBattery); dropSampleAction.addPrecondition(relationBatteryCharged); Action takeImageAction = domain.getAction("TAKE_IMAGE"); takeImageAction.addParameter(actionParameterBattery); takeImageAction.addPrecondition(relationRoverHasBattery); takeImageAction.addPrecondition(relationBatteryCharged); return(domain); }
internal Term(UnaryPredicate aPredicate, bool aIsNegative) { mIsNegative = aIsNegative; mPredicate = aPredicate; }
public ISinglePredicateState IsNotNull() { var predicate = new UnaryPredicate(_expression, UnaryOperationType.IsNull); return(InitialPredicateState(predicate, _negate)); }
public void DescribeWorldState() { Text myText = GameObject.Find("Content").GetComponent <Text>(); Text title = GameObject.Find("Title").GetComponent <Text>(); GameObject mars = GameObject.Find("Mars Simulation").gameObject.transform.GetChild(0).gameObject; GameObject venus = GameObject.Find("Venus Simulation").gameObject.transform.GetChild(0).gameObject; Simulation marsSimulation = mars.GetComponent <Simulation>(); Simulation venusSimulation = venus.GetComponent <Simulation>(); int marsLoD = marsSimulation.CurrentLevelOfDetail; int venusLoD = venusSimulation.CurrentLevelOfDetail; if (marsLoD != 1) { title.text = "Mars"; levelOfDetail = marsLoD; } else if (venusLoD != 1) { title.text = "Venus"; levelOfDetail = venusLoD; } print("Level Of Detail: " + levelOfDetail); switch (levelOfDetail) { case (0): //print("Rover is NOT inside a LOD"); //title.text = "Space"; //myText.text += "Not enogh close to a planet to recieve information."; foreach (IRelation r in marsSimulation.CurrentNode.Data.Relations) { if (r.GetType() == typeof(BinaryRelation)) { BinaryRelation rel = r as BinaryRelation; BinaryPredicate pred = r.Predicate as BinaryPredicate; myText.text += "BinaryRelation: " + rel.Source.Name + " " + pred.Description + " " + rel.Destination.Name + "\n"; } else { UnaryRelation rel = r as UnaryRelation; UnaryPredicate pred = r.Predicate as UnaryPredicate; myText.text += "UnaryRelation: " + rel.Source.Name + " " + pred.Description + "\n"; } //myText.text += r.ToString() + "\n"; } break; case (1): foreach (IRelation r in marsSimulation.CurrentNode.Data.Relations) { if (r.GetType() == typeof(BinaryRelation)) { BinaryRelation rel = r as BinaryRelation; BinaryPredicate pred = r.Predicate as BinaryPredicate; myText.text += "BinaryRelation: " + rel.Source.Name + " " + pred.Description + " " + rel.Destination.Name + "\n"; } else { UnaryRelation rel = r as UnaryRelation; UnaryPredicate pred = r.Predicate as UnaryPredicate; myText.text += "UnaryRelation: " + rel.Source.Name + " " + pred.Description + "\n"; } //myText.text += r.ToString() + "\n"; } break; case (2): foreach (IRelation r in marsSimulation.CurrentNode.Data.Relations) { if (r.GetType() == typeof(BinaryRelation)) { BinaryRelation rel = r as BinaryRelation; BinaryPredicate pred = r.Predicate as BinaryPredicate; myText.text += "BinaryRelation: " + rel.Source.Name + " " + pred.Description + " " + rel.Destination.Name + "\n"; } else { UnaryRelation rel = r as UnaryRelation; UnaryPredicate pred = r.Predicate as UnaryPredicate; myText.text += "UnaryRelation: " + rel.Source.Name + " " + pred.Description + "\n"; } //myText.text += r.ToString() + "\n"; } break; case (3): Domain domainThirdLevel = Utils.roverWorldDomainThirdLevel(); WorldState worldStateThirdLevel = Utils.roverWorldStateFirstLevel(domainThirdLevel); myText.text += "Third Level of Detail" + "\n\n"; foreach (IRelation r in worldStateThirdLevel.Relations) { if (r.GetType() == typeof(BinaryRelation)) { BinaryRelation rel = r as BinaryRelation; BinaryPredicate pred = r.Predicate as BinaryPredicate; myText.text += "BinaryRelation: " + rel.Source.Name + " " + pred.Description + " " + rel.Destination.Name + "\n"; } else { UnaryRelation rel = r as UnaryRelation; UnaryPredicate pred = r.Predicate as UnaryPredicate; myText.text += "UnaryRelation: " + rel.Source.Name + " " + pred.Description + "\n"; } } break; } }
public IPredicateDisjunctionState IsNotNull() { var predicate = new UnaryPredicate(Expression, UnaryOperationType.IsNotNull); return(PredicateDisjunctionState(predicate, _negate)); }
public void DescribeAction(Action act) { Text myText = GameObject.Find("Content").GetComponent <Text>(); myText.text = ""; print(act.Name); HashSet <IRelation> preconditions = act.PreConditions; HashSet <ActionParameter> parameters = act.Parameters; HashSet <IRelation> postconditions = act.PostConditions; string preText = null; string postText = null; string actionText = null; string destination = null; //PREconditions foreach (IRelation pre in preconditions) { if (pre.Value == RelationValue.TRUE) { if (pre.GetType() == typeof(BinaryRelation)) { BinaryRelation r = pre as BinaryRelation; BinaryPredicate p = pre.Predicate as BinaryPredicate; //preText += "the " + r.Source.Name + " " + p.Description + " " + r.Destination.Name + "\n"; preText += string.Format("the {0} {1} {2}\n", r.Source.Name, p.Description, r.Destination.Name); } else if (pre.GetType() == typeof(UnaryRelation)) { UnaryRelation r = pre as UnaryRelation; UnaryPredicate p = pre.Predicate as UnaryPredicate; //preText += "the " + r.Source.Name + " " + p.Description + "\n"; preText += string.Format("the {0} {1}\n", r.Source.Name, p.Description); } } } //POSTconditions foreach (IRelation post in postconditions) { if (post.Value == RelationValue.TRUE) { if (post.GetType() == typeof(BinaryRelation)) { BinaryRelation r = post as BinaryRelation; BinaryPredicate p = post.Predicate as BinaryPredicate; //postText += "the " + r.Source.Name + " " + p.Description + " " + r.Destination.Name + "\n"; postText += string.Format("the {0} {1} {2}\n", r.Source.Name, p.Description, r.Destination.Name); } else if (post.GetType() == typeof(UnaryRelation)) { UnaryRelation r = post as UnaryRelation; UnaryPredicate p = post.Predicate as UnaryPredicate; //postText += "the " + r.Source.Name + " " + p.Description + "\n"; postText += string.Format("the {0} {1}\n", r.Source.Name, p.Description); } } } // TO FIX // ////Action // //foreach (Entity param in parameters) //{ // if (param.Type.Equals(domain.getEntityType("CHARACTER"))) // { // actionText += "the " + param.Name + " decided to " + act.Name + " to " + destination + "\n"; // } //} myText.text += "Initially " + preText + "\nThen " + actionText + "\nNow " + postText; }