def test_merge(self): function_name = "one" function_one = "( = (" + function_name + ") {0} )".format(1) function_two = "( = (" + function_name + ") {0} )".format(2) one = PDDL(statement=function_one, functions=function_name, time_stamp=rospy.Time(secs=10)) two = PDDL(statement=function_two, functions=function_name, time_stamp=rospy.Time(secs=11)) merged = mergeStatePDDL(one, two) self.assertIsNotNone(merged) self.assertEquals(function_two, merged.statement) two.time_stamp = rospy.Time( secs=9) # check again with two becoming older merged = mergeStatePDDL(one, two) self.assertIsNotNone(merged) self.assertEquals(function_one, merged.statement)
def test_empty(self): """ test PDDL.empty property """ empty_pddl = PDDL() non_empty_pddl = PDDL( statement="(:action test_action\n:parameters ()\n", functions="costs") self.assertTrue(empty_pddl.empty, "Empty PDDL is not empty") self.assertFalse(non_empty_pddl.empty, "not empty PDDL is empty")
def getPreconditionPDDL(self, satisfaction_threshold): # Calling getSensorPreconditionPDDL for all sensors conditions = [self._activator.get_sensor_precondition_pddl_using_current_value(s.name, satisfaction_threshold, self._get_value_of_sensor_for_pddl_creation(s)) for s in self._sensors] # TODO this code is copy pasted from conjuction condition pddl = PDDL(statement = "(and") for cond_pddl in conditions: pddl.statement += " {0}".format(cond_pddl.statement) pddl.predicates = pddl.predicates.union(cond_pddl.predicates) pddl.functions = pddl.functions.union(cond_pddl.functions) pddl.statement += ")" return pddl
def getSensorStatePDDL(self, sensorName, normalizedValue): functionName = self.getPDDLFunctionName(sensorName) return PDDL(statement = "( = (" + functionName + ") {0:f} )".format(normalizedValue), functions = functionName)
def getSensorPreconditionPDDL(self, sensorName, satisfaction_threshold): functionName = self.getPDDLFunctionName(sensorName) satisfaction_bound = self._calculate_satisfaction_bound(satisfaction_threshold) return PDDL(statement = "( >= (" + functionName + ") {0:f} )".format(satisfaction_bound) if self.getDirection() == 1 else "( <= (" + functionName + ") {0:f} )".format(satisfaction_bound), functions = functionName)
def get_sensor_precondition_pddl_using_current_value(self, sensor_name, satisfaction_threshold, current_value): function_name = self.getPDDLFunctionName(sensor_name) next_threshold = current_value + self.__step_size * self.getDirection() operator = '>=' if self.getDirection() > 0 else '<=' statement = '( {0} ({1}) {2:f})'.format(operator,function_name,next_threshold) return PDDL(statement=statement, functions=function_name)
def getSensorStatePDDL(self, sensorName, normalizedValue): functionName = self.getPDDLFunctionName(sensorName) return PDDL(statement="(" + functionName + ")" if normalizedValue == True else "(not (" + functionName + "))", predicates=functionName)
def getSensorPreconditionPDDL(self, sensorName, satisfaction_threshold): functionName = self.getPDDLFunctionName(sensorName) return PDDL(statement = "(" + functionName + ")" if self._desired == True else "(not (" + functionName + "))", predicates=functionName)
def getSensorStatePDDL(self, sensorName, normalizedValue, sensor_update_time): functionName = self.getPDDLFunctionName(sensorName) return PDDL(statement="(" + functionName + ")" if normalizedValue == self._desired else "(not (" + functionName + "))", predicates=functionName, time_stamp=sensor_update_time)
def getSensorPreconditionPDDL(self, sensorName, satisfaction_threshold, current_sensor_value): functionName = self.getPDDLFunctionName(sensorName) return PDDL(statement="(" + functionName + ")", predicates=functionName)
def getSensorPreconditionPDDL(self, sensorName, satisfaction_threshold, current_sensor_value): functionName = self.getPDDLFunctionName(sensorName) return PDDL(statement="( = (" + functionName + ") {0} )".format(self._desired), functions=functionName)
def getSensorPreconditionPDDL(self, sensorName, satisfaction_threshold, current_sensor_value): functionName = self.getPDDLFunctionName(sensorName) return PDDL(statement="( >= (" + functionName + ") {0:f} )".format(self._threshold) if self.getDirection() == 1 else "( <= (" + functionName + ") {0:f} )".format(self._threshold), functions = functionName)