mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-10-31 15:20:10 +00:00
Fix: YAPF doesn't check destination for start nodes (#12217)
This commit is contained in:
parent
216905ce1f
commit
30e1a61c04
@ -113,45 +113,39 @@ public:
|
||||
m_veh = v;
|
||||
|
||||
Yapf().PfSetStartupNodes();
|
||||
bool bDestFound = true;
|
||||
|
||||
for (;;) {
|
||||
m_num_steps++;
|
||||
Node *n = m_nodes.GetBestOpenNode();
|
||||
if (n == nullptr) {
|
||||
Node *best_open_node = m_nodes.GetBestOpenNode();
|
||||
if (best_open_node == nullptr) break;
|
||||
|
||||
if (Yapf().PfDetectDestination(*best_open_node)) {
|
||||
m_pBestDestNode = best_open_node;
|
||||
break;
|
||||
}
|
||||
|
||||
/* if the best open node was worse than the best path found, we can finish */
|
||||
if (m_pBestDestNode != nullptr && m_pBestDestNode->GetCost() < n->GetCostEstimate()) {
|
||||
break;
|
||||
Yapf().PfFollowNode(*best_open_node);
|
||||
if (m_max_search_nodes != 0 && m_nodes.ClosedCount() >= m_max_search_nodes) break;
|
||||
|
||||
m_nodes.PopOpenNode(best_open_node->GetKey());
|
||||
m_nodes.InsertClosedNode(*best_open_node);
|
||||
}
|
||||
|
||||
Yapf().PfFollowNode(*n);
|
||||
if (m_max_search_nodes == 0 || m_nodes.ClosedCount() < m_max_search_nodes) {
|
||||
m_nodes.PopOpenNode(n->GetKey());
|
||||
m_nodes.InsertClosedNode(*n);
|
||||
} else {
|
||||
bDestFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bDestFound &= (m_pBestDestNode != nullptr);
|
||||
const bool destination_found = (m_pBestDestNode != nullptr);
|
||||
|
||||
if (_debug_yapf_level >= 3) {
|
||||
UnitID veh_idx = (m_veh != nullptr) ? m_veh->unitnumber : 0;
|
||||
char ttc = Yapf().TransportTypeChar();
|
||||
float cache_hit_ratio = (m_stats_cache_hits == 0) ? 0.0f : ((float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f);
|
||||
int cost = bDestFound ? m_pBestDestNode->m_cost : -1;
|
||||
int dist = bDestFound ? m_pBestDestNode->m_estimate - m_pBestDestNode->m_cost : -1;
|
||||
const UnitID veh_idx = (m_veh != nullptr) ? m_veh->unitnumber : 0;
|
||||
const char ttc = Yapf().TransportTypeChar();
|
||||
const float cache_hit_ratio = (m_stats_cache_hits == 0) ? 0.0f : ((float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f);
|
||||
const int cost = destination_found ? m_pBestDestNode->m_cost : -1;
|
||||
const int dist = destination_found ? m_pBestDestNode->m_estimate - m_pBestDestNode->m_cost : -1;
|
||||
|
||||
Debug(yapf, 3, "[YAPF{}]{}{:4d} - {} rounds - {} open - {} closed - CHR {:4.1f}% - C {} D {}",
|
||||
ttc, bDestFound ? '-' : '!', veh_idx, m_num_steps, m_nodes.OpenCount(), m_nodes.ClosedCount(), cache_hit_ratio, cost, dist
|
||||
ttc, destination_found ? '-' : '!', veh_idx, m_num_steps, m_nodes.OpenCount(), m_nodes.ClosedCount(), cache_hit_ratio, cost, dist
|
||||
);
|
||||
}
|
||||
|
||||
return bDestFound;
|
||||
return destination_found;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,16 +236,6 @@ public:
|
||||
/* have the cost or estimate callbacks marked this node as invalid? */
|
||||
if (!bValid) return;
|
||||
|
||||
/* detect the destination */
|
||||
bool bDestination = Yapf().PfDetectDestination(n);
|
||||
if (bDestination) {
|
||||
if (m_pBestDestNode == nullptr || n < *m_pBestDestNode) {
|
||||
m_pBestDestNode = &n;
|
||||
}
|
||||
m_nodes.FoundBestNode(n);
|
||||
return;
|
||||
}
|
||||
|
||||
/* The new node can be set as the best intermediate node only once we're
|
||||
* certain it will be finalized by being inserted into the open list. */
|
||||
bool set_intermediate = m_max_search_nodes > 0 && (m_pBestIntermediateNode == nullptr || (m_pBestIntermediateNode->GetCostEstimate() - m_pBestIntermediateNode->GetCost()) > (n.GetCostEstimate() - n.GetCost()));
|
||||
|
Loading…
Reference in New Issue
Block a user