diff --git a/README.md b/README.md index d17114a..4a2fe07 100644 --- a/README.md +++ b/README.md @@ -6,36 +6,60 @@ `plasp` 3 is in early development and not intended for productive use yet. -As of now, `plasp` 3 experimentally supports the full [SAS Format](http://www.fast-downward.org/TranslatorOutputFormat) (as of version 3) used by [Fast Downward](http://www.fast-downward.org/). +`plasp` 3 translates planning problem instances to ASP facts. +`plasp` 3 supports the input languages [PDDL](https://helios.hud.ac.uk/scommv/IPC-14/software.html) (only basic features currently) and the [SAS](http://www.fast-downward.org/TranslatorOutputFormat) (full support of the current version 3), which is used by [Fast Downward](http://www.fast-downward.org/). Please get in touch with [Patrick Lühne](https://www.luehne.de) if you have any suggestions. ## Usage -To translate an SAS file into ASP facts, call: +### Translating PDDL to ASP Facts + +PDDL instances are translated to ASP facts as follows: ```bash -$ plasp file.sas +$ plasp domain.pddl problem.pddl ``` -For example, a PDDL instance can be solved as follows. -First, use [Fast Downward](http://www.fast-downward.org/) to translate the files from PDDL to SAS: +Alternatively, PDDL instances may first be translated to SAS, the output format of [Fast Downward](http://www.fast-downward.org/). ```bash $ ./fast-downward.py --translate --build=release64 domain.pddl instance.pddl ``` -This creates the file `output.sas`. -The translated SAS instance can now be solved incrementally with `clingo` and the meta encoding `meta-sequential-incremental.lp`: +This creates a file called `output.sas`, which may now be translated by `plasp`. ```bash -$ plasp output.sas > instance.lp -$ clingo encodings/meta-sequential-incremental.lp instance.lp +$ plasp output.sas ``` +### Solving the Translated Instance + +The translated instance can finally be solved incrementally with `clingo` and a meta encoding, for instance, `pddl-meta-sequential-incremental.lp`: + +```bash +$ plasp domain.pddl problem.pddl > instance.lp +$ clingo encodings/pddl-meta-sequential-incremental.lp instance.lp +``` + +### Command-Line Interface + +```bash +$ plasp [files] [options] +``` + +`[files]` may be omitted, in which case the input is read from `std::cin`. +The `[options]` are listed below: + +| **option** | **explanation** | +|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| +| `-l` [ `--language` ] | Specify the input language (`sas` or `pddl`). Omit for automatic detection. | +| `--warning-level` arg (=`normal`) | Specify whether to output warnings normally (`normal`), to treat them as critical errors (`error`), or to ignore them (`ignore`). | +| `--color` arg (=`auto`) | Specify whether to colorize the output (`always`, `never`, or `auto`). | + ## Building -`plasp` requires a C++14 compiler (preferrably GCC ≥ 6.1), the `boost` libraries (≥ 1.55), and CMake for building. +`plasp` requires a C++14 compiler (preferrably GCC ≥ 6.1 or clang ≥ 3.8), the `boost` libraries (≥ 1.55), and CMake for building. ```bash $ git clone https://github.com/potassco/plasp.git diff --git a/apps/plasp-app/main.cpp b/apps/plasp-app/main.cpp index dd43531..dc9c2c5 100644 --- a/apps/plasp-app/main.cpp +++ b/apps/plasp-app/main.cpp @@ -21,7 +21,7 @@ int main(int argc, char **argv) ("help,h", "Display this help message.") ("version,v", "Display version information.") ("input,i", po::value>(), "Specify the PDDL or SAS input file.") - ("language,l", po::value(), "Specify the input language (SAS or PDDL). Omit for automatic detection.") + ("language,l", po::value(), "Specify the input language (sas or pddl). Omit for automatic detection.") ("warning-level", po::value()->default_value("normal"), "Specify whether to output warnings normally (normal), to treat them as critical errors (error), or to ignore them (ignore).") ("color", po::value()->default_value("auto"), "Specify whether to colorize the output (always, never, or auto)."); @@ -33,7 +33,7 @@ int main(int argc, char **argv) const auto printHelp = [&]() { - std::cout << "Usage: plasp file [options]" << std::endl; + std::cout << "Usage: plasp [files] [options]" << std::endl; std::cout << "Translate PDDL instances to ASP facts." << std::endl << std::endl; std::cout << description; @@ -76,6 +76,15 @@ int main(int argc, char **argv) logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Error); else if (warningLevel == "ignore") logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Ignore); + else if (warningLevel == "normal") + logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Normal); + else + { + logger.logError("unknown warning level “" + warningLevel + "”"); + std::cout << std::endl; + printHelp(); + return EXIT_FAILURE; + } const auto colorPolicy = variablesMap["color"].as(); @@ -85,6 +94,13 @@ int main(int argc, char **argv) logger.setColorPolicy(plasp::utils::LogStream::ColorPolicy::Never); else if (colorPolicy == "always") logger.setColorPolicy(plasp::utils::LogStream::ColorPolicy::Always); + else + { + logger.logError("unknown color policy “" + colorPolicy + "”"); + std::cout << std::endl; + printHelp(); + return EXIT_FAILURE; + } try { diff --git a/include/plasp/utils/LogStream.h b/include/plasp/utils/LogStream.h index e086b6d..87760f3 100644 --- a/include/plasp/utils/LogStream.h +++ b/include/plasp/utils/LogStream.h @@ -40,13 +40,13 @@ class LogStream public: LogStream(StandardStream standardStream) : m_standardStream{standardStream}, - m_colorPolicy{ColorPolicy::Never} + m_colorPolicy{ColorPolicy::Auto} { } LogStream(const LogStream &other) : m_standardStream{other.m_standardStream}, - m_colorPolicy{ColorPolicy::Never} + m_colorPolicy{ColorPolicy::Auto} { } @@ -62,7 +62,7 @@ class LogStream : m_standardStream{other.m_standardStream}, m_colorPolicy{other.m_colorPolicy} { - other.m_colorPolicy = ColorPolicy::Never; + other.m_colorPolicy = ColorPolicy::Auto; } LogStream &operator=(LogStream &&other) @@ -70,7 +70,7 @@ class LogStream m_standardStream = other.m_standardStream; m_colorPolicy = other.m_colorPolicy; - other.m_colorPolicy = ColorPolicy::Never; + other.m_colorPolicy = ColorPolicy::Auto; return *this; } diff --git a/src/plasp/Language.cpp b/src/plasp/Language.cpp index c23924e..6caaeb0 100644 --- a/src/plasp/Language.cpp +++ b/src/plasp/Language.cpp @@ -17,9 +17,9 @@ using LanguageNames = boost::bimap; //////////////////////////////////////////////////////////////////////////////////////////////////// const LanguageNames languageNames = boost::assign::list_of - (Language::Type::PDDL, "PDDL") - (Language::Type::SAS, "SAS") - (Language::Type::Unknown, "Unknown"); + (Language::Type::PDDL, "pddl") + (Language::Type::SAS, "sas") + (Language::Type::Unknown, "unknown"); //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -28,7 +28,7 @@ std::string Language::toString(Language::Type language) const auto match = languageNames.left.find(language); if (match == languageNames.left.end()) - return "Unknown"; + return "unknown"; return match->second; } diff --git a/src/plasp/pddl/TranslatorASP.cpp b/src/plasp/pddl/TranslatorASP.cpp index 4ee5c70..ee2eb69 100644 --- a/src/plasp/pddl/TranslatorASP.cpp +++ b/src/plasp/pddl/TranslatorASP.cpp @@ -325,7 +325,7 @@ void TranslatorASP::translateVariablesBody(const expressions::Variables &variabl m_outputStream << utils::Keyword("hasType") << "(" << utils::Variable(utils::escapeASPVariable(variable.name())) << ", " - << utils::Keyword("type") << "(" << type.name() << "))"; + << utils::Keyword("type") << "(" << utils::escapeASP(type.name()) << "))"; } else {