dlvhex  2.5.0
include/dlvhex2/ModelGenerator.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 
00037 #ifndef MODEL_GENERATOR_HPP_INCLUDED__30082010
00038 #define MODEL_GENERATOR_HPP_INCLUDED__30082010
00039 
00040 #ifdef HAVE_CONFIG_H
00041 #include "config.h"
00042 #endif                           // HAVE_CONFIG_H
00043 
00044 #include "dlvhex2/PlatformDefinitions.h"
00045 #include "dlvhex2/Logger.h"
00046 #include "dlvhex2/Printhelpers.h"
00047 
00048 #include <boost/shared_ptr.hpp>
00049 #include <boost/concept/assert.hpp>
00050 #include <boost/concept_check.hpp>
00051 
00052 #include <ostream>
00053 
00054 DLVHEX_NAMESPACE_BEGIN
00055 
00057 class DLVHEX_EXPORT InterpretationBase:
00058 public ostream_printable<InterpretationBase>
00059 
00060 {
00061     public:
00062         // debug
00063         std::ostream& print(std::ostream& o) const
00064             { return o << "InterpretationBase::print() not overloaded"; }
00065 };
00066 
00067 class Nogood; // fwd definition
00077 template<typename InterpretationT>
00078 class ModelGeneratorBase:
00079 public ostream_printable<ModelGeneratorBase<InterpretationT> >
00080 {
00081     // types
00082     public:
00083         BOOST_CONCEPT_ASSERT((boost::Convertible<InterpretationT, InterpretationBase>));
00084 
00085         typedef InterpretationT Interpretation;
00086         // those typedefs are just to remove the 'typename's from the interface
00087         typedef typename Interpretation::ConstPtr InterpretationConstPtr;
00088         typedef typename Interpretation::Ptr InterpretationPtr;
00089         typedef boost::shared_ptr<ModelGeneratorBase<Interpretation> > Ptr;
00090 
00091         // storage
00092     protected:
00094         InterpretationConstPtr input;
00095 
00096         // members
00097     public:
00100         ModelGeneratorBase(InterpretationConstPtr input):
00101         input(input) {}
00103         virtual ~ModelGeneratorBase() {}
00104 
00107         virtual InterpretationPtr generateNextModel() = 0;
00108 
00112         virtual const Nogood* getInconsistencyCause() { return 0; }
00113         
00119         virtual void addNogood(const Nogood* ng) {}
00120 
00121         // debug output
00122         virtual std::ostream& print(std::ostream& o) const
00123             { return o << "ModelGeneratorBase::print() not overloaded"; }
00124 };
00125 
00130 template<typename InterpretationT>
00131 class ModelGeneratorFactoryBase:
00132 public ostream_printable<ModelGeneratorFactoryBase<InterpretationT> >
00133 {
00134     // types
00135     public:
00136         typedef InterpretationT Interpretation;
00137 
00138     public:
00139         typedef boost::shared_ptr<
00140             ModelGeneratorFactoryBase<InterpretationT> > Ptr;
00141 
00142         typedef ModelGeneratorBase<InterpretationT> MyModelGeneratorBase;
00143         typedef typename MyModelGeneratorBase::Ptr ModelGeneratorPtr;
00144         typedef typename MyModelGeneratorBase::InterpretationConstPtr
00145             InterpretationConstPtr;
00146 
00147         // methods
00148     public:
00150         ModelGeneratorFactoryBase() {}
00152         virtual ~ModelGeneratorFactoryBase() {}
00153         
00158         virtual void addInconsistencyCauseFromSuccessor(const Nogood* cause) {}
00159 
00162         virtual ModelGeneratorPtr createModelGenerator(
00163             InterpretationConstPtr input) = 0;
00164         virtual std::ostream& print(std::ostream& o) const
00165             { return o << "ModelGeneratorFactoryBase::print() not overloaded"; }
00166 };
00167 
00170 template<typename InterpretationT>
00171 struct EvalUnitModelGeneratorFactoryProperties:
00172 public ostream_printable<EvalUnitModelGeneratorFactoryProperties<InterpretationT> >
00173 {
00174     BOOST_CONCEPT_ASSERT((boost::Convertible<InterpretationT, InterpretationBase>));
00175     typedef InterpretationT Interpretation;
00176 
00177     // aka model generator factory
00178     typename ModelGeneratorFactoryBase<InterpretationT>::Ptr
00179         mgf;                     // aka model generator factory
00180 
00181     public:
00182         virtual std::ostream& print(std::ostream& o) const
00183         {
00184             if( mgf )
00185                 return o << *mgf;
00186             else
00187                 return o << "(no ModelGeneratorFactory)";
00188         }
00189 };
00190 
00191 DLVHEX_NAMESPACE_END
00192 #endif                           //MODEL_GENERATOR_HPP_INCLUDED__30082010
00193 
00194 // vim:expandtab:ts=4:sw=4:
00195 // mode: C++
00196 // End: