Commit fbefbaa5 authored by Thomas Schiex's avatar Thomas Schiex
Browse files

[bug] Nary full table CFN reader now properly computes its minCost + explicit type conversions

parent 9955e7bf
......@@ -4263,7 +4263,7 @@ Cost WCSP::decimalToCost(const string& decimalToken, const unsigned int lineNumb
size_t readIdx;
if (dotFound == std::string::npos) {
try {
Cost cost = (Cost)std::stoll(decimalToken, &readIdx) * ToulBar2::costMultiplier * powl(10, ToulBar2::decimalPoint);
Cost cost = (Cost)std::stoll(decimalToken, &readIdx) * ToulBar2::costMultiplier * (Cost)powl(10, ToulBar2::decimalPoint);
if (decimalToken[readIdx])
throw std::invalid_argument("Not a cost");
return cost;
......@@ -4284,11 +4284,11 @@ Cost WCSP::decimalToCost(const string& decimalToken, const unsigned int lineNumb
Cost cost;
try {
cost = (std::stoll(integerPart, &readIdx) * powl(10, ToulBar2::decimalPoint) * ToulBar2::costMultiplier);
cost = (std::stoll(integerPart, &readIdx) * (Cost)powl(10, ToulBar2::decimalPoint) * ToulBar2::costMultiplier);
if (integerPart[readIdx])
throw std::invalid_argument("Not a cost");
if (decimalPart.size()) {
cost += std::stoll(decimalPart, &readIdx) * powl(10, shift) * ToulBar2::costMultiplier;
cost += std::stoll(decimalPart, &readIdx) * (Cost)powl(10, shift) * ToulBar2::costMultiplier;
if (decimalPart[readIdx])
throw std::invalid_argument("Not a cost");
}
......
......@@ -572,7 +572,7 @@ Cost CFNStreamReader::readHeader()
try {
if (pos != string::npos) {
pbBound = (std::stoll(integerPart) * powl(10, decimalPart.size()));
pbBound = (std::stoll(integerPart) * (Cost)powl(10, decimalPart.size()));
pbBound += ((pbBound >= 0) ? std::stoll(decimalPart) : -std::stoll(decimalPart));
} else {
pbBound = std::stoll(integerPart);
......@@ -1268,7 +1268,8 @@ void CFNStreamReader::readNaryCostFunction(vector<int>& scope, bool all, Cost de
// Read all costs
while (!isCBrace(token)) {
costs.push_back(wcsp->decimalToCost(token, lineNumber));
cost = wcsp->decimalToCost(token, lineNumber);
costs.push_back(cost);
minCost = min(minCost, cost);
nbTuples++;
std::tie(lineNumber, token) = this->getNextToken();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment