dlvhex  2.5.0
include/dlvhex2/FLPModelGeneratorBase.h
Go to the documentation of this file.
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 
00035 #ifndef FLP_MODEL_GENERATOR_BASE_HPP_INCLUDED__09112010
00036 #define FLP_MODEL_GENERATOR_BASE_HPP_INCLUDED__09112010
00037 
00038 #include "dlvhex2/PlatformDefinitions.h"
00039 #include "dlvhex2/fwd.h"
00040 #include "dlvhex2/BaseModelGenerator.h"
00041 #include "dlvhex2/AnnotatedGroundProgram.h"
00042 
00043 #include <boost/unordered_map.hpp>
00044 
00045 DLVHEX_NAMESPACE_BEGIN
00046 
00049 class DLVHEX_EXPORT FLPModelGeneratorFactoryBase:
00050 public BaseModelGeneratorFactory
00051 {
00052     public:
00053         FLPModelGeneratorFactoryBase(ProgramCtx& ctx);
00054         virtual ~FLPModelGeneratorFactoryBase() {}
00055 
00056     protected:
00057         // data
00059         ProgramCtx& ctx;
00060 
00061         // for getting auxiliaries and registering FLP replacements
00063         RegistryPtr reg;
00064 
00069         std::vector<ID> idb;
00070 
00072         std::vector<ID> innerEatoms;
00073 
00077         std::vector<ID> gidb;
00078 
00080         std::vector<ID> xidb;
00081 
00083         std::vector<ID> deidb;
00085         std::vector<ID> deidbInnerEatoms;
00086 
00087         // xidb rewritten for FLP calculation
00089         std::vector<ID> xidbflphead;
00091         std::vector<ID> xidbflpbody;
00092 
00093         // incrementally updated bitmask for guessed eatom replacement predicates
00094         // (positive and negative, respectively)
00096         PredicateMask gpMask;
00098         PredicateMask gnMask;
00099 
00101         PredicateMask fMask;
00102 
00103     protected:
00106         void createEatomGuessingRules(const ProgramCtx& ctx);
00112         ID createEatomGuessingRule(const ProgramCtx& ctx, ID ruleID, ID litID);
00113 
00121         void createFLPRules();
00122 
00127         void computeCyclicInputPredicates(
00128             RegistryPtr reg,
00129             ProgramCtx& ctx,
00130             const std::vector<ID>& idb);
00131 
00132         friend class FLPModelGeneratorBase;
00133 };
00134 
00135 //
00136 // the flp model generator base class (always refers to a factory which prepares the rewritten rules)
00137 //
00138 class DLVHEX_EXPORT FLPModelGeneratorBase:
00139 public BaseModelGenerator
00140 {
00141     // members
00142     public:
00148         FLPModelGeneratorBase(FLPModelGeneratorFactoryBase& factory, InterpretationConstPtr input);
00150         virtual ~FLPModelGeneratorBase() {}
00151 
00152     protected:
00153         // the factory storing our flp rewriting and external atom guessing and shared bitmasks
00155         FLPModelGeneratorFactoryBase& factory;
00156 
00158         AnnotatedGroundProgram annotatedGroundProgram;
00159     protected:
00167         virtual bool isCompatibleSet(
00168             InterpretationConstPtr candidateCompatibleSet,
00169             InterpretationConstPtr postprocessedInput,
00170             ProgramCtx& ctx,
00171             SimpleNogoodContainerPtr nc);
00172 
00181         template<typename OrdinaryASPSolverT>
00182             bool isSubsetMinimalFLPModel(
00183             InterpretationConstPtr compatibleSet,
00184             InterpretationConstPtr postprocessedInput,
00185             ProgramCtx& ctx,
00186             SimpleNogoodContainerPtr ngc = SimpleNogoodContainerPtr()
00187             );
00188 
00198         Nogood getFLPNogood(
00199             ProgramCtx& ctx,
00200             const OrdinaryASPProgram& groundProgram,
00201             InterpretationConstPtr compatibleSet,
00202             InterpretationConstPtr projectedCompatibleSet,
00203             InterpretationConstPtr smallerFLPModel
00204             );
00205 
00215         void computeShadowAndUnfoundedPredicates(
00216             RegistryPtr reg,
00217             InterpretationConstPtr edb,
00218             const std::vector<ID>& idb,
00219             std::map<ID, std::pair<int, ID> >& shadowPredicates,
00220             std::map<ID, std::pair<int, ID> >& unfoundedPredicates,
00221             std::string& shadowPostfix,
00222             std::string& unfoundedPostfix
00223             );
00224 
00232         void addShadowInterpretation(
00233             RegistryPtr reg,
00234             std::map<ID, std::pair<int, ID> >& shadowPredicates,
00235             InterpretationConstPtr input,
00236             InterpretationPtr output);
00237 
00249         void createMinimalityRules(
00250             RegistryPtr reg,
00251             std::map<ID, std::pair<int, ID> >& shadowPredicates,
00252             std::string& shadowPostfix,
00253             std::vector<ID>& idb);
00254 
00270         void createFoundingRules(
00271             RegistryPtr reg,
00272             std::map<ID, std::pair<int, ID> >& shadowPredicates,
00273             std::map<ID, std::pair<int, ID> >& unfoundedPredicates,
00274             std::vector<ID>& idb);
00275 };
00276 
00277 DLVHEX_NAMESPACE_END
00278 
00279 #include "dlvhex2/FLPModelGeneratorBase.tcc"
00280 #endif                           // FLP_MODEL_GENERATOR_BASE_HPP_INCLUDED__09112010
00281 
00282 // vim:expandtab:ts=4:sw=4:
00283 // mode: C++
00284 // End: