Commit 6c0aeca7 authored by Marco Amagliani's avatar Marco Amagliani
Browse files

DoCloud cache now store the information that a DoCloud has not been able to...

DoCloud cache now store the information that a DoCloud has not been able to find a solution for a problem.

[git-p4: depot-paths = "//ReForm/ReForm/main/CoMISo/": change = 12128]
parent 114e1c5d
...@@ -123,6 +123,8 @@ void string_to_key(const std::string& _str, std::string& _key) ...@@ -123,6 +123,8 @@ void string_to_key(const std::string& _str, std::string& _key)
_key = std::to_string(hash_fn(_str)); _key = std::to_string(hash_fn(_str));
} }
const size_t NO_SOLUTION_CODE = UINT_MAX;
// Load variables and objective values from a file. // Load variables and objective values from a file.
bool load_data(const std::string& _filename, bool load_data(const std::string& _filename,
std::vector<double>& _x, double& _obj_val) std::vector<double>& _x, double& _obj_val)
...@@ -133,6 +135,12 @@ bool load_data(const std::string& _filename, ...@@ -133,6 +135,12 @@ bool load_data(const std::string& _filename,
size_t dim = std::numeric_limits<size_t>::max(); size_t dim = std::numeric_limits<size_t>::max();
in_file_strm >> dim; in_file_strm >> dim;
if (dim == NO_SOLUTION_CODE)
{
_x.clear();
return true;
}
if (dim != _x.size()) if (dim != _x.size())
return false; return false;
...@@ -151,6 +159,11 @@ bool save_data(const std::string& _filename, ...@@ -151,6 +159,11 @@ bool save_data(const std::string& _filename,
if (!out_file_strm.is_open()) if (!out_file_strm.is_open())
return false; return false;
if (_x.empty())
{
out_file_strm << NO_SOLUTION_CODE;
return true;
}
out_file_strm << _x.size() << std::endl; out_file_strm << _x.size() << std::endl;
for (const auto& xi : _x) for (const auto& xi : _x)
out_file_strm << xi << std::endl;; out_file_strm << xi << std::endl;;
......
...@@ -441,33 +441,42 @@ void throw_http_error(const int _err_code, const std::string& _bdy) ...@@ -441,33 +441,42 @@ void throw_http_error(const int _err_code, const std::string& _bdy)
} }
} }
void check_http_error( class HttpStatus
const cURLpp::Request& _rqst,
const HeaderTokens& _hdr_tkns,
const int code_ok = 201
)
{ {
const std::string http_lbl = "HTTP/1.1"; public:
const int code_cntn = 100; // continue code, ignore HttpStatus(const cURLpp::Request& _rqst)
: rqst_(_rqst), hdr_tkns_(_rqst.header()), code_(0)
for (auto it = _hdr_tkns.begin(), it_end = _hdr_tkns.end(); it != it_end;
++it)
{ {
if (*it != http_lbl) // search for the http label token const std::string http_lbl = "HTTP/1.1";
continue; const int code_cntn = 100; // continue code, ignore
THROW_OUTCOME_if(++it == it_end, TODO); // missing http code
const auto code = atoi(it->data()); for (auto it = hdr_tkns_.begin(), it_end = hdr_tkns_.end(); it != it_end; ++it)
{
if (code == code_ok) if (*it != http_lbl) // search for the http label token
return; // success code found, exit here continue;
else if (code == code_cntn) THROW_OUTCOME_if(++it == it_end, TODO); // missing http code
continue; // continue code found, continue code_ = atoi(it->data());
else // another code found, throw an error if (code_ != code_cntn)
throw_http_error(code, _rqst.body()); return;
}
THROW_OUTCOME(TODO); // final http code not found
} }
THROW_OUTCOME(TODO); // final http code not found
}
void check(int _code_ok) const
{
if (code_ != _code_ok) // another code found, throw an error
throw_http_error(code_, rqst_.body());
}
const int& code() const { return code_; }
const HeaderTokens& header_tokens() const { return hdr_tkns_; }
private:
const cURLpp::Request& rqst_;
HeaderTokens hdr_tkns_;
int code_;
};
class Job : public cURLpp::Session class Job : public cURLpp::Session
{ {
...@@ -571,10 +580,11 @@ void Job::make() ...@@ -571,10 +580,11 @@ void Job::make()
post.add_http_header(app_type__); post.add_http_header(app_type__);
post.perform(); post.perform();
HeaderTokens hdr_tkns(post.header()); HttpStatus http_stat(post);
check_http_error(post, hdr_tkns); http_stat.check(201);
// TODO: DOcloud header is successful but no location value // TODO: DOcloud header is successful but no location value
THROW_OUTCOME_if(!hdr_tkns.find_value("Location:", url_), TODO); THROW_OUTCOME_if(!http_stat.header_tokens().find_value("Location:", url_),
TODO);
} }
void Job::upload_internal(cURLpp::Upload& _upload) void Job::upload_internal(cURLpp::Upload& _upload)
...@@ -585,8 +595,8 @@ void Job::upload_internal(cURLpp::Upload& _upload) ...@@ -585,8 +595,8 @@ void Job::upload_internal(cURLpp::Upload& _upload)
_upload.set_url(url.data()); _upload.set_url(url.data());
_upload.add_http_header(api_key__.c_str()); _upload.add_http_header(api_key__.c_str());
_upload.perform(); _upload.perform();
HeaderTokens hdr_tkns(_upload.header()); HttpStatus http_stat(_upload);
check_http_error(_upload, hdr_tkns, 204); http_stat.check(204);
} }
void Job::start() void Job::start()
...@@ -599,8 +609,8 @@ void Job::start() ...@@ -599,8 +609,8 @@ void Job::start()
post.add_http_header(api_key__.c_str()); post.add_http_header(api_key__.c_str());
post.add_http_header(app_type__); post.add_http_header(app_type__);
post.perform(); post.perform();
HeaderTokens hdr_tkns(post.header()); HttpStatus http_stat(post);
check_http_error(post, hdr_tkns, 204); http_stat.check(204);
log_seq_idx_ = sol_nmbr_ = sol_sec_nmbr_ = stld_sec_nmbr_ = 0; log_seq_idx_ = sol_nmbr_ = sol_sec_nmbr_ = stld_sec_nmbr_ = 0;
} }
...@@ -614,8 +624,8 @@ void Job::sync_status() ...@@ -614,8 +624,8 @@ void Job::sync_status()
get.set_url(url_.data()); get.set_url(url_.data());
get.add_http_header(api_key__.c_str()); get.add_http_header(api_key__.c_str());
get.perform(); get.perform();
HeaderTokens hdr_tkns(get.header()); HttpStatus http_stat(get);
check_http_error(get, hdr_tkns, 200); http_stat.check(200);
stts_.set(get.body()); stts_.set(get.body());
/* /*
...@@ -653,8 +663,8 @@ void Job::sync_log() ...@@ -653,8 +663,8 @@ void Job::sync_log()
get.set_url(url.data()); get.set_url(url.data());
get.add_http_header(api_key__.c_str()); get.add_http_header(api_key__.c_str());
get.perform(); get.perform();
HeaderTokens hdr_tkns(get.header()); HttpStatus http_stat(get);
check_http_error(get, hdr_tkns, 200); http_stat.check(200);
JsonTokens log(get.body()); JsonTokens log(get.body());
...@@ -741,8 +751,8 @@ void Job::abort() ...@@ -741,8 +751,8 @@ void Job::abort()
del.add_http_header(api_key__.c_str()); del.add_http_header(api_key__.c_str());
del.perform(); del.perform();
HeaderTokens hdr_tkns(del.header()); HttpStatus http_stat(del);
check_http_error(del, hdr_tkns, 204); http_stat.check(204);
} }
void Job::wait() void Job::wait()
...@@ -776,8 +786,15 @@ double Job::solution(std::vector<double>& _x) const ...@@ -776,8 +786,15 @@ double Job::solution(std::vector<double>& _x) const
get.add_http_header(api_key__.c_str()); get.add_http_header(api_key__.c_str());
get.perform(); get.perform();
HeaderTokens hdr_tkns(get.header()); HttpStatus http_stat(get);
check_http_error(get, hdr_tkns, 200); if (http_stat.code() == 404 &&
get.body().find("CIVOC5102E") != std::string::npos)
{
// The mixed integer optimization has not found any solution.
_x.clear();
return 0;
}
http_stat.check(200);
JsonTokens bdy_tkns(get.body()); JsonTokens bdy_tkns(get.body());
DEB_line(7, bdy_tkns); DEB_line(7, bdy_tkns);
...@@ -1067,6 +1084,7 @@ void DOCloudSolver::solve( ...@@ -1067,6 +1084,7 @@ void DOCloudSolver::solve(
obj_val = job.solution(x); obj_val = job.solution(x);
cache.store_result(x, obj_val); cache.store_result(x, obj_val);
} }
THROW_OUTCOME_if(x.empty(), MIPS_NO_SOLUTION);
DEB_only( DEB_only(
// The lp problem ignores the constant term in the objective function. // The lp problem ignores the constant term in the objective function.
......
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