dlvhex  2.5.0
include/dlvhex2/Rule.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 
00034 #ifndef RULE_HPP_INCLUDED__12102010
00035 #define RULE_HPP_INCLUDED__12102010
00036 
00037 #include "dlvhex2/PlatformDefinitions.h"
00038 #include "dlvhex2/Logger.h"
00039 #include "dlvhex2/ID.h"
00040 
00041 DLVHEX_NAMESPACE_BEGIN
00042 
00046 struct Rule:
00047 private ostream_printable<Rule>
00048 {
00050     IDKind kind;
00051 
00053     Tuple head;
00054 
00056     Tuple body;
00057 
00059     Tuple headGuard;
00060 
00062     Tuple bodyWeightVector;
00063 
00065     ID bound;
00066 
00068     ID weight;
00069 
00071     ID level;
00072 
00077     Tuple weakconstraintVector;
00078 
00081     Rule(IDKind kind):
00082     kind(kind), head(), headGuard(), body(), bound(ID_FAIL), weight(ID_FAIL), level(ID_FAIL)
00083         { assert(ID(kind,0).isRule()); }
00084 
00091     Rule(IDKind kind, const Tuple& head, const Tuple& body):
00092     kind(kind), head(head), body(body), headGuard(), bound(ID_FAIL), weight(ID_FAIL), level(ID_FAIL)
00093         { assert(ID(kind,0).isRule()); }
00094 
00102     Rule(IDKind kind, const Tuple& head, const Tuple& body, const Tuple& headGuard):
00103     kind(kind), head(head), body(body), headGuard(headGuard), bound(ID_FAIL), weight(ID_FAIL), level(ID_FAIL)
00104         { assert(ID(kind,0).isRule()); }
00105 
00115     Rule(IDKind kind, const Tuple& head, const Tuple& body, ID weight, ID level, Tuple weakconstraintVector):
00116     kind(kind), head(head), body(body), headGuard(), bound(ID_FAIL), weight(weight), level(level), weakconstraintVector(weakconstraintVector)
00117         { assert(ID(kind,0).isRule()); }
00118 
00129     Rule(IDKind kind, const Tuple& head, const Tuple& body, const Tuple& headGuard, ID weight, ID level, Tuple weakconstraintVector):
00130     kind(kind), head(head), body(body), headGuard(headGuard), bound(ID_FAIL), weight(weight), level(level), weakconstraintVector(weakconstraintVector)
00131         { assert(ID(kind,0).isRule()); }
00132 
00140     Rule(IDKind kind, ID weight, ID level, Tuple weakconstraintVector):
00141     kind(kind), head(), body(), headGuard(), bound(ID_FAIL), weight(weight), level(level), weakconstraintVector(weakconstraintVector)
00142         { assert(ID(kind,0).isRule()); }
00143 
00152     Rule(IDKind kind, const Tuple& head, const Tuple& body, const Tuple& bodyWeightVector, ID bound):
00153     kind(kind), head(head), body(body), headGuard(), bodyWeightVector(bodyWeightVector), bound(bound), weight(ID_FAIL), level(ID_FAIL)
00154         { assert(ID(kind,0).isWeightRule()); assert(body.size() == bodyWeightVector.size()); }
00155 
00165     Rule(IDKind kind, const Tuple& head, const Tuple& body, const Tuple& headGuard, const Tuple& bodyWeightVector, ID bound):
00166     kind(kind), head(head), body(body), headGuard(headGuard), bodyWeightVector(bodyWeightVector), bound(bound), weight(ID_FAIL), level(ID_FAIL)
00167         { assert(ID(kind,0).isWeightRule()); assert(body.size() == bodyWeightVector.size()); }
00168 
00175     inline bool isEAGuessingRule() const
00176         { return head.size() == 2 && head[0].isExternalAuxiliary() && head[1].isExternalAuxiliary(); }
00177 
00184     inline bool isEAAuxInputRule() const
00185         { return head.size() == 1 && head[0].isExternalInputAuxiliary(); }
00186 
00193     std::ostream& print(std::ostream& o) const
00194     {
00195         o << "Rule(" << printvector(head) << " <- " << printvector(body);
00196         if( weight != ID_FAIL || level != ID_FAIL )
00197             o << " [" << weight << ":" << level << "]";
00198         if ( ID(kind,0).isWeightRule() )
00199             o << "; " << printvector(bodyWeightVector) << " >= " << bound.address;
00200         return o << ")";
00201     }
00202 };
00203 
00204 DLVHEX_NAMESPACE_END
00205 #endif                           // RULE_HPP_INCLUDED__12102010
00206 
00207 // vim:expandtab:ts=4:sw=4:
00208 // mode: C++
00209 // End: