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 00034 #ifndef MODEL_BUILDER_HPP_INCLUDED__18012011 00035 #define MODEL_BUILDER_HPP_INCLUDED__18012011 00036 00037 #include "dlvhex2/PlatformDefinitions.h" 00038 #include "EvalGraph.h" 00039 #include "ModelGraph.h" 00040 00041 DLVHEX_NAMESPACE_BEGIN 00042 00044 template<typename EvalGraphT> 00045 struct ModelBuilderConfig 00046 { 00049 ModelBuilderConfig(EvalGraphT& eg): 00050 eg(eg), redundancyElimination(true), constantSpace(false) {} 00052 EvalGraphT& eg; 00054 bool redundancyElimination; 00056 bool constantSpace; 00057 }; 00058 00060 template<typename EvalGraphT> 00061 class ModelBuilder 00062 { 00063 // types 00064 public: 00065 typedef ModelBuilder<EvalGraphT> 00066 Self; 00067 00068 // concept check: EvalGraphT must be an eval graph 00069 BOOST_CONCEPT_ASSERT((boost::Convertible< 00070 EvalGraphT, 00071 EvalGraph< 00072 typename EvalGraphT::EvalUnitPropertyBase, 00073 typename EvalGraphT::EvalUnitDepPropertyBase> >)); 00074 typedef EvalGraphT 00075 MyEvalGraph; 00076 typedef typename MyEvalGraph::EvalUnit 00077 EvalUnit; 00078 00079 // concept check: eval graph must store model generator factory properties for units 00080 BOOST_CONCEPT_ASSERT((boost::Convertible< 00081 typename EvalGraphT::EvalUnitPropertyBundle, 00082 EvalUnitModelGeneratorFactoryProperties< 00083 typename EvalGraphT::EvalUnitPropertyBundle::Interpretation> >)); 00084 typedef typename EvalGraphT::EvalUnitPropertyBundle 00085 EvalUnitPropertyBundle; 00086 // from eval unit properties we get the interpretation type 00087 typedef typename EvalUnitPropertyBundle::Interpretation 00088 Interpretation; 00089 typedef typename EvalUnitPropertyBundle::Interpretation::Ptr 00090 InterpretationPtr; 00091 00093 struct ModelProperties 00094 { 00096 InterpretationPtr interpretation; 00097 00098 // for input models only: 00099 00101 bool dummy; 00103 bool childModelsGenerated; 00104 00106 ModelProperties(); 00110 std::ostream& print(std::ostream& o) const; 00111 }; 00112 00113 typedef ModelGraph<EvalGraphT, ModelProperties> 00114 MyModelGraph; 00115 typedef typename MyModelGraph::Model 00116 Model; 00117 typedef boost::optional<Model> 00118 OptionalModel; 00119 00120 // members 00121 protected: 00123 EvalGraphT& eg; 00125 MyModelGraph mg; 00126 00127 // methods 00128 public: 00131 ModelBuilder(ModelBuilderConfig<EvalGraphT>& cfg): 00132 eg(cfg.eg), mg(cfg.eg) {} 00134 virtual ~ModelBuilder() {} 00137 inline EvalGraphT& getEvalGraph() { return eg; } 00140 inline MyModelGraph& getModelGraph() { return mg; } 00141 00145 virtual OptionalModel getNextIModel(EvalUnit u) = 0; 00146 00150 virtual OptionalModel getNextOModel(EvalUnit u) = 0; 00151 00152 // debugging methods 00155 virtual void printEvalGraphModelGraph(std::ostream& o) = 0; 00158 virtual void printModelBuildingPropertyMap(std::ostream& o) = 0; 00159 }; 00160 00161 // impl 00162 00163 template<typename EvalGraphT> 00164 ModelBuilder<EvalGraphT>::ModelProperties::ModelProperties(): 00165 interpretation(), 00166 dummy(false), 00167 childModelsGenerated(false) 00168 { 00169 } 00170 00171 00172 template<typename EvalGraphT> 00173 std::ostream& 00174 ModelBuilder<EvalGraphT>::ModelProperties::print(std::ostream& o) const 00175 { 00176 if( dummy ) 00177 o << "dummy "; 00178 if( childModelsGenerated ) 00179 o << "childModelsGenerated "; 00180 o << 00181 "interpretation=" << printptr(interpretation); 00182 if( interpretation ) 00183 o << *interpretation; 00184 return o; 00185 } 00186 00187 00188 DLVHEX_NAMESPACE_END 00189 #endif // MODEL_BUILDER_HPP_INCLUDED__18012011 00190 00191 // vim:expandtab:ts=4:sw=4: 00192 // mode: C++ 00193 // End: