Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unfeasible problem analyzer #1527

Merged
merged 18 commits into from
Sep 14, 2023
51 changes: 39 additions & 12 deletions src/solver/infeasible-problem-analysis/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "constraint.h"
#include <sstream>
#include <iomanip>
#include <algorithm>

namespace Antares
{
Expand Down Expand Up @@ -39,20 +41,45 @@ double Constraint::getSlackValue() const
{
return mSlackValue;
}
std::vector<std::string> split(const std::string& s, char delimiter)

class StringIsNotWellFormated : public std::runtime_error
{
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter))
{
tokens.push_back(token);
}
return tokens;
}
public:
StringIsNotWellFormated(const std::string& error_message) : std::runtime_error(error_message)
{
}
};

std::string StringBetweenAngleBrackets(const std::string& str){
return split(split(str, '<')[1], '>')[0];
std::string StringBetweenAngleBrackets(const std::string& str)
{
const auto& str_begin_iterator = str.begin();
const auto& str_end_iterator = str.end();
a-zakir marked this conversation as resolved.
Show resolved Hide resolved
auto left = std::find(str.begin(), str.end(), '<');
if (left == str_end_iterator)
{
std::ostringstream stream;
stream << std::string("Error the string: ") << std::quoted(str)
<< " does not contains the left angle bracket " << std::quoted("<");
throw StringIsNotWellFormated(stream.str());
}

auto right = std::find(str_begin_iterator, str_end_iterator, '>');
if (right == str_end_iterator)
{
std::ostringstream stream;
stream << std::string("Error the string: ") << std::quoted(str)
<< " does not contains the right angle bracket " << std::quoted(">");
throw StringIsNotWellFormated(stream.str());
}

if (std::distance(left, right) <= 1)
{
std::ostringstream stream;
stream << std::string("Error the string: ") << std::quoted(str) << " must be of format "
<< std::quoted("*<str>*");
throw StringIsNotWellFormated(stream.str());
}
return std::string(left + 1, right);
}

std::string Constraint::getAreaName() const
Expand Down