Skip to content

Commit fc37fdb

Browse files
committed
added missing negation of numeric constraints in negation normal form. improve argparsing according to issue #16
1 parent 411e04d commit fc37fdb

28 files changed

Lines changed: 714 additions & 365 deletions

exe/loki.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222

2323
int main(int argc, char** argv)
2424
{
25-
auto program = argparse::ArgumentParser("AStar search.");
26-
program.add_argument("-D", "--domain-filepath").required().help("The path to the PDDL domain file.");
27-
program.add_argument("-P", "--problem-filepath").default_value("").help("The path to the PDDL problem file.");
28-
program.add_argument("-OD", "--out-domain-filepath").default_value("").help("The path to the output PDDL domain file.");
29-
program.add_argument("-OP", "--out-problem-filepath").default_value("").help("The path to the output PDDL problem file.");
25+
auto program = argparse::ArgumentParser("loki");
26+
program.add_argument("domain").required().help("The path to the PDDL domain file.");
27+
program.add_argument("problem").default_value("").help("The path to the PDDL problem file.");
28+
program.add_argument("-OD", "--out-domain").default_value("").help("The path to the output PDDL domain file.");
29+
program.add_argument("-OP", "--out-problem").default_value("").help("The path to the output PDDL problem file.");
3030
program.add_argument("-S", "--strict").default_value(false).implicit_value(true).help("Enable strict parsing mode.");
31-
program.add_argument("-Q", "--quiet").default_value(true).implicit_value(false).help("Disable quiet mode.");
32-
/* TODO(Dominik): add translator options */
33-
program.add_argument("-T", "--remove-typing").default_value(false).implicit_value(true).help("Enable removal of typing.");
31+
program.add_argument("-V", "--verbose").default_value(false).implicit_value(true).help("Verbose prints.");
32+
program.add_argument("--remove-typing").default_value(false).implicit_value(true).help("Enable removal of typing.");
3433

3534
try
3635
{
@@ -43,13 +42,13 @@ int main(int argc, char** argv)
4342
std::exit(1);
4443
}
4544

46-
auto domain_filepath = program.get<std::string>("--domain-filepath");
47-
auto problem_filepath = program.get<std::string>("--problem-filepath");
48-
auto out_domain_filepath = program.get<std::string>("--out-domain-filepath");
49-
auto out_problem_filepath = program.get<std::string>("--out-problem-filepath");
45+
auto domain_filepath = program.get<std::string>("domain");
46+
auto problem_filepath = program.get<std::string>("problem");
47+
auto out_domain_filepath = program.get<std::string>("--out-domain");
48+
auto out_problem_filepath = program.get<std::string>("--out-problem");
5049

5150
auto parser_options = loki::ParserOptions();
52-
parser_options.quiet = program.get<bool>("--quiet");
51+
parser_options.verbose = program.get<bool>("--verbose");
5352
parser_options.strict = program.get<bool>("--strict");
5453

5554
auto translator_options = loki::TranslatorOptions();
@@ -59,7 +58,8 @@ int main(int argc, char** argv)
5958
const auto domain = parser.get_domain();
6059

6160
const auto domain_translation_result = loki::translate(domain, translator_options);
62-
std::cout << *domain_translation_result.get_translated_domain() << std::endl;
61+
if (parser_options.verbose)
62+
std::cout << *domain_translation_result.get_translated_domain() << std::endl;
6363

6464
if (!out_domain_filepath.empty())
6565
{
@@ -73,7 +73,8 @@ int main(int argc, char** argv)
7373
auto problem = parser.parse_problem(problem_filepath, parser_options);
7474

7575
const auto translated_problem = loki::translate(problem, domain_translation_result, translator_options);
76-
std::cout << *translated_problem << std::endl;
76+
if (parser_options.verbose)
77+
std::cout << *translated_problem << std::endl;
7778

7879
if (!out_problem_filepath.empty())
7980
{

include/loki/details/ast/ast.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct BinaryOperator;
9999
struct BinaryComparatorGreater;
100100
struct BinaryComparatorLess;
101101
struct BinaryComparatorEqual;
102+
struct BinaryComparatorUnequal;
102103
struct BinaryComparatorGreaterEqual;
103104
struct BinaryComparatorLessEqual;
104105
struct BinaryComparator;
@@ -573,6 +574,10 @@ struct BinaryComparatorEqual : x3::position_tagged
573574
{
574575
};
575576

577+
struct BinaryComparatorUnequal : x3::position_tagged
578+
{
579+
};
580+
576581
struct BinaryComparatorGreaterEqual : x3::position_tagged
577582
{
578583
};
@@ -583,7 +588,12 @@ struct BinaryComparatorLessEqual : x3::position_tagged
583588

584589
struct BinaryComparator :
585590
x3::position_tagged,
586-
x3::variant<BinaryComparatorGreater, BinaryComparatorLess, BinaryComparatorEqual, BinaryComparatorGreaterEqual, BinaryComparatorLessEqual>
591+
x3::variant<BinaryComparatorGreater,
592+
BinaryComparatorLess,
593+
BinaryComparatorEqual,
594+
BinaryComparatorGreaterEqual,
595+
BinaryComparatorUnequal,
596+
BinaryComparatorLessEqual>
587597
{
588598
using base_type::base_type;
589599
using base_type::operator=;

include/loki/details/ast/printer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ void write(const ast::BinaryComparatorLess& node, T formatter, std::ostream& out
187187
template<Formatter T>
188188
void write(const ast::BinaryComparatorEqual& node, T formatter, std::ostream& out);
189189
template<Formatter T>
190+
void write(const ast::BinaryComparatorUnequal& node, T formatter, std::ostream& out);
191+
template<Formatter T>
190192
void write(const ast::BinaryComparatorGreaterEqual& node, T formatter, std::ostream& out);
191193
template<Formatter T>
192194
void write(const ast::BinaryComparatorLessEqual& node, T formatter, std::ostream& out);

include/loki/details/pddl/domain_builder.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class DomainBuilder
5353
/// @return the resulting `Domain`.
5454
Domain get_result();
5555

56+
/// @brief Finalizes the `Domain`, verify indexing schemes, and returns it.
57+
/// The `DomainBuilder` is in an invalid state afterwards.
58+
/// @return the resulting `Domain`.
59+
Domain get_result_checked();
60+
5661
/**
5762
* Get and modify components of the domain.
5863
*/

include/loki/details/pddl/function_expressions.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ enum class BinaryComparatorEnum
3030
GREATER, ///< ">"
3131
LESS, ///< "<"
3232
EQUAL, ///< "="
33+
UNEQUAL, ///< "!="
3334
GREATER_EQUAL, ///< ">="
3435
LESS_EQUAL, ///< "<="
3536
};
3637

3738
extern std::unordered_map<BinaryComparatorEnum, std::string> binary_comparator_enum_to_string;
3839
extern std::ostream& operator<<(std::ostream& out, BinaryComparatorEnum element);
40+
extern BinaryComparatorEnum negate(BinaryComparatorEnum element);
3941

4042
enum class BinaryOperatorEnum
4143
{

include/loki/details/pddl/parser_options.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ namespace loki
2323
struct ParserOptions
2424
{
2525
bool strict;
26-
bool quiet;
26+
bool verbose;
2727

28-
ParserOptions() : strict(false), quiet(true) {}
28+
ParserOptions() : strict(false), verbose(false) {}
2929
};
3030
}
3131

include/loki/details/pddl/problem_builder.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,18 @@ class ProblemBuilder
4747

4848
public:
4949
/// @brief Create a `ProblemBuilder` for a given `Domain`.
50-
///
51-
/// Copies all elements from the domain repositories as external elements into the problem repositories.
52-
/// We use canonical representations to retrieve syntactically equivalent elements from the domain in most cases,
53-
/// especially for the critial ones such as Type, Predicate, FunctionSkeleton, Object and all of its nested elements.
54-
/// We do not yet have a canonical representation for Condition, FunctionExpression, and Effect, meaning that there can be semantic duplicates.
55-
///
56-
/// The canonical representation is important during translation to ensure that we can decouple the domain from the problem translation.
57-
/// Let's assume we translate the domain first, meaning that we get new addresses for all elements and that we now translate a problem.
58-
/// The copy step ensures that we reuse elements of the translated domain during the problem translation.
5950
explicit ProblemBuilder(Domain domain);
6051

6152
/// @brief Finalizes the `Problem` and returns it.
6253
/// The `ProblemBuilder` is in an invalid state afterwards.
6354
/// @return the resulting `Problem`.
6455
Problem get_result(size_t problem_index);
6556

57+
/// @brief Finalizes the `Problem`, verify indexing schemes, and returns it.
58+
/// The `ProblemBuilder` is in an invalid state afterwards.
59+
/// @return the resulting `Problem`.
60+
Problem get_result_checked(size_t problem_index);
61+
6662
/**
6763
* Get and modify components of the problem.
6864
*/

include/loki/details/pddl/translator.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ class DomainTranslationResult
2828
{
2929
private:
3030
Domain original_domain; ///< used to check that a problem can be translated with this result.
31-
Domain translated_typed_domain;
3231
Domain translated_domain;
3332

3433
public:
35-
DomainTranslationResult(Domain original_domain, Domain translated_typed_domain, Domain translated_domain);
34+
DomainTranslationResult(Domain original_domain, Domain translated_domain);
3635

3736
const Domain& get_original_domain() const;
38-
const Domain& get_translated_typed_domain() const;
3937
const Domain& get_translated_domain() const;
4038
};
4139

src/ast/parser.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct BinaryOperatorClass;
113113
struct BinaryComparatorGreaterClass;
114114
struct BinaryComparatorLessClass;
115115
struct BinaryComparatorEqualClass;
116+
struct BinaryComparatorUnequalClass;
116117
struct BinaryComparatorGreaterEqualClass;
117118
struct BinaryComparatorLessEqualClass;
118119
struct BinaryComparatorClass;
@@ -312,6 +313,7 @@ typedef x3::rule<BinaryOperatorClass, ast::BinaryOperator> binary_operator_type;
312313
typedef x3::rule<BinaryComparatorGreaterClass, ast::BinaryComparatorGreater> binary_comparator_greater_type;
313314
typedef x3::rule<BinaryComparatorLessClass, ast::BinaryComparatorLess> binary_comparator_less_type;
314315
typedef x3::rule<BinaryComparatorEqualClass, ast::BinaryComparatorEqual> binary_comparator_equal_type;
316+
typedef x3::rule<BinaryComparatorUnequalClass, ast::BinaryComparatorUnequal> binary_comparator_unequal_type;
315317
typedef x3::rule<BinaryComparatorGreaterEqualClass, ast::BinaryComparatorGreaterEqual> binary_comparator_greater_equal_type;
316318
typedef x3::rule<BinaryComparatorLessEqualClass, ast::BinaryComparatorLessEqual> binary_comparator_less_equal_type;
317319
typedef x3::rule<BinaryComparatorClass, ast::BinaryComparator> binary_comparator_type;
@@ -503,6 +505,7 @@ BOOST_SPIRIT_DECLARE(multi_operator_mul_type,
503505
BOOST_SPIRIT_DECLARE(binary_comparator_greater_type,
504506
binary_comparator_less_type,
505507
binary_comparator_equal_type,
508+
binary_comparator_unequal_type,
506509
binary_comparator_greater_equal_type,
507510
binary_comparator_less_equal_type,
508511
binary_comparator_type)
@@ -680,6 +683,7 @@ parser::binary_operator_type const& binary_operator();
680683
parser::binary_comparator_greater_type const& binary_comparator_greater();
681684
parser::binary_comparator_less_type const& binary_comparator_less();
682685
parser::binary_comparator_equal_type const& binary_comparator_equal();
686+
parser::binary_comparator_unequal_type const& binary_comparator_unequal();
683687
parser::binary_comparator_greater_equal_type const& binary_comparator_greater_equal();
684688
parser::binary_comparator_less_equal_type const& binary_comparator_less_equal();
685689
parser::binary_comparator_type const& binary_comparator();

src/ast/parser_def.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ binary_operator_type const binary_operator = "binary_operator";
129129
binary_comparator_greater_type const binary_comparator_greater = "binary_comparator_greater";
130130
binary_comparator_less_type const binary_comparator_less = "binary_comparator_less";
131131
binary_comparator_equal_type const binary_comparator_equal = "binary_comparator_equal";
132+
binary_comparator_unequal_type const binary_comparator_unequal = "binary_comparator_unequal";
132133
binary_comparator_greater_equal_type const binary_comparator_greater_equal = "binary_comparator_greater_equal";
133134
binary_comparator_less_equal_type const binary_comparator_less_equal = "binary_comparator_less_equal";
134135
binary_comparator_type const binary_comparator = "binary_comparator";
@@ -334,10 +335,11 @@ const auto binary_operator_def = binary_operator_minus | binary_operator_div | m
334335
const auto binary_comparator_greater_def = lit('>') > x3::attr(ast::BinaryComparatorGreater {});
335336
const auto binary_comparator_less_def = lit('<') > x3::attr(ast::BinaryComparatorLess {});
336337
const auto binary_comparator_equal_def = lit('=') > x3::attr(ast::BinaryComparatorEqual {});
338+
const auto binary_comparator_unequal_def = lit('=') > x3::attr(ast::BinaryComparatorUnequal {});
337339
const auto binary_comparator_greater_equal_def = lit(">=") > x3::attr(ast::BinaryComparatorGreaterEqual {});
338340
const auto binary_comparator_less_equal_def = lit("<=") > x3::attr(ast::BinaryComparatorLessEqual {});
339-
const auto binary_comparator_def =
340-
binary_comparator_greater_equal | binary_comparator_less_equal | binary_comparator_greater | binary_comparator_less | binary_comparator_equal;
341+
const auto binary_comparator_def = binary_comparator_greater_equal | binary_comparator_less_equal | binary_comparator_greater | binary_comparator_less
342+
| binary_comparator_equal | binary_comparator_unequal;
341343

342344
const auto function_head_def = (((lit('(') >> function_symbol) > *term) > lit(')'));
343345
const auto function_expression_def =
@@ -542,6 +544,7 @@ BOOST_SPIRIT_DEFINE(multi_operator_mul, multi_operator_plus, multi_operator, bin
542544
BOOST_SPIRIT_DEFINE(binary_comparator_greater,
543545
binary_comparator_less,
544546
binary_comparator_equal,
547+
binary_comparator_unequal,
545548
binary_comparator_greater_equal,
546549
binary_comparator_less_equal,
547550
binary_comparator)
@@ -831,6 +834,9 @@ struct BinaryComparatorLessClass : x3::annotate_on_success
831834
struct BinaryComparatorEqualClass : x3::annotate_on_success
832835
{
833836
};
837+
struct BinaryComparatorUnequalClass : x3::annotate_on_success
838+
{
839+
};
834840
struct BinaryComparatorGreaterEqualClass : x3::annotate_on_success
835841
{
836842
};
@@ -1260,6 +1266,7 @@ parser::binary_operator_type const& binary_operator() { return parser::binary_op
12601266
parser::binary_comparator_greater_type const& binary_comparator_greater() { return parser::binary_comparator_greater; }
12611267
parser::binary_comparator_less_type const& binary_comparator_less() { return parser::binary_comparator_less; }
12621268
parser::binary_comparator_equal_type const& binary_comparator_equal() { return parser::binary_comparator_equal; }
1269+
parser::binary_comparator_unequal_type const& binary_comparator_unequal() { return parser::binary_comparator_unequal; }
12631270
parser::binary_comparator_greater_equal_type const& binary_comparator_greater_equal() { return parser::binary_comparator_greater_equal; }
12641271
parser::binary_comparator_less_equal_type const& binary_comparator_less_equal() { return parser::binary_comparator_less_equal; }
12651272
parser::binary_comparator_type const& binary_comparator() { return parser::binary_comparator; }

0 commit comments

Comments
 (0)