def visitExpression_t(self, ctx: pddl22Parser.Expression_tContext): hasht = ExprBase(expr_type=ExprBase.ExprType.SPECIAL, special_type=ExprBase.SpecialType.HASHT) if ctx.expression(): binary_op = ExprBase(expr_type=ExprBase.ExprType.BINARY_OPERATOR, op=ExprBase.BinaryOperator.MUL) expr = self.visit(ctx.expression()) return ExprComposite([binary_op,hasht]+expr.tokens) else: return ExprComposite([hasht])
def set_constant_duration(self, duration: float): lhs = ExprComposite([ ExprBase(expr_type=ExprBase.ExprType.SPECIAL, special_type=ExprBase.SpecialType.DURATION) ]) rhs = ExprComposite([ ExprBase(expr_type=ExprBase.ExprType.CONSTANT, constant=duration) ]) self.duration = DurationInequality( Inequality(comparison_type=Inequality.ComparisonType.EQUALS, lhs=lhs, rhs=rhs))
def visitGround_function_expression_binary( self, ctx: pddl22Parser.Ground_function_expression_binaryContext): binary_op = ExprBase(expr_type=ExprBase.ExprType.BINARY_OPERATOR) binary_op.op = ExprBase.BinaryOperator(ctx.binary_operator().getText()) lhs = self.visit(ctx.ground_function_expression()[0]) rhs = self.visit(ctx.ground_function_expression()[1]) return ExprComposite([binary_op] + lhs.tokens + rhs.tokens)
def visitExpression_durative_operator( self, ctx: pddl22Parser.Expression_durative_operatorContext): binary_op = ExprBase(expr_type=ExprBase.ExprType.BINARY_OPERATOR) binary_op.op = ExprBase.BinaryOperator(ctx.binary_operator().getText()) lhs = self.visit(ctx.expression_durative()[0]) rhs = self.visit(ctx.expression_durative()[1]) return ExprComposite([binary_op] + lhs.tokens + rhs.tokens)
def visitGround_function_expression_function(self, ctx: pddl22Parser.Ground_function_expression_functionContext): expr = ExprBase(expr_type=ExprBase.ExprType.FUNCTION) name = ctx.name()[0].getText() params = [] for param in ctx.name()[1:]: params.append(TypedParameter("TODO parse tables", "TODO parse tables", param.getText())) expr.function = AtomicFormula(name, params) return ExprComposite([expr])
def visitSimple_duration_constraint_simple( self, ctx: pddl22Parser.Simple_duration_constraint_simpleContext): comparison_type = Inequality.ComparisonType( ctx.duration_op().getText()) token = ExprBase(expr_type=ExprBase.ExprType.SPECIAL, special_type=ExprBase.SpecialType.DURATION) lhs = ExprComposite([token]) rhs = self.visit(ctx.expression()) return DurationInequality(Inequality(comparison_type, lhs, rhs))
def add_assign_effect(self, function: AtomicFormula, time_spec: TimeSpec = TimeSpec.AT_START, assign_type: AssignmentType = AssignmentType.ASSIGN, value: float = 1.0): """ Adds a numeric effect. If the operator already has a non-conjunctive effect then the new and existing effects will be wrapped together within a new conjunctive effect. """ value_expr = ExprComposite( [ExprBase(expr_type=ExprBase.ExprType.CONSTANT, constant=value)]) effect = Assignment(assign_type, function, value_expr) if self.durative: effect = TimedEffect(time_spec, effect) if self.effect.effect_type == EffectType.CONJUNCTION: self.effect: EffectConjunction self.effect.effects.append(effect) elif self.effect.effect_type == EffectType.EMPTY: self.effect = effect else: self.effect = EffectConjunction(effects=[self.effect, effect])
def visitGround_function_expression_total_time(self, ctx: pddl22Parser.Ground_function_expression_total_timeContext): token = ExprBase(expr_type=ExprBase.ExprType.SPECIAL, special_type=ExprBase.SpecialType.TOTAL_TIME) return ExprComposite([token])
def visitGround_function_expression_uminus(self, ctx: pddl22Parser.Ground_function_expression_uminusContext): uminus = ExprBase(expr_type=ExprBase.ExprType.UMINUS) return ExprComposite([uminus] + self.visit(ctx.ground_function_expression()))
def visitGround_function_expression_number(self, ctx: pddl22Parser.Ground_function_expression_numberContext): number = ExprBase(expr_type=ExprBase.ExprType.CONSTANT, constant=float(ctx.number().getText())) return ExprComposite([number])
def visitExpression_durative_duration(self, ctx: pddl22Parser.Expression_durative_durationContext): return ExprComposite([ExprBase( expr_type=ExprBase.ExprType.SPECIAL, special_type=ExprBase.SpecialType.DURATION)])
def visitExpression_durative_uminus(self, ctx: pddl22Parser.Expression_durative_uminusContext): uminus = ExprBase(expr_type=ExprBase.ExprType.UMINUS) return ExprComposite([uminus] + self.visit(ctx.expression_durative()))
def visitExpression_function(self, ctx: pddl22Parser.Expression_functionContext): expr = ExprBase(expr_type=ExprBase.ExprType.FUNCTION) expr.function = self.visit(ctx.atomic_formula()) return ExprComposite([expr])