dlvhex  2.5.0
include/dlvhex2/GuessAndCheckModelGenerator.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 
00036 #ifndef GUESSANDCHECK_MODEL_GENERATOR_HPP_INCLUDED__09112010
00037 #define GUESSANDCHECK_MODEL_GENERATOR_HPP_INCLUDED__09112010
00038 
00039 #include "dlvhex2/PlatformDefinitions.h"
00040 #include "dlvhex2/fwd.h"
00041 #include "dlvhex2/FLPModelGeneratorBase.h"
00042 #include "dlvhex2/ID.h"
00043 #include "dlvhex2/ComponentGraph.h"
00044 #include "dlvhex2/PredicateMask.h"
00045 
00046 #include <boost/shared_ptr.hpp>
00047 
00048 DLVHEX_NAMESPACE_BEGIN
00049 
00051 class GuessAndCheckModelGeneratorFactory:
00052 public FLPModelGeneratorFactoryBase,
00053 public ostream_printable<GuessAndCheckModelGeneratorFactory>
00054 {
00055     // types
00056     public:
00057         friend class GuessAndCheckModelGenerator;
00058         typedef ComponentGraph::ComponentInfo ComponentInfo;
00059 
00060         // storage
00061     protected:
00063         ASPSolverManager::SoftwareConfigurationPtr externalEvalConfig;
00065         ProgramCtx& ctx;
00067         ComponentInfo ci;        // should be a reference, but there is currently a bug in the copy constructor of ComponentGraph: it seems that the component info is shared between different copies of a component graph, hence it is deallocated when one of the copies dies.
00068         WARNING("TODO see comment above about ComponentInfo copy construction bug")
00069 
00070         
00071             std::vector<ID> outerEatoms;
00072 
00073         // methods
00074     public:
00081         GuessAndCheckModelGeneratorFactory(
00082             ProgramCtx& ctx, const ComponentInfo& ci,
00083             ASPSolverManager::SoftwareConfigurationPtr externalEvalConfig);
00085         virtual ~GuessAndCheckModelGeneratorFactory() {}
00086 
00092         virtual ModelGeneratorPtr createModelGenerator(InterpretationConstPtr input);
00093 
00096         virtual std::ostream& print(std::ostream& o) const;
00097 
00101         virtual std::ostream& print(std::ostream& o, bool verbose) const;
00102 };
00103 
00104 class GuessAndCheckModelGenerator:
00105 public FLPModelGeneratorBase,
00106 public ostream_printable<GuessAndCheckModelGenerator>
00107 {
00108     // types
00109     public:
00110         typedef GuessAndCheckModelGeneratorFactory Factory;
00111 
00112         // storage
00113     protected:
00114         // we store the factory again, because the base class stores it with the base type only!
00116         Factory& factory;
00117 
00119         InterpretationConstPtr postprocessedInput;
00121         InterpretationPtr mask;
00122 
00124         ASPSolverManager::ResultsPtr guessres;
00125 
00126         // members
00127     public:
00133         GuessAndCheckModelGenerator(Factory& factory, InterpretationConstPtr input);
00134 
00138         virtual ~GuessAndCheckModelGenerator() {}
00139 
00140         // generate and return next model, return null after last model
00141         virtual InterpretationPtr generateNextModel();
00142 };
00143 
00144 DLVHEX_NAMESPACE_END
00145 #endif                           // GUESSANDCHECK_MODEL_GENERATOR_HPP_INCLUDED__09112010
00146 
00147 // vim:expandtab:ts=4:sw=4:
00148 // mode: C++
00149 // End: