Changes have been pushed for the project "Fawkes Robotics Software Framework".
Gitweb: http://git.fawkesrobotics.org/fawkes.git Trac: http://trac.fawkesrobotics.org The branch, bschaepers/asp-aspect has been updated to 0c578f53763afea4bf9ef222b054f1b5cfa0a8e3 (commit) via 559b56aa233d8a8480f0736fa3eab9f39727c203 (commit) via 2cf4dc4bb25b6779444375df78550ed4b6e90e67 (commit) via d87b61b714a9c77eea8697d053b42fd9b14c25c2 (commit) from 07374426b1c53acc9510a7375fbcc54646810c33 (commit) http://git.fawkesrobotics.org/fawkes.git/bschaepers/asp-aspect Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - *Log* --------------------------------------------------------------- commit d87b61b714a9c77eea8697d053b42fd9b14c25c2 Author: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> AuthorDate: Thu Dec 1 19:57:54 2016 +0100 Commit: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> CommitDate: Thu Dec 1 19:57:54 2016 +0100 ASP-Aspect: Use cmake clingo everywhere. http://git.fawkesrobotics.org/fawkes.git/commit/d87b61b http://trac.fawkesrobotics.org/changeset/d87b61b - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - commit 2cf4dc4bb25b6779444375df78550ed4b6e90e67 Author: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> AuthorDate: Thu Dec 1 20:00:49 2016 +0100 Commit: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> CommitDate: Thu Dec 1 20:00:49 2016 +0100 ASP-Aspect: Added ability to reset Clingo. By deleting the Control object, there is no other way to reset it. http://git.fawkesrobotics.org/fawkes.git/commit/2cf4dc4 http://trac.fawkesrobotics.org/changeset/2cf4dc4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - commit 559b56aa233d8a8480f0736fa3eab9f39727c203 Author: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> AuthorDate: Thu Dec 1 20:01:54 2016 +0100 Commit: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> CommitDate: Thu Dec 1 20:01:54 2016 +0100 ASP-Aspect: Add possible ground callback. Within this callback functions can be exported to ASP. We use this at least for constants read from fawkes config. http://git.fawkesrobotics.org/fawkes.git/commit/559b56a http://trac.fawkesrobotics.org/changeset/559b56a - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - commit 0c578f53763afea4bf9ef222b054f1b5cfa0a8e3 Author: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> AuthorDate: Thu Dec 1 20:03:36 2016 +0100 Commit: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> CommitDate: Thu Dec 1 20:03:36 2016 +0100 ASP-Aspect: Use references for externals. http://git.fawkesrobotics.org/fawkes.git/commit/0c578f5 http://trac.fawkesrobotics.org/changeset/0c578f5 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *Summary* ----------------------------------------------------------- src/plugins/asp/aspect/Makefile | 2 +- src/plugins/asp/aspect/clingo_access.cpp | 108 ++++++++++++++++++++++------- src/plugins/asp/aspect/clingo_access.h | 14 +++- 3 files changed, 94 insertions(+), 30 deletions(-) - *Diffs* ------------------------------------------------------------- - *commit* d87b61b714a9c77eea8697d053b42fd9b14c25c2 - - - - - - - - - - Author: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> Date: Thu Dec 1 19:57:54 2016 +0100 Subject: ASP-Aspect: Use cmake clingo everywhere. src/plugins/asp/aspect/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) _Diff for modified files_: diff --git a/src/plugins/asp/aspect/Makefile b/src/plugins/asp/aspect/Makefile index 9a43079..3bd268b 100644 --- a/src/plugins/asp/aspect/Makefile +++ b/src/plugins/asp/aspect/Makefile @@ -32,7 +32,7 @@ CFLAGS_CLINGO = -DWITH_THREADS=1 \ -I $(HOME)/clingo/libgringo \ -I $(HOME)/clingo/liblp \ -I $(HOME)/clingo/libprogram_opts -LDFLAGS_CLINGO = -L$(HOME)/clingo/build/debug/ -Wl,-rpath=$(HOME)/clingo/build/debug/ -lclingo +LDFLAGS_CLINGO = -L$(HOME)/clingo-build/bin -Wl,-rpath=$(HOME)/clingo-build/bin -lclingo ifeq ($(HAVE_CPP11),1) ifeq ($(HAVE_CLINGO),1) - *commit* 2cf4dc4bb25b6779444375df78550ed4b6e90e67 - - - - - - - - - - Author: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> Date: Thu Dec 1 20:00:49 2016 +0100 Subject: ASP-Aspect: Added ability to reset Clingo. src/plugins/asp/aspect/clingo_access.cpp | 89 ++++++++++++++++++++++-------- src/plugins/asp/aspect/clingo_access.h | 7 ++- 2 files changed, 71 insertions(+), 25 deletions(-) _Diff for modified files_: diff --git a/src/plugins/asp/aspect/clingo_access.cpp b/src/plugins/asp/aspect/clingo_access.cpp index 3117f04..1705a70 100644 --- a/src/plugins/asp/aspect/clingo_access.cpp +++ b/src/plugins/asp/aspect/clingo_access.cpp @@ -148,30 +148,51 @@ ClingoAccess::solvingFinished(const Clingo::SolveResult result) } /** + * @brief Allocates the control object and initializes the logger. + */ +void +ClingoAccess::allocControl() +{ + assert(!Control); + Control = new Clingo::Control({}, + [this](const Clingo::WarningCode code, char const *msg) + { + fawkes::Logger::LogLevel level = fawkes::Logger::LL_NONE; + switch ( code ) + { + case Clingo::WarningCode::AtomUndefined : + case Clingo::WarningCode::OperationUndefined : + case Clingo::WarningCode::RuntimeError : level = fawkes::Logger::LL_ERROR; break; + case Clingo::WarningCode::Other : + case Clingo::WarningCode::VariableUnbounded : level = fawkes::Logger::LL_WARN; break; + case Clingo::WarningCode::FileIncluded : + case Clingo::WarningCode::GlobalVariable : level = fawkes::Logger::LL_INFO; break; + } //switch ( code ) + Log->log(level, LogComponent.c_str(), msg); + return; + }, 100); + return; +} + +/** * @brief Constructor. * @param[in] log The used logger. * @param[in] logComponent The logging component. * @param[in] controlArgs... The arguments for the clingo control constructor. */ ClingoAccess::ClingoAccess(Logger *log, const std::string& logComponent) : Log(log), - LogComponent(logComponent.empty() ? "Clingo" : logComponent), Control({}, - [this](const Clingo::WarningCode code, char const *msg) - { - fawkes::Logger::LogLevel level = fawkes::Logger::LL_NONE; - switch ( code ) - { - case Clingo::WarningCode::AtomUndefined : - case Clingo::WarningCode::OperationUndefined : - case Clingo::WarningCode::RuntimeError : level = fawkes::Logger::LL_ERROR; break; - case Clingo::WarningCode::Other : - case Clingo::WarningCode::VariableUnbounded : level = fawkes::Logger::LL_WARN; break; - case Clingo::WarningCode::FileIncluded : - case Clingo::WarningCode::GlobalVariable : level = fawkes::Logger::LL_INFO; break; - } //switch ( code ) - Log->log(level, LogComponent.c_str(), msg); - return; - }, 100), Solving(false), Debug(false) + LogComponent(logComponent.empty() ? "Clingo" : logComponent), Control(nullptr), Solving(false), Debug(false) +{ + allocControl(); + return; +} + +/** + * @brief The destructor. + */ +ClingoAccess::~ClingoAccess(void) { + delete Control; return; } @@ -251,7 +272,7 @@ ClingoAccess::startSolving(void) Log->log_info(LogComponent.c_str(), "Start async solving."); } //if ( Debug ) Solving = true; - Control.solve_async([this](const Clingo::Model& model) { return newModel(model); }, + Control->solve_async([this](const Clingo::Model& model) { return newModel(model); }, [this](const Clingo::SolveResult& result) { solvingFinished(result); return; }); return true; } @@ -275,7 +296,7 @@ ClingoAccess::startSolvingBlocking(void) Log->log_info(LogComponent.c_str(), "Start sync solving."); } //if ( Debug ) Solving = true; - const auto result(Control.solve([this,&locker](const Clingo::Model& model) { + const auto result(Control->solve([this,&locker](const Clingo::Model& model) { locker.unlock(); const auto ret = newModel(model); locker.relock(); @@ -303,7 +324,27 @@ ClingoAccess::cancelSolving(void) { Log->log_info(LogComponent.c_str(), "Cancel solving."); } //if ( Debug ) - Control.interrupt(); + Control->interrupt(); + return true; +} + +/** + * @brief Tries to reset Clingo, that means deletes the control object and creates a new one. + * @return If it was an success. + */ +bool +ClingoAccess::reset() +{ + if ( Solving ) + { + Log->log_warn(LogComponent.c_str(), + "Could not reset while solving. Please try again when the solving is stopped."); + cancelSolving(); + return false; + } //if ( Solving ) + delete Control; + Control = nullptr; + allocControl(); return true; } @@ -332,7 +373,7 @@ ClingoAccess::loadFile(const std::string& path) } //if ( Solving ) Log->log_info(LogComponent.c_str(), "Loading file program file %s.", path.c_str()); - Control.load(path.c_str()); + Control->load(path.c_str()); return true; } @@ -374,7 +415,7 @@ ClingoAccess::ground(const Clingo::PartSpan& parts) } //for ( const auto& part : parts ) } //if ( Debug ) - Control.ground(parts); + Control->ground(parts); if ( Debug ) { @@ -412,7 +453,7 @@ ClingoAccess::assign_external(const Clingo::Symbol atom, const Clingo::TruthValu return ret; }(), atom.to_string().c_str()); } //if ( Debug ) - Control.assign_external(atom, value); + Control->assign_external(atom, value); return true; } @@ -434,7 +475,7 @@ ClingoAccess::release_external(const Clingo::Symbol atom) { Log->log_info(LogComponent.c_str(), "Releasing %s.", atom.to_string().c_str()); } //if ( Debug ) - Control.release_external(atom); + Control->release_external(atom); return true; } diff --git a/src/plugins/asp/aspect/clingo_access.h b/src/plugins/asp/aspect/clingo_access.h index 1afabc8..4fb8379 100644 --- a/src/plugins/asp/aspect/clingo_access.h +++ b/src/plugins/asp/aspect/clingo_access.h @@ -45,7 +45,7 @@ class ClingoAccess const std::string LogComponent; mutable Mutex ControlMutex; - Clingo::Control Control; + Clingo::Control *Control; Clingo::SymbolVector ModelSymbols, OldSymbols; std::atomic_bool Solving; @@ -56,10 +56,13 @@ class ClingoAccess bool newModel(const Clingo::Model& model); void solvingFinished(const Clingo::SolveResult result); + void allocControl(void); + public: std::atomic_bool Debug; ClingoAccess(Logger *log, const std::string& logComponent); + ~ClingoAccess(void); void registerModelCallback(std::shared_ptr<std::function<bool(void)>> callback); void unregisterModelCallback(std::shared_ptr<std::function<bool(void)>> callback); @@ -71,6 +74,8 @@ class ClingoAccess bool startSolvingBlocking(void); bool cancelSolving(void); + bool reset(void); + Clingo::SymbolVector modelSymbols(void) const; bool loadFile(const std::string& path); - *commit* 559b56aa233d8a8480f0736fa3eab9f39727c203 - - - - - - - - - - Author: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> Date: Thu Dec 1 20:01:54 2016 +0100 Subject: ASP-Aspect: Add possible ground callback. src/plugins/asp/aspect/clingo_access.cpp | 17 ++++++++++++++++- src/plugins/asp/aspect/clingo_access.h | 3 +++ 2 files changed, 19 insertions(+), 1 deletions(-) _Diff for modified files_: diff --git a/src/plugins/asp/aspect/clingo_access.cpp b/src/plugins/asp/aspect/clingo_access.cpp index 1705a70..5289ec6 100644 --- a/src/plugins/asp/aspect/clingo_access.cpp +++ b/src/plugins/asp/aspect/clingo_access.cpp @@ -68,6 +68,9 @@ namespace fawkes { * @property ClingoAccess::FinishCallbacks * @brief The functions to call, when the solving process finished. * + * @property ClingoAccess::GroundCallback + * @brief The callback for the grounding. + * * @property ClingoAccess::Debug * @brief Whether additional debug output is desired. */ @@ -246,6 +249,18 @@ ClingoAccess::unregisterFinishCallback(std::shared_ptr<std::function<void(Clingo } /** + * @brief Sets the ground callback, to implement custom functions. + * @param[in, out] callback The callback, will be moved. + */ +void +ClingoAccess::setGroundCallback(Clingo::GroundCallback&& callback) +{ + MutexLocker locker(&CallbackMutex); + GroundCallback = std::move(callback); + return; +} + +/** * @brief Returns whether the solving process is running. */ bool @@ -415,7 +430,7 @@ ClingoAccess::ground(const Clingo::PartSpan& parts) } //for ( const auto& part : parts ) } //if ( Debug ) - Control->ground(parts); + Control->ground(parts, GroundCallback); if ( Debug ) { diff --git a/src/plugins/asp/aspect/clingo_access.h b/src/plugins/asp/aspect/clingo_access.h index 4fb8379..289a522 100644 --- a/src/plugins/asp/aspect/clingo_access.h +++ b/src/plugins/asp/aspect/clingo_access.h @@ -52,6 +52,7 @@ class ClingoAccess mutable Mutex CallbackMutex; std::vector<std::shared_ptr<std::function<bool(void)>>> ModelCallbacks; std::vector<std::shared_ptr<std::function<void(Clingo::SolveResult)>>> FinishCallbacks; + Clingo::GroundCallback GroundCallback; bool newModel(const Clingo::Model& model); void solvingFinished(const Clingo::SolveResult result); @@ -69,6 +70,8 @@ class ClingoAccess void registerFinishCallback(std::shared_ptr<std::function<void(Clingo::SolveResult)>> callback); void unregisterFinishCallback(std::shared_ptr<std::function<void(Clingo::SolveResult)>> callback); + void setGroundCallback(Clingo::GroundCallback&& callback); + bool solving(void) const noexcept; bool startSolving(void); bool startSolvingBlocking(void); - *commit* 0c578f53763afea4bf9ef222b054f1b5cfa0a8e3 - - - - - - - - - - Author: Bjoern Schaepers <bjoern.schaep...@rwth-aachen.de> Date: Thu Dec 1 20:03:36 2016 +0100 Subject: ASP-Aspect: Use references for externals. src/plugins/asp/aspect/clingo_access.cpp | 4 ++-- src/plugins/asp/aspect/clingo_access.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) _Diff for modified files_: diff --git a/src/plugins/asp/aspect/clingo_access.cpp b/src/plugins/asp/aspect/clingo_access.cpp index 5289ec6..7cd4cc7 100644 --- a/src/plugins/asp/aspect/clingo_access.cpp +++ b/src/plugins/asp/aspect/clingo_access.cpp @@ -446,7 +446,7 @@ ClingoAccess::ground(const Clingo::PartSpan& parts) * @return If it could be assigned. */ bool -ClingoAccess::assign_external(const Clingo::Symbol atom, const Clingo::TruthValue value) +ClingoAccess::assign_external(const Clingo::Symbol& atom, const Clingo::TruthValue value) { MutexLocker locker(&ControlMutex); if ( Solving ) @@ -478,7 +478,7 @@ ClingoAccess::assign_external(const Clingo::Symbol atom, const Clingo::TruthValu * @return If it could be released. */ bool -ClingoAccess::release_external(const Clingo::Symbol atom) +ClingoAccess::release_external(const Clingo::Symbol& atom) { MutexLocker locker(&ControlMutex); if ( Solving ) diff --git a/src/plugins/asp/aspect/clingo_access.h b/src/plugins/asp/aspect/clingo_access.h index 289a522..9b3c7e8 100644 --- a/src/plugins/asp/aspect/clingo_access.h +++ b/src/plugins/asp/aspect/clingo_access.h @@ -85,8 +85,8 @@ class ClingoAccess bool ground(const Clingo::PartSpan& parts); - bool assign_external(const Clingo::Symbol atom, const Clingo::TruthValue value); - bool release_external(const Clingo::Symbol atom); + bool assign_external(const Clingo::Symbol& atom, const Clingo::TruthValue value); + bool release_external(const Clingo::Symbol& atom); }; } // end namespace fawkes -- Fawkes Robotics Framework http://www.fawkesrobotics.org _______________________________________________ fawkes-commits mailing list fawkes-commits@lists.kbsg.rwth-aachen.de https://lists.kbsg.rwth-aachen.de/listinfo/fawkes-commits