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 #ifndef _DLVHEX_ANNOTATEDGROUNDPPROGRAM_HPP_ 00038 #define _DLVHEX_ANNOTATEDGROUNDPPROGRAM_HPP_ 00039 00040 #include "dlvhex2/PlatformDefinitions.h" 00041 #include "dlvhex2/ID.h" 00042 #include "dlvhex2/Error.h" 00043 #include "dlvhex2/Registry.h" 00044 #include "dlvhex2/OrdinaryASPProgram.h" 00045 #include "dlvhex2/PredicateMask.h" 00046 #include "dlvhex2/Nogood.h" 00047 00048 #include <boost/graph/graph_traits.hpp> 00049 #include <boost/graph/adjacency_list.hpp> 00050 #include <boost/shared_ptr.hpp> 00051 00052 #include <boost/shared_ptr.hpp> 00053 #include <boost/unordered_map.hpp> 00054 00055 #include <vector> 00056 #include <list> 00057 00058 DLVHEX_NAMESPACE_BEGIN 00059 00063 class DLVHEX_EXPORT AnnotatedGroundProgram 00064 { 00065 00067 ProgramCtx* ctx; 00069 RegistryPtr reg; 00071 OrdinaryASPProgram groundProgram; 00073 std::vector<ID> dependencyIDB; 00075 bool haveGrounding; 00076 00077 // back-mapping of (ground) external auxiliaries to their nonground external atoms 00079 std::vector<ID> indexedEatoms; 00081 std::vector<boost::shared_ptr<ExternalAtomMask> > eaMasks; 00083 boost::unordered_map<IDAddress, std::vector<ID> > auxToEA; 00084 00088 SimpleNogoodContainerPtr supportSets; 00089 00091 InterpretationPtr programMask; 00092 00094 struct ProgramComponent 00095 { 00097 InterpretationConstPtr componentAtoms; 00099 OrdinaryASPProgram program; 00104 ProgramComponent(InterpretationConstPtr componentAtoms, OrdinaryASPProgram& program) : componentAtoms(componentAtoms), program(program) {} 00105 typedef boost::shared_ptr<ProgramComponent> Ptr; 00106 }; 00107 typedef ProgramComponent::Ptr ProgramComponentPtr; 00108 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, IDAddress> Graph; 00109 typedef Graph::vertex_descriptor Node; 00111 boost::unordered_map<IDAddress, Node> depNodes; 00113 Graph depGraph; 00115 std::vector<std::set<IDAddress> > depSCC; 00117 boost::unordered_map<IDAddress, int> componentOfAtom; 00119 std::vector<std::pair<IDAddress, IDAddress> > externalEdges; 00121 std::vector<bool> headCycles; 00123 InterpretationPtr headCyclicRules; 00125 std::vector<bool> eCycles; 00127 std::vector<ProgramComponentPtr> programComponents; 00128 00130 bool headCyclesTotal; 00132 bool eCyclesTotal; 00133 00134 // initialization members 00136 void createProgramMask(); 00138 void createEAMasks(); 00140 void mapAuxToEAtoms(); 00142 void initialize(); 00144 void computeAtomDependencyGraph(); 00146 void computeAdditionalDependencies(); 00148 void computeStronglyConnectedComponents(); 00150 void computeHeadCycles(); 00152 void computeECycles(); 00153 public: 00155 AnnotatedGroundProgram(); 00176 AnnotatedGroundProgram(ProgramCtx& ctx, const OrdinaryASPProgram& groundProgram, std::vector<ID> indexedEatoms = std::vector<ID>(), std::vector<ID> dependencyIDB = std::vector<ID>()); 00177 00183 AnnotatedGroundProgram(ProgramCtx& ctx, std::vector<ID> indexedEatoms); 00184 00198 void addProgram(const AnnotatedGroundProgram& other); 00199 00203 const AnnotatedGroundProgram& operator=(const AnnotatedGroundProgram& other); 00204 00208 void setIndexEAtoms(std::vector<ID> indexedEatoms); 00209 00215 bool containsHeadCycles(ID ruleID) const; 00220 int getComponentCount() const; 00226 const OrdinaryASPProgram& getProgramOfComponent(int compNr) const; 00232 InterpretationConstPtr getAtomsOfComponent(int compNr) const; 00238 bool hasHeadCycles(int compNr) const; 00244 bool hasECycles(int compNr) const; 00251 bool hasECycles(int compNr, InterpretationConstPtr intr) const; 00256 bool hasHeadCycles() const; 00261 bool hasECycles() const; 00267 bool hasECycles(InterpretationConstPtr intr) const; 00268 00273 bool mapsAux(IDAddress ida) const; 00274 typedef std::pair<IDAddress, std::vector<ID> > AuxToExternalAtoms; 00279 const boost::unordered_map<IDAddress, std::vector<ID> >& getAuxToEA() const; 00284 const std::vector<ID>& getAuxToEA(IDAddress ida) const; 00290 const boost::shared_ptr<ExternalAtomMask> getEAMask(int eaIndex) const; 00291 00296 const OrdinaryASPProgram& getGroundProgram() const; 00301 const std::vector<ID>& getIndexedEAtoms() const; 00307 ID getIndexedEAtom(int index) const; 00313 int getIndexOfEAtom(ID eatomID) const; 00318 InterpretationConstPtr getProgramMask() const; 00319 00324 void setCompleteSupportSetsForVerification(SimpleNogoodContainerPtr supportSets); 00325 00330 bool allowsForVerificationUsingCompleteSupportSets() const; 00335 SimpleNogoodContainerPtr getCompleteSupportSetsForVerification(); 00336 00345 bool verifyExternalAtomsUsingCompleteSupportSets(int eaIndex, InterpretationConstPtr interpretation, InterpretationConstPtr auxiliariesToVerify) const; 00346 }; 00347 00348 DLVHEX_NAMESPACE_END 00349 #endif // _DLVHEX_ANNOTATEDGROUNDPPROGRAM_HPP_ 00350 00351 00352 // vim:expandtab:ts=4:sw=4: 00353 // mode: C++ 00354 // End: