Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
2maz committed Jul 24, 2024
1 parent 7e01a88 commit b72e916
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Test
run: docker run rock/${{ matrix.os }}
/bin/bash -c
"source /home/docker/rock_test/env.sh; BOOST_TEST_CATCH_SYSTEM_ERRORS=\"no\" make -C /home/docker/rock_test/${{ matrix.package }}/build/test/graph_analysis-test --log_level=all"
"source /home/docker/rock_test/env.sh; BOOST_TEST_CATCH_SYSTEM_ERRORS=\"no\" /home/docker/rock_test/${{ matrix.package }}/build/test/graph_analysis-test --log_level=all"



93 changes: 92 additions & 1 deletion src/algorithms/lp/CLPSolver.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "CLPSolver.hpp"
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
Expand All @@ -19,7 +21,80 @@ std::string CLPSolver::createSolverCommand() const
return cmd;
}

Solution CLPSolver::readBasicSolution(const std::string& filename)
Solution CLPSolver::readBasicSolution_v2(const std::string& filename)
{
Solution solution;
std::ifstream solutionFile;
solutionFile.open(filename.c_str(), std::ios::in);

std::string header;
getline(solutionFile, header);
boost::to_lower(header);

std::vector<std::string> splitLine;
boost::split(splitLine, header, boost::is_any_of("-"), boost::token_compress_on);

std::string status = splitLine[0];
boost::trim_if(status, boost::is_any_of(" "));

if(status == "optimal")
{
solution.setStatus(LPSolver::STATUS_OPTIMAL);
} else if(status == "infeasible")
{
solution.setStatus(LPSolver::STATUS_INFEASIBLE);
return solution;
} else {
solution.setStatus(LPSolver::STATUS_UNKNOWN);
}

if(boost::contains(header, "objective value"))
{
// Optimal - objective value 6.00000000
std::vector<std::string> objectiveKeyValue;
std::string objective = splitLine[1];
boost::trim_if(objective, boost::is_any_of(" "));
boost::split(objectiveKeyValue, objective, boost::is_any_of(" "), boost::token_compress_on);

// -- Parsing the header
double objectiveValue = 0;
try {
objectiveValue = boost::lexical_cast<double>(objectiveKeyValue[2]);
} catch(const std::bad_cast& e)
{
LOG_WARN_S << "Failed to extract objective value from '"
+ objective + "'";
throw;
}
solution.setObjectiveValue(objectiveValue);
}

std::string line;
while(std::getline(solutionFile, line))
{
std::vector<std::string> splitLine;
boost::trim_if(line, boost::is_any_of("\t "));
// https://www.boost.org/doc/libs/1_49_0/doc/html/boost/algorithm/split_id820181.html
// token_compress_on: adjacent separators are merged together. Otherwise, every two separators delimit a token.
boost::split(splitLine, line, boost::is_any_of("\t "), boost::token_compress_on);
if(splitLine.empty())
{
continue;
}

{
if(splitLine.size() > 3 && boost::starts_with(splitLine[1], "x"))
{
solution.setColumnValue(splitLine[1], boost::lexical_cast<size_t>(splitLine[2]));
}
}
}

solutionFile.close();
return solution;
}

Solution CLPSolver::readBasicSolution_v1(const std::string& filename)
{
Solution solution;
std::ifstream solutionFile;
Expand Down Expand Up @@ -79,7 +154,23 @@ Solution CLPSolver::readBasicSolution(const std::string& filename)

solutionFile.close();
return solution;
}

Solution CLPSolver::readBasicSolution(const std::string& filename)
{
Solution solution;
std::ifstream solutionFile;
solutionFile.open(filename.c_str(), std::ios::in);

std::string line;
getline(solutionFile, line);
solutionFile.close();

if(boost::contains(line, "-"))
{
return this->readBasicSolution_v2(filename);
}
return this->readBasicSolution_v1(filename);
}

} // end namespace lp
Expand Down
5 changes: 5 additions & 0 deletions src/algorithms/lp/CLPSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ class CLPSolver : public CommandlineSolver
LPSolver::Type getSolverType() const override { return CLP_SOLVER; }

std::string createSolverCommand() const override;

Solution readBasicSolution(const std::string& filename) override;

Solution readBasicSolution_v1(const std::string& filename);

Solution readBasicSolution_v2(const std::string& filename);
};

} // end namespace lp
Expand Down
1 change: 1 addition & 0 deletions test/algorithms/test_MultiCommodityMinCostFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ BOOST_AUTO_TEST_CASE(multi_commodity_min_cost_flow_0)
LPSolver::Status status;
double cost = 0.0;
{
BOOST_TEST_MESSAGE("SolverType: "<< LPSolver::TypeTxt[solverType]);
std::string prefixPath("/tmp/graph_analysis-test-algorithms-multi_commodity_min_cost_flow_0");
MultiCommodityMinCostFlow minCostFlow(graph, commodities, solverType);
checkSolverResult(status = minCostFlow.solve(prefixPath),
Expand Down

0 comments on commit b72e916

Please sign in to comment.