From 2ebe03451b410afabcc3a8bac3e2a7b0950d444d Mon Sep 17 00:00:00 2001 From: samidh talsania Date: Mon, 26 Dec 2016 12:52:30 -0700 Subject: [PATCH] Fixed incorrect lpmln2wc translation of weighted facts. Reinstated the 10000 multiplier. --- src/src/MVSMParserGrammar.cpp | 203 +++++++++++++++++++++++++--------- src/src/MVSMParserGrammar.y | 181 +++++++++++++++++++++++------- 2 files changed, 287 insertions(+), 97 deletions(-) diff --git a/src/src/MVSMParserGrammar.cpp b/src/src/MVSMParserGrammar.cpp index 937a318..4ef2453 100644 --- a/src/src/MVSMParserGrammar.cpp +++ b/src/src/MVSMParserGrammar.cpp @@ -1892,11 +1892,18 @@ static void yy_reduce( uniqueSetStr.pop_back(); uniqueSetStr = "," + uniqueSetStr; } + std::string temp = yygotominor.yy16->getExtra(tree->variables); + if(temp.length() > 0){ + temp = ", "+ temp; + } + + string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(yymsp[-1].minor.yy0->toString())* 1)) + uniqueSetStr + ")"; std::cout << unsatString << " :- " << "not " << yygotominor.yy16->toString(tree->domainList) + << temp <toString())* 1)) @@ -1924,10 +1933,10 @@ static void yy_reduce( } delete yymsp[0].minor.yy92; } -#line 1928 "MVSMParserGrammar.c" +#line 1937 "MVSMParserGrammar.c" break; case 57: /* predicate ::= number NEGATION NEGATION literal */ -#line 1043 "MVSMParserGrammar.y" +#line 1052 "MVSMParserGrammar.y" { yygotominor.yy16 = new Predicate; *yygotominor.yy16 = yymsp[0].minor.yy92->getPredicate(); @@ -1938,18 +1947,37 @@ static void yy_reduce( cout<toString(yymsp[-3].minor.yy0->toString()+SPACE, false); } else if(tree->outputType == OutputType::OUTPUT_ASP){ - std::string str = yygotominor.yy16->toString(":~ not ", false); - std::string temp = yygotominor.yy16->getExtra(tree->variables); - if(temp.length() > 0) - str += ","; - str += temp; - std::string constants = yygotominor.yy16->getExtraConstants(); - if (constants.length() > 0) - { - constants = "," + constants; - } - - std::set uniqueSet = tree->findVariables(str); + // std::string str = yygotominor.yy16->toString(":~ not ", false); + // std::string temp = yygotominor.yy16->getExtra(tree->variables); + // if(temp.length() > 0) + // str += ","; + // str += temp; + // std::string constants = yygotominor.yy16->getExtraConstants(); + // if (constants.length() > 0) + // { + // constants = "," + constants; + // } + + // std::set uniqueSet = tree->findVariables(str); + // std::string uniqueSetStr; + // for(auto itr = uniqueSet.begin(); itr != uniqueSet.end(); ++itr){ + // uniqueSetStr += *itr + ","; + // } + // if (uniqueSetStr.length() > 0) + // { + // uniqueSetStr.pop_back(); + // uniqueSetStr = "," + uniqueSetStr; + // } + + // str += LanguageConstants::LINE_END; + // str += " [" + + // std::to_string((int)(std::stof(yymsp[-3].minor.yy0->toString())* 1)) + + // "," + + // std::to_string(tree->weak_constraint_counter++) + + // constants + + // "]\n"; + // cout< uniqueSet = tree->findVariables(yygotominor.yy16->toString(tree->domainList)); std::string uniqueSetStr; for(auto itr = uniqueSet.begin(); itr != uniqueSet.end(); ++itr){ uniqueSetStr += *itr + ","; @@ -1959,23 +1987,52 @@ static void yy_reduce( uniqueSetStr.pop_back(); uniqueSetStr = "," + uniqueSetStr; } + std::string temp = yygotominor.yy16->getExtra(tree->variables); + if(temp.length() > 0){ + temp = ", "+ temp; + } + + + string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(yymsp[-3].minor.yy0->toString())* 1)) + uniqueSetStr + ")"; + std::cout << unsatString + << " :- " + << "not " + << yygotominor.yy16->toString(tree->domainList) + << temp + <toString(tree->domainList) + << " :- " + << "not " + << unsatString + << temp + << LanguageConstants::LINE_END + << "\n"; - str += LanguageConstants::LINE_END; - str += " [" + - std::to_string((int)(std::stof(yymsp[-3].minor.yy0->toString())* 1)) + - "," + - std::to_string(tree->weak_constraint_counter++) + - constants + - "]\n"; - cout<toString())* 1)) + <<"," + << tree->weak_constraint_counter + << uniqueSetStr + << "]" + <<"\n"; + + tree->weak_constraint_counter++; } delete yymsp[0].minor.yy92; } -#line 1976 "MVSMParserGrammar.c" +#line 2033 "MVSMParserGrammar.c" break; case 58: /* predicate ::= number NEGATION literal */ -#line 1088 "MVSMParserGrammar.y" +#line 1145 "MVSMParserGrammar.y" { yygotominor.yy16 = new Predicate; *yygotominor.yy16 = yymsp[0].minor.yy92->getPredicate(); @@ -1985,14 +2042,20 @@ static void yy_reduce( cout<toString(yymsp[-2].minor.yy0->toString()+SPACE, false); } else if(tree->outputType == OutputType::OUTPUT_ASP){ - std::string str = yygotominor.yy16->toString(":~ ", false); + std::string str = yygotominor.yy16->toString(":~ ", false); + std::string temp = yygotominor.yy16->getExtra(tree->variables); - if(temp.length() > 0) - str += ","; + if(temp.length() > 0){ + // temp.pop_back(); + temp = ", "+ temp; + } + + // std::string temp = yygotominor.yy16->getExtra(tree->variables); + // if(temp.length() > 0) + // str += ","; std::string constants = yygotominor.yy16->getExtraConstants(); - if (constants.length() > 0) - { + if (constants.length() > 0){ constants = "," + constants; } @@ -2001,8 +2064,7 @@ static void yy_reduce( for(auto itr = uniqueSet.begin(); itr != uniqueSet.end(); ++itr){ uniqueSetStr += *itr + ","; } - if (uniqueSetStr.length() > 0) - { + if (uniqueSetStr.length() > 0){ uniqueSetStr.pop_back(); uniqueSetStr = "," + uniqueSetStr; } @@ -2010,22 +2072,55 @@ static void yy_reduce( - str += " [" + - std::to_string((int)(std::stof(yymsp[-2].minor.yy0->toString())* 1)) + - "," + - std::to_string(tree->weak_constraint_counter++) + - constants + - "]\n"; - cout<toString())* 1)) + + // "," + + // std::to_string(tree->weak_constraint_counter++) + + // constants + + // "]\n"; + + string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(yymsp[-2].minor.yy0->toString())* 1)) + uniqueSetStr + ")"; + std::cout << unsatString + << " :- " + << "not not " + << yygotominor.yy16->toString(tree->domainList) + << temp + <toString(tree->domainList) + << " :- " + << "not " + << unsatString + << temp + << LanguageConstants::LINE_END + << "\n"; + + + std::cout << " :~ " + << unsatString + << temp + << ". " + << "[" + << std::to_string((int)(std::stof(yymsp[-2].minor.yy0->toString())* 1)) + <<"," + << tree->weak_constraint_counter + << uniqueSetStr + << "]" + <<"\n"; + + tree->weak_constraint_counter++; + + // cout<getPredicate(); @@ -2044,35 +2139,35 @@ static void yy_reduce( delete yymsp[-1].minor.yy92; } -#line 2048 "MVSMParserGrammar.c" +#line 2143 "MVSMParserGrammar.c" break; case 60: /* variables ::= variable */ -#line 1155 "MVSMParserGrammar.y" +#line 1250 "MVSMParserGrammar.y" { yygotominor.yy7 = new std::vector(); yygotominor.yy7->push_back(yymsp[0].minor.yy0->token); } -#line 2056 "MVSMParserGrammar.c" +#line 2151 "MVSMParserGrammar.c" break; case 61: /* variables ::= variables COMMA variable */ -#line 1160 "MVSMParserGrammar.y" +#line 1255 "MVSMParserGrammar.y" { yygotominor.yy7 = yymsp[-2].minor.yy7; yymsp[-2].minor.yy7->push_back(yymsp[0].minor.yy0->token); } -#line 2064 "MVSMParserGrammar.c" +#line 2159 "MVSMParserGrammar.c" break; case 62: /* variable ::= string */ case 63: /* variable ::= number */ yytestcase(yyruleno==63); case 64: /* string ::= STRING */ yytestcase(yyruleno==64); -#line 1165 "MVSMParserGrammar.y" +#line 1260 "MVSMParserGrammar.y" { yygotominor.yy0=yymsp[0].minor.yy0;} -#line 2071 "MVSMParserGrammar.c" +#line 2166 "MVSMParserGrammar.c" break; case 65: /* number ::= NUMBER */ -#line 1173 "MVSMParserGrammar.y" +#line 1268 "MVSMParserGrammar.y" { yygotominor.yy0=yymsp[0].minor.yy0; } -#line 2076 "MVSMParserGrammar.c" +#line 2171 "MVSMParserGrammar.c" break; default: /* (0) start ::= prog */ yytestcase(yyruleno==0); @@ -2137,7 +2232,7 @@ static void yy_parse_failed( std::cout<<"Giving up.Parser is lost...\n"; -#line 2141 "MVSMParserGrammar.c" +#line 2236 "MVSMParserGrammar.c" MVSMParserGrammarARG_STORE; /* Suppress warning about unused %extra_argument variable */ } #endif /* YYNOERRORRECOVERY */ @@ -2167,7 +2262,7 @@ static void yy_syntax_error( } throw syntax_exception("Parsing Failed. Unexpected sequence of tokens\n"); -#line 2171 "MVSMParserGrammar.c" +#line 2266 "MVSMParserGrammar.c" MVSMParserGrammarARG_STORE; /* Suppress warning about unused %extra_argument variable */ } @@ -2192,7 +2287,7 @@ static void yy_accept( std::cout<<("%parsing complete!\n"); else std::cout<<("//parsing complete!\n"); -#line 2196 "MVSMParserGrammar.c" +#line 2291 "MVSMParserGrammar.c" MVSMParserGrammarARG_STORE; /* Suppress warning about unused %extra_argument variable */ } diff --git a/src/src/MVSMParserGrammar.y b/src/src/MVSMParserGrammar.y index 11e04f7..3c73eee 100644 --- a/src/src/MVSMParserGrammar.y +++ b/src/src/MVSMParserGrammar.y @@ -401,7 +401,7 @@ rule(R) ::= number(N) REVERSE_IMPLICATION body(B).{ + LanguageConstants::LINE_END + " " + "[" - + std::to_string((int)(std::stof(N->toString())* 1)) + + std::to_string((int)(std::stof(N->toString())* 10000)) + "," + std::to_string(tree->weak_constraint_counter); @@ -486,7 +486,7 @@ rule(R) ::= number(N) head(B) DISJUNCTION bodydef(B1).{ uniqueSetStr.pop_back(); uniqueSetStr = "," + uniqueSetStr; } - string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(N->toString())* 1)) + uniqueSetStr + ")"; + string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(N->toString())* 10000)) + uniqueSetStr + ")"; std::cout << unsatString << " :- " <toNNFString(tree->domainList) @@ -501,7 +501,7 @@ rule(R) ::= number(N) head(B) DISJUNCTION bodydef(B1).{ << unsatString << ". " << "[" - << std::to_string((int)(std::stof(N->toString())* 1)) + << std::to_string((int)(std::stof(N->toString())* 10000)) <<"," << tree->weak_constraint_counter << uniqueSetStr @@ -592,7 +592,7 @@ rule(R) ::= number(N) head(H) REVERSE_IMPLICATION body(B). { uniqueSetStr.pop_back(); uniqueSetStr = "," + uniqueSetStr; } - string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(N->toString())* 1)) + uniqueSetStr + ")"; + string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(N->toString())* 10000)) + uniqueSetStr + ")"; std::cout << unsatString << " :- " << B->toString() @@ -616,7 +616,7 @@ rule(R) ::= number(N) head(H) REVERSE_IMPLICATION body(B). { << unsatString << ". " << "[" - << std::to_string((int)(std::stof(N->toString())* 1)) + << std::to_string((int)(std::stof(N->toString())* 10000)) << "@0" <<"," << tree->weak_constraint_counter @@ -1007,11 +1007,18 @@ predicate(P) ::= number(N) literal(L).{ uniqueSetStr.pop_back(); uniqueSetStr = "," + uniqueSetStr; } - string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(N->toString())* 1)) + uniqueSetStr + ")"; + std::string temp = P->getExtra(tree->variables); + if(temp.length() > 0){ + temp = ", "+ temp; + } + + + string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(N->toString())* 10000)) + uniqueSetStr + ")"; std::cout << unsatString << " :- " << "not " << P->toString(tree->domainList) + << temp <toString())* 1)) + << std::to_string((int)(std::stof(N->toString())* 10000)) <<"," << tree->weak_constraint_counter << uniqueSetStr @@ -1050,18 +1059,37 @@ predicate(P) ::= number(N) NEGATION NEGATION literal(L).{ cout<toString(N->toString()+SPACE, false); } else if(tree->outputType == OutputType::OUTPUT_ASP){ - std::string str = P->toString(":~ not ", false); - std::string temp = P->getExtra(tree->variables); - if(temp.length() > 0) - str += ","; - str += temp; - std::string constants = P->getExtraConstants(); - if (constants.length() > 0) - { - constants = "," + constants; - } - - std::set uniqueSet = tree->findVariables(str); + // std::string str = P->toString(":~ not ", false); + // std::string temp = P->getExtra(tree->variables); + // if(temp.length() > 0) + // str += ","; + // str += temp; + // std::string constants = P->getExtraConstants(); + // if (constants.length() > 0) + // { + // constants = "," + constants; + // } + + // std::set uniqueSet = tree->findVariables(str); + // std::string uniqueSetStr; + // for(auto itr = uniqueSet.begin(); itr != uniqueSet.end(); ++itr){ + // uniqueSetStr += *itr + ","; + // } + // if (uniqueSetStr.length() > 0) + // { + // uniqueSetStr.pop_back(); + // uniqueSetStr = "," + uniqueSetStr; + // } + + // str += LanguageConstants::LINE_END; + // str += " [" + + // std::to_string((int)(std::stof(N->toString())* 10000)) + + // "," + + // std::to_string(tree->weak_constraint_counter++) + + // constants + + // "]\n"; + // cout< uniqueSet = tree->findVariables(P->toString(tree->domainList)); std::string uniqueSetStr; for(auto itr = uniqueSet.begin(); itr != uniqueSet.end(); ++itr){ uniqueSetStr += *itr + ","; @@ -1071,15 +1099,44 @@ predicate(P) ::= number(N) NEGATION NEGATION literal(L).{ uniqueSetStr.pop_back(); uniqueSetStr = "," + uniqueSetStr; } + std::string temp = P->getExtra(tree->variables); + if(temp.length() > 0){ + temp = ", "+ temp; + } + + + string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(N->toString())* 10000)) + uniqueSetStr + ")"; + std::cout << unsatString + << " :- " + << "not " + << P->toString(tree->domainList) + << temp + <toString())* 1)) + - "," + - std::to_string(tree->weak_constraint_counter++) + - constants + - "]\n"; - cout<toString(tree->domainList) + << " :- " + << "not " + << unsatString + << temp + << LanguageConstants::LINE_END + << "\n"; + + + std::cout << " :~ " + << unsatString + << temp + << ". " + << "[" + << std::to_string((int)(std::stof(N->toString())* 10000)) + <<"," + << tree->weak_constraint_counter + << uniqueSetStr + << "]" + <<"\n"; + + tree->weak_constraint_counter++; } delete L; @@ -1094,14 +1151,20 @@ predicate(P) ::= number(N) NEGATION literal(L).{ cout<toString(N->toString()+SPACE, false); } else if(tree->outputType == OutputType::OUTPUT_ASP){ - std::string str = P->toString(":~ ", false); + std::string str = P->toString(":~ ", false); + std::string temp = P->getExtra(tree->variables); - if(temp.length() > 0) - str += ","; + if(temp.length() > 0){ + // temp.pop_back(); + temp = ", "+ temp; + } + + // std::string temp = P->getExtra(tree->variables); + // if(temp.length() > 0) + // str += ","; std::string constants = P->getExtraConstants(); - if (constants.length() > 0) - { + if (constants.length() > 0){ constants = "," + constants; } @@ -1110,8 +1173,7 @@ predicate(P) ::= number(N) NEGATION literal(L).{ for(auto itr = uniqueSet.begin(); itr != uniqueSet.end(); ++itr){ uniqueSetStr += *itr + ","; } - if (uniqueSetStr.length() > 0) - { + if (uniqueSetStr.length() > 0){ uniqueSetStr.pop_back(); uniqueSetStr = "," + uniqueSetStr; } @@ -1119,13 +1181,46 @@ predicate(P) ::= number(N) NEGATION literal(L).{ - str += " [" + - std::to_string((int)(std::stof(N->toString())* 1)) + - "," + - std::to_string(tree->weak_constraint_counter++) + - constants + - "]\n"; - cout<toString())* 10000)) + + // "," + + // std::to_string(tree->weak_constraint_counter++) + + // constants + + // "]\n"; + + string unsatString = "unsat(" + std::to_string(tree->weak_constraint_counter) + ",0," + std::to_string((int)(std::stof(N->toString())* 10000)) + uniqueSetStr + ")"; + std::cout << unsatString + << " :- " + << "not not " + << P->toString(tree->domainList) + << temp + <toString(tree->domainList) + << " :- " + << "not " + << unsatString + << temp + << LanguageConstants::LINE_END + << "\n"; + + + std::cout << " :~ " + << unsatString + << temp + << ". " + << "[" + << std::to_string((int)(std::stof(N->toString())* 10000)) + <<"," + << tree->weak_constraint_counter + << uniqueSetStr + << "]" + <<"\n"; + + tree->weak_constraint_counter++; + + // cout<