dlvhex
2.5.0
|
00001 /* dlvhex -- Answer-Set Programming with external interfaces. 00002 * Copyright (C) 2005-2007 Roman Schindlauer 00003 * Copyright (C) 2006-2015 Thomas Krennwallner 00004 * Copyright (C) 2009-2016 Peter Schüller 00005 * Copyright (C) 2011-2016 Christoph Redl 00006 * Copyright (C) 2015-2016 Tobias Kaminski 00007 * Copyright (C) 2015-2016 Antonius Weinzierl 00008 * 00009 * This file is part of dlvhex. 00010 * 00011 * dlvhex is free software; you can redistribute it and/or modify it 00012 * under the terms of the GNU Lesser General Public License as 00013 * published by the Free Software Foundation; either version 2.1 of 00014 * the License, or (at your option) any later version. 00015 * 00016 * dlvhex is distributed in the hope that it will be useful, but 00017 * WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with dlvhex; if not, write to the Free Software 00023 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00024 * 02110-1301 USA. 00025 */ 00026 00037 #if !defined(_DLVHEX_GENUINESOLVER_HPP) 00038 #define _DLVHEX_GENUINESOLVER_HPP 00039 00040 #include "dlvhex2/PlatformDefinitions.h" 00041 #include "dlvhex2/ASPSolverManager.h" 00042 #include "dlvhex2/Error.h" 00043 00044 #include "dlvhex2/OrdinaryASPProgram.h" 00045 #include "dlvhex2/AnnotatedGroundProgram.h" 00046 #include "dlvhex2/OrdinaryASPSolver.h" 00047 00048 #include "dlvhex2/Nogood.h" 00049 00050 #include <boost/shared_ptr.hpp> 00051 #include <boost/scoped_ptr.hpp> 00052 #include <vector> 00053 00054 DLVHEX_NAMESPACE_BEGIN 00055 00059 class DLVHEX_EXPORT PropagatorCallback 00060 { 00061 public: 00071 virtual void propagate(InterpretationConstPtr partialInterpretation, InterpretationConstPtr assigned, InterpretationConstPtr changed) = 0; 00072 }; 00073 00077 class DLVHEX_EXPORT GenuineGrounder 00078 { 00079 public: 00080 virtual const OrdinaryASPProgram& getGroundProgram() = 0; 00081 00082 typedef boost::shared_ptr<GenuineGrounder> Ptr; 00083 typedef boost::shared_ptr<const GenuineGrounder> ConstPtr; 00084 00094 static Ptr getInstance(ProgramCtx& ctx, const OrdinaryASPProgram& program, InterpretationConstPtr frozen = InterpretationConstPtr()); 00095 }; 00096 00097 typedef GenuineGrounder::Ptr GenuineGrounderPtr; 00098 typedef GenuineGrounder::ConstPtr GenuineGrounderConstPtr; 00099 00103 class DLVHEX_EXPORT GenuineGroundSolver : virtual public NogoodContainer, public OrdinaryASPSolver 00104 { 00105 public: 00110 virtual std::string getStatistics() = 0; 00111 00118 virtual void setOptimum(std::vector<int>& optimum) = 0; 00119 00120 // inherited from OrdinaryASPSolver 00121 virtual InterpretationPtr getNextModel() = 0; 00122 00128 virtual int getModelCount() = 0; 00129 00136 virtual void restartWithAssumptions(const std::vector<ID>& assumptions) = 0; 00137 00144 virtual void addPropagator(PropagatorCallback* pb) = 0; 00145 00150 virtual void removePropagator(PropagatorCallback* pb) = 0; 00151 00159 virtual void addProgram(const AnnotatedGroundProgram& program, InterpretationConstPtr frozen = InterpretationConstPtr()) = 0; 00160 00187 virtual Nogood getInconsistencyCause(InterpretationConstPtr explanationAtoms) = 0; 00188 00196 virtual void addNogoodSet(const NogoodSet& ns, InterpretationConstPtr frozen = InterpretationConstPtr()) = 0; 00197 00198 typedef boost::shared_ptr<GenuineGroundSolver> Ptr; 00199 typedef boost::shared_ptr<const GenuineGroundSolver> ConstPtr; 00200 00213 static Ptr getInstance(ProgramCtx& ctx, const OrdinaryASPProgram& program, InterpretationConstPtr frozen = InterpretationConstPtr(), bool minCheck = true); 00214 00227 static Ptr getInstance(ProgramCtx& ctx, const AnnotatedGroundProgram& program, InterpretationConstPtr frozen = InterpretationConstPtr(), bool minCheck = true); 00228 }; 00229 00230 typedef GenuineGroundSolver::Ptr GenuineGroundSolverPtr; 00231 typedef GenuineGroundSolver::ConstPtr GenuineGroundSolverConstPtr; 00232 00236 class DLVHEX_EXPORT GenuineSolver : public GenuineGrounder, public GenuineGroundSolver 00237 { 00238 private: 00240 GenuineGrounderPtr grounder; 00242 GenuineGroundSolverPtr solver; 00244 OrdinaryASPProgram gprog; 00245 00252 GenuineSolver(GenuineGrounderPtr grounder, GenuineGroundSolverPtr solver, OrdinaryASPProgram gprog) : grounder(grounder), solver(solver), gprog(gprog){} 00253 public: 00258 const OrdinaryASPProgram& getGroundProgram(); 00259 00260 // inherited 00261 std::string getStatistics(); 00262 void setOptimum(std::vector<int>& optimum); 00263 InterpretationPtr getNextModel(); 00264 int getModelCount(); 00265 void addNogood(Nogood ng); 00266 void restartWithAssumptions(const std::vector<ID>& assumptions); 00267 void addPropagator(PropagatorCallback* pb); 00268 void removePropagator(PropagatorCallback* pb); 00269 void addProgram(const AnnotatedGroundProgram& program, InterpretationConstPtr frozen = InterpretationConstPtr()); 00270 Nogood getInconsistencyCause(InterpretationConstPtr explanationAtoms); 00271 void addNogoodSet(const NogoodSet& ns, InterpretationConstPtr frozen = InterpretationConstPtr()); 00272 00277 inline GenuineGrounderPtr getGenuineGrounder(){ return grounder; } 00278 00283 inline GenuineGroundSolverPtr getGenuineGroundSolver(){ return solver; } 00284 00285 typedef boost::shared_ptr<GenuineSolver> Ptr; 00286 typedef boost::shared_ptr<const GenuineSolver> ConstPtr; 00287 00288 // inherited 00289 static Ptr getInstance(ProgramCtx& ctx, const OrdinaryASPProgram& p, InterpretationConstPtr frozen = InterpretationConstPtr(), bool minCheck = true); 00290 }; 00291 00292 typedef GenuineSolver::Ptr GenuineSolverPtr; 00293 typedef GenuineSolver::ConstPtr GenuineSolverConstPtr; 00294 00295 DLVHEX_NAMESPACE_END 00296 #endif // _DLVHEX_GENUINESOLVER_H 00297 00298 00299 // vim:expandtab:ts=4:sw=4: 00300 // mode: C++ 00301 // End: