Skip to content

Commit

Permalink
Fixes bug in J-V solver.
Browse files Browse the repository at this point in the history
  • Loading branch information
pazmivaniye committed Nov 8, 2024
1 parent ea107f1 commit 489f312
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 14 additions & 5 deletions jv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#define GET_COST(i, j) get_cost(costMat, resolution, intInf, i, j, -minCost)

constexpr double MinRes = 1e-9;

// Handle non-square matrices. (1/2)
static std::int64_t get_cost(const paz::MatRef& costMat, double resolution,
std::int64_t intInf, std::size_t i, std::size_t j, double offset)
Expand Down Expand Up @@ -66,10 +64,21 @@ double paz::jv(const MatRef& costMat, std::vector<std::size_t>& rowSols)

const double maxCost = max_finite_cost(costMat) - minCost;

const double resolution = std::max(MinRes, eps(maxCost*(rows + 1)));
const std::int64_t intInf = std::round(maxCost/resolution)*(rows + 1);
double resolution;
std::int64_t intInf;
if(maxCost)
{
resolution = eps(maxCost*(rows + 1));
intInf = std::round(maxCost/resolution)*(rows + 1);
}
else
{
resolution = 1.;
intInf = rows + 1;
}

rowSols.resize(cols, None);
rowSols.resize(cols);
std::fill(rowSols.begin(), rowSols.end(), None);
std::vector<std::size_t> colSols(cols, None);

std::vector<std::size_t> colList(cols);
Expand Down
2 changes: 2 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ int main()
std::vector<std::size_t> rowSols;
PRINT(jv(paz::Mat{{1.}}, rowSols))
PRINT(jv(paz::Mat{{1., 2., 3.}}, rowSols))
PRINT(jv(paz::Mat{{0., paz::inf()}}, rowSols))
PRINT(jv(paz::Mat{{paz::inf(), 0.}}, rowSols))
}

{
Expand Down

0 comments on commit 489f312

Please sign in to comment.