Skip to content

Commit

Permalink
fix: add round3, apply in insertionCost and remove not_equal checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhil-CM committed Apr 29, 2024
1 parent 255faf2 commit 2582baa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 2 additions & 4 deletions include/tsp_discrete_enn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,7 @@ class DiscreteENN_TSP
const Index_t pos_next{ m_path[idx_next] };
const Value_t cost_current{ insertionCost(city, m_cities[pos],
m_cities[pos_next]) };
const bool not_equal{ not utils::isEqual(cost_current, cost) };
if (not_equal and (cost_current < cost)) {
if (cost_current < cost) {
#if TSP_DEBUG_PRINT > 1
if (global_print) {
utils::printInfo("cost_current " +
Expand Down Expand Up @@ -886,8 +885,7 @@ class DiscreteENN_TSP
}
const City& city{ m_cities[pos] };
const Value_t cost{ insertionCost(city, city_start, city_end) };
const bool not_equal{ not utils::isEqual(cost, city.cost) };
if (not_equal and (cost < city.cost)) {
if (cost < city.cost) {
#if TSP_DEBUG_PRINT > 1
if (global_print) {
const auto [start_tmp, end_tmp] = findEdge(pos_start, pos_end);
Expand Down
7 changes: 7 additions & 0 deletions include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ inline float getRound2(float value)
return (round2/100.f);
}

inline float getRound3(float value)
{
const float round1{ std::round(value * 10000.f) };
const float round2{ std::round(round1/10.f) };
return (round2/1000.f);
}

inline float getRoundN(float value, int places)
{
const float round1 = std::round(value * std::pow(10.f, places+1));
Expand Down
2 changes: 1 addition & 1 deletion src/tsp_discrete_enn.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Value_t insertionCost(const City& new_city, const City& cityA,
const Value_t cost = getDistance(new_city, cityA) +
getDistance(new_city, cityB) -
getDistance(cityA, cityB);
return utils::isEqual(cost, VALUE_ZERO) ? VALUE_ZERO : cost;
return utils::getRound3(cost);
}

bool isInside(const City& city, const City& cityA, const City& cityB,
Expand Down

0 comments on commit 2582baa

Please sign in to comment.