Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend RDDL expressions to handle >2 operands in reward function #322

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions rosplan_knowledge_base/src/RDDLExprUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,34 @@ RDDLExprUtils::getExpression(const LogicalExpression *expr, const std::map<std::
}

rosplan_knowledge_msgs::ExprComposite RDDLExprUtils::getExpression(const Connective *expr, const std::map<std::string, std::string>& assign) {
assert(expr->exprs.size() == 2); // Assuming two operands in each
rosplan_knowledge_msgs::ExprComposite ret;

rosplan_knowledge_msgs::ExprBase base;
base.expr_type = rosplan_knowledge_msgs::ExprBase::OPERATOR;
for (int i = 0; i < expr->exprs.size()-1; ++i) {
rosplan_knowledge_msgs::ExprBase base;
base.expr_type = rosplan_knowledge_msgs::ExprBase::OPERATOR;

// Check type
if (dynamic_cast<const Multiplication *>(expr) != nullptr ||
dynamic_cast<const Conjunction *>(expr) != nullptr)
base.op = rosplan_knowledge_msgs::ExprBase::MUL;
else if (dynamic_cast<const Addition *>(expr) != nullptr ||
dynamic_cast<const Disjunction *>(expr) != nullptr)
base.op = rosplan_knowledge_msgs::ExprBase::ADD;
else if (dynamic_cast<const Subtraction *>(expr) != nullptr) base.op = rosplan_knowledge_msgs::ExprBase::SUB;
else if (dynamic_cast<const Division *>(expr) != nullptr) base.op = rosplan_knowledge_msgs::ExprBase::DIV;
else {
NOT_IMPLEMENTED_EXPR;
return ret;
}
ret.tokens.push_back(base);

// Check type
if (dynamic_cast<const Multiplication*>(expr) != nullptr || dynamic_cast<const Conjunction*>(expr) != nullptr) base.op = rosplan_knowledge_msgs::ExprBase::MUL;
else if (dynamic_cast<const Addition*>(expr) != nullptr || dynamic_cast<const Disjunction*>(expr) != nullptr) base.op = rosplan_knowledge_msgs::ExprBase::ADD;
else if (dynamic_cast<const Subtraction*>(expr) != nullptr) base.op = rosplan_knowledge_msgs::ExprBase::SUB;
else if (dynamic_cast<const Division*>(expr) != nullptr) base.op = rosplan_knowledge_msgs::ExprBase::DIV;
else {
NOT_IMPLEMENTED_EXPR;
return ret;
rosplan_knowledge_msgs::ExprComposite operand = getExpression(expr->exprs[i], assign);
join(ret.tokens, operand.tokens);
}
ret.tokens.push_back(base);

rosplan_knowledge_msgs::ExprComposite operand1 = getExpression(expr->exprs[0], assign);
rosplan_knowledge_msgs::ExprComposite operand2 = getExpression(expr->exprs[1], assign);
//ret.tokens.insert(ret.tokens.end(), std::make_move_iterator(operand1.tokens.begin()), std::make_move_iterator(operand1.tokens.end()));
join(ret.tokens, operand1.tokens);
//ret.tokens.insert(ret.tokens.end(), std::make_move_iterator(operand2.tokens.begin()), std::make_move_iterator(operand2.tokens.end()));
join(ret.tokens, operand2.tokens);
// Add last
rosplan_knowledge_msgs::ExprComposite operand = getExpression(expr->exprs[expr->exprs.size()-1], assign);
join(ret.tokens, operand.tokens);
return ret;
}

Expand Down