The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: Philip on September 18, 2014, 03:33:21 PM

Title: [PATCH] routing code does not respect maximum cost
Post by: Philip on September 18, 2014, 03:33:21 PM
In looking over the bridge building code again, I came across something weird: the wegbauer class sometimes returns routes that have a greater cost than the maximum cost argument, but sometimes fails to find such routes. It seems the route finding code in route.cc is also affected.

It's possible that this behaviour makes sense somehow, but it seems quite random to me, so I've attached a patch to fix it:


diff --git a/bauer/wegbauer.cc b/bauer/wegbauer.cc
index c221a05..38fc066 100644
--- a/bauer/wegbauer.cc
+++ b/bauer/wegbauer.cc
@@ -1503,7 +1503,8 @@ DBG_DEBUG("wegbauer_t::intern_calc_route()","steps=%i  (max %i) in route, open %
route_t::RELEASE_NODE();

// target reached?
- if( !ziel.is_contained(gr->get_pos())  ||  step>=route_t::MAX_STEP  ||  tmp->parent==NULL) {
+ if( !ziel.is_contained(gr->get_pos())  ||  step>=route_t::MAX_STEP  ||  tmp->parent==NULL  ||
+     tmp->g > maximum) {
if (step>=route_t::MAX_STEP) {
dbg->warning("wegbauer_t::intern_calc_route()","Too many steps (%i>=max %i) in route (too long/complex)",step,route_t::MAX_STEP);
}
diff --git a/dataobj/route.cc b/dataobj/route.cc
index c1ff9fc..7223516 100644
--- a/dataobj/route.cc
+++ b/dataobj/route.cc
@@ -481,7 +481,7 @@ bool route_t::intern_calc_route(karte_t *welt, const koord3d ziel, const koord3d

INT_CHECK("route 194");
// target reached?
- if(!ziel_erreicht  || step >= MAX_STEP  ||  tmp->parent==NULL) {
+ if(!ziel_erreicht  || step >= MAX_STEP  ||  tmp->g >= max_cost  ||  tmp->parent==NULL) {
if(  step >= MAX_STEP  ) {
dbg->warning("route_t::intern_calc_route()","Too many steps (%i>=max %i) in route (too long/complex)",step,MAX_STEP);
}


(It's intentional, to match the other code, that one comparison is > while the other one is >=, though I think route.cc should also be changed to use an inclusive maximum).

In either case, I don't think it makes sense to specify a fixed maximum cost of 2 in brueckenbauer.cc.
Title: Re: [PATCH] routing code does not respect maximum cost
Post by: prissi on September 21, 2014, 08:49:35 PM
In in r7330. I think that the cost is route.cc is (currently) not used. But well spotted anyway, thank you.