|
From: <chr...@us...> - 2012-02-24 20:00:38
|
Revision: 3571
http://dlvhex.svn.sourceforge.net/dlvhex/?rev=3571&view=rev
Author: chrisr86
Date: 2012-02-24 20:00:32 +0000 (Fri, 24 Feb 2012)
Log Message:
-----------
add property "antimonotonic"
Modified Paths:
--------------
dlvhex/branches/dlvhex-refactoring/examples/setminus.hex
dlvhex/branches/dlvhex-refactoring/include/dlvhex2/ExtSourceProperties.h
dlvhex/branches/dlvhex-refactoring/include/dlvhex2/HexGrammar.tcc
dlvhex/branches/dlvhex-refactoring/include/dlvhex2/PluginInterface.h
dlvhex/branches/dlvhex-refactoring/src/PluginInterface.cpp
dlvhex/branches/dlvhex-refactoring/src/dlvhex.cpp
Modified: dlvhex/branches/dlvhex-refactoring/examples/setminus.hex
===================================================================
--- dlvhex/branches/dlvhex-refactoring/examples/setminus.hex 2012-02-24 13:38:48 UTC (rev 3570)
+++ dlvhex/branches/dlvhex-refactoring/examples/setminus.hex 2012-02-24 20:00:32 UTC (rev 3571)
@@ -5,6 +5,6 @@
domain(e).
domain(f).
-nsel(X) :- domain(X), &testSetMinusNogoodBasedLearning[domain, sel](X).
-sel(X) :- domain(X), &testSetMinusNogoodBasedLearning[domain, nsel](X).
+nsel(X) :- domain(X), &testSetMinus[domain, sel](X)<monotonic domain,antimonotonic sel>.
+sel(X) :- domain(X), &testSetMinus[domain, nsel](X)<monotonic domain,antimonotonic nsel>.
:- sel(X), sel(Y), sel(Z), X != Y, X != Z, Y != Z.
Modified: dlvhex/branches/dlvhex-refactoring/include/dlvhex2/ExtSourceProperties.h
===================================================================
--- dlvhex/branches/dlvhex-refactoring/include/dlvhex2/ExtSourceProperties.h 2012-02-24 13:38:48 UTC (rev 3570)
+++ dlvhex/branches/dlvhex-refactoring/include/dlvhex2/ExtSourceProperties.h 2012-02-24 20:00:32 UTC (rev 3571)
@@ -45,6 +45,8 @@
enum Type{
MONOTONIC,
NONMONOTONIC,
+ ANTIMONOTONIC,
+ NONANTIMONOTONIC,
FUNCTIONAL,
NONFUNCTIONAL,
FULLYLINEAR,
@@ -62,6 +64,7 @@
struct ExtSourceProperties
{
std::vector<int> monotonicInputPredicates;
+ std::vector<int> antimonotonicInputPredicates;
bool functional;
bool fullylinear;
Modified: dlvhex/branches/dlvhex-refactoring/include/dlvhex2/HexGrammar.tcc
===================================================================
--- dlvhex/branches/dlvhex-refactoring/include/dlvhex2/HexGrammar.tcc 2012-02-24 13:38:48 UTC (rev 3570)
+++ dlvhex/branches/dlvhex-refactoring/include/dlvhex2/HexGrammar.tcc 2012-02-24 20:00:32 UTC (rev 3571)
@@ -563,6 +563,44 @@
if (!found) throw SyntaxError("Property refers to invalid input parameter");
}
break;
+ case ExtSourceProperty::ANTIMONOTONIC:
+ if (prop.param == ID_FAIL){
+ DBGLOG(DBG, "External Atom is antimonotonic in all input parameters");
+ for (int i = 0; i < atom.inputs.size(); ++i){
+ atom.prop.antimonotonicInputPredicates.push_back(i);
+ }
+ }else{
+ bool found = false;
+ for (int i = 0; i < atom.inputs.size(); ++i){
+ if (atom.inputs[i] == prop.param){
+ DBGLOG(DBG, "External Atom is antimonotonic in parameter " << i);
+ atom.prop.antimonotonicInputPredicates.push_back(i);
+ found = true;
+ break;
+ }
+ }
+ if (!found) throw SyntaxError("Property refers to invalid input parameter");
+ }
+ break;
+ case ExtSourceProperty::NONANTIMONOTONIC:
+ if (prop.param == ID_FAIL){
+ DBGLOG(DBG, "External Atom is nonmonotonic in all input parameters");
+ atom.prop.antimonotonicInputPredicates.clear();
+ }else{
+ bool found = false;
+ for (int i = 0; i < atom.inputs.size(); ++i){
+ if (atom.inputs[i] == prop.param){
+ DBGLOG(DBG, "External Atom is nonantimonotonic in parameter " << i);
+ if (std::find(atom.prop.antimonotonicInputPredicates.begin(), atom.prop.antimonotonicInputPredicates.end(), i) != atom.prop.antimonotonicInputPredicates.end()){
+ atom.prop.antimonotonicInputPredicates.erase(std::find(atom.prop.antimonotonicInputPredicates.begin(), atom.prop.antimonotonicInputPredicates.end(), i));
+ }
+ found = true;
+ break;
+ }
+ }
+ if (!found) throw SyntaxError("Property refers to invalid input parameter");
+ }
+ break;
case ExtSourceProperty::FULLYLINEAR:
DBGLOG(DBG, "External Atom is fully linear");
atom.prop.fullylinear = true;
@@ -635,6 +673,10 @@
target = ExtSourceProperty(ExtSourceProperty::MONOTONIC, boost::fusion::at_c<1>(source));
}else if (boost::fusion::at_c<0>(source) == "nonmonotonic"){
target = ExtSourceProperty(ExtSourceProperty::NONMONOTONIC, boost::fusion::at_c<1>(source));
+ }else if (boost::fusion::at_c<0>(source) == "antimonotonic"){
+ target = ExtSourceProperty(ExtSourceProperty::ANTIMONOTONIC, boost::fusion::at_c<1>(source));
+ }else if (boost::fusion::at_c<0>(source) == "nonantimonotonic"){
+ target = ExtSourceProperty(ExtSourceProperty::NONANTIMONOTONIC, boost::fusion::at_c<1>(source));
}else if (boost::fusion::at_c<0>(source) == "fullylinear"){
target = ExtSourceProperty(ExtSourceProperty::FULLYLINEAR, boost::fusion::at_c<1>(source));
}else{
Modified: dlvhex/branches/dlvhex-refactoring/include/dlvhex2/PluginInterface.h
===================================================================
--- dlvhex/branches/dlvhex-refactoring/include/dlvhex2/PluginInterface.h 2012-02-24 13:38:48 UTC (rev 3570)
+++ dlvhex/branches/dlvhex-refactoring/include/dlvhex2/PluginInterface.h 2012-02-24 20:00:32 UTC (rev 3571)
@@ -975,6 +975,12 @@
{ return std::find(prop.monotonicInputPredicates.begin(), prop.monotonicInputPredicates.end(), parameterIndex) != prop.monotonicInputPredicates.end(); }
/**
+ * @return antimonotonicity on parameter level
+ */
+ bool isAntimonotonic(const ExtSourceProperties& prop, int parameterIndex) const
+ { return std::find(prop.antimonotonicInputPredicates.begin(), prop.antimonotonicInputPredicates.end(), parameterIndex) != prop.antimonotonicInputPredicates.end(); }
+
+ /**
* @return functional
*/
bool isFunctional(const ExtSourceProperties& prop) const
Modified: dlvhex/branches/dlvhex-refactoring/src/PluginInterface.cpp
===================================================================
--- dlvhex/branches/dlvhex-refactoring/src/PluginInterface.cpp 2012-02-24 13:38:48 UTC (rev 3570)
+++ dlvhex/branches/dlvhex-refactoring/src/PluginInterface.cpp 2012-02-24 20:00:32 UTC (rev 3571)
@@ -497,10 +497,20 @@
// find the parameter index of this atom
int index = query.inputPredicateTable.find(pred)->second;
- // for nonmonotonic parameters we need the positive and negative input, for monotonic ones the positive input suffices
- if (query.interpretation->getFact(*en) || !isMonotonic(prop, index) || !ctx->config.getOption("ExternalLearningMonotonicity")){
- extNgInput.insert(nogoods->createLiteral(*en, query.interpretation->getFact(*en)));
+ // positive atoms are only required for non-antimonotonic input parameters
+ // negative atoms are only required for non-monotonic input parameters
+ if (query.interpretation->getFact(*en)){
+ // positive
+ if (!isAntimonotonic(prop, index) || !ctx->config.getOption("ExternalLearningMonotonicity")){
+ extNgInput.insert(nogoods->createLiteral(*en, query.interpretation->getFact(*en)));
+ }
+ }else{
+ // negative
+ if (!isMonotonic(prop, index) || !ctx->config.getOption("ExternalLearningMonotonicity")){
+ extNgInput.insert(nogoods->createLiteral(*en, query.interpretation->getFact(*en)));
+ }
}
+
en++;
}
Modified: dlvhex/branches/dlvhex-refactoring/src/dlvhex.cpp
===================================================================
--- dlvhex/branches/dlvhex-refactoring/src/dlvhex.cpp 2012-02-24 13:38:48 UTC (rev 3570)
+++ dlvhex/branches/dlvhex-refactoring/src/dlvhex.cpp 2012-02-24 20:00:32 UTC (rev 3571)
@@ -140,12 +140,10 @@
// 123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-
out << " -- Parse from stdin." << std::endl
// << " --instantiate Generate ground program without evaluating (only useful with --genuinesolver)" << std::endl
-// << " --genuinesolver[=internal,clingo]" << std::endl
-// << " Use embedded solver and grounder (implementation from scratch vs. clingo)" << std::endl
<< " --extlearn[=eabehavior,monotonicity,functionality,user,partial]" << std::endl
<< " Learn nogoods from external atom evaluation (only useful with --solver=genuineii or --solver=genuinegi)" << std::endl
<< " eabehavior: Apply generic rules to learn input-output behavior" << std::endl
- << " monotonicity: Apply special rules for monotonic external atoms (only useful with eabehavior)" << std::endl
+ << " monotonicity: Apply special rules for monotonic and antimonotonic external atoms (only useful with eabehavior)" << std::endl
<< " functionality: Apply special rules for functional external atoms" << std::endl
<< " linear: Apply special rules for external atoms which are linear in all(!) predicate parameters" << std::endl
<< " user: Apply user-defined rules for nogood learning" << std::endl
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|