-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add solver API integration and enhance main function for input handling
- Loading branch information
1 parent
e0f7aaf
commit f7fbb95
Showing
3 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,55 @@ | ||
#include "solver.hpp" | ||
#include "logging.hpp" | ||
#include "solver_api.hpp" | ||
#include <chrono> | ||
#include <numeric> | ||
#include <fstream> | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
if (argc < 3) | ||
{ | ||
LOG_FATAL("usage: oRatio <input-file> [<input-file> ...] <output-file>"); | ||
return -1; | ||
} | ||
|
||
// the problem files.. | ||
std::vector<std::string> prob_names; | ||
for (int i = 1; i < argc - 1; i++) | ||
prob_names.push_back(argv[i]); | ||
|
||
// the solution file.. | ||
std::string sol_name = argv[argc - 1]; | ||
|
||
LOG_INFO("starting oRatio"); | ||
auto start = std::chrono::high_resolution_clock::now(); | ||
auto s = std::make_shared<ratio::solver>(); | ||
s->init(); | ||
try | ||
{ | ||
s->read(prob_names); | ||
|
||
if (s->solve()) | ||
{ | ||
LOG_INFO("hurray!! we have found a solution.."); | ||
|
||
std::ofstream sol_file; | ||
sol_file.open(sol_name); | ||
sol_file << to_json(*s).dump(); | ||
sol_file.close(); | ||
} | ||
else | ||
{ | ||
LOG_INFO("the problem is unsolvable.."); | ||
} | ||
auto dur = std::chrono::high_resolution_clock::now() - start; | ||
LOG_INFO("running time: " + std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(dur).count()) + " ms"); | ||
} | ||
catch (const std::exception &ex) | ||
{ | ||
LOG_FATAL("exception: " + std::string(ex.what())); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters