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 #ifdef HAVE_CONFIG_H 00035 #include "config.h" 00036 #endif // HAVE_CONFIG_H 00037 00038 #include "dlvhex2/DumpingEvalGraphBuilder.h" 00039 #include "dlvhex2/Logger.h" 00040 00041 #include <fstream> 00042 00043 DLVHEX_NAMESPACE_BEGIN 00044 00045 DumpingEvalGraphBuilder::DumpingEvalGraphBuilder( 00046 ProgramCtx& ctx, 00047 ComponentGraph& cg, 00048 EvalGraphT& eg, 00049 ASPSolverManager::SoftwareConfigurationPtr externalEvalConfig, 00050 const std::string& ofname): 00051 EvalGraphBuilder(ctx, cg, eg, externalEvalConfig), 00052 output(ofname.c_str(), std::ios::out | std::ios::trunc) 00053 { 00054 throw std::runtime_error("TODO revitalize this functionality as follows: record indices of components here, cg.collapseComponents must record in the component which components get into a goal component, then createEvalUnit can dump which original component indices become which units (this is the clean and only useful way to do it)"); 00055 } 00056 00057 00058 DumpingEvalGraphBuilder::~DumpingEvalGraphBuilder() 00059 { 00060 } 00061 00062 00063 DumpingEvalGraphBuilder::EvalUnit 00064 DumpingEvalGraphBuilder::createEvalUnit( 00065 const std::list<Component>& comps, const std::list<Component>& ccomps) 00066 { 00067 if( componentidx.empty() ) { 00068 ComponentGraph::ComponentIterator cit, cit_end; 00069 unsigned idx = 0; 00070 for(boost::tie(cit, cit_end) = cg.getComponents(); 00071 cit != cit_end; ++cit, ++idx) { 00072 componentidx[*cit] = idx; 00073 } 00074 } 00075 00076 std::vector<unsigned> icomps, iccomps; 00077 BOOST_FOREACH(const Component& comp, comps) { 00078 icomps.push_back(componentidx[comp]); 00079 } 00080 BOOST_FOREACH(const Component& comp, ccomps) { 00081 iccomps.push_back(componentidx[comp]); 00082 } 00083 00084 output << "collapse" << printrange(icomps, " ", " ", " "); 00085 if( !iccomps.empty() ) 00086 output << "share" << printrange(iccomps, " ", " ", " "); 00087 output << std::endl; 00088 00089 DumpingEvalGraphBuilder::EvalUnit u( 00090 EvalGraphBuilder::createEvalUnit(comps, ccomps)); 00091 00092 #ifndef NDEBUG 00093 typedef EvalGraphBuilder::ComponentGraphRest CGRest; 00094 typedef boost::graph_traits<CGRest> CGRestTraits; 00095 const CGRest& cgrest = getComponentGraphRest(); 00096 DBGLOG(DBG, "after createEvalUnit with result " << u); 00097 DBGLOG_SCOPE(DBG,"cgrest",false); 00098 CGRestTraits::vertex_iterator cit, cit_end; 00099 for(boost::tie(cit, cit_end) = boost::vertices(cgrest); 00100 cit != cit_end; ++cit) { 00101 DBGLOG(DBG,"component " << *cit << ": " << cgrest[*cit]); 00102 } 00103 #endif 00104 return u; 00105 } 00106 00107 00108 DLVHEX_NAMESPACE_END 00109 00110 00111 // vim:expandtab:ts=4:sw=4: 00112 // mode: C++ 00113 // End: