News:

Want to praise Simutrans?
Your feedback is important for us ;D.

wegbauer_t::weg_search

Started by gerw, May 22, 2009, 07:21:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gerw

In r2487, lines 137+138 are logically identical and line 139 doesn't do, what the comment implies. I think these lines should read
( best->get_topspeed() <      speed_limit       &&      speed_limit      <= test->get_topspeed()) || // test is faster than speed_limit
( best->get_topspeed() <  test->get_topspeed()  &&  test->get_topspeed() <=     speed_limit  )    || // closer to desired speed (from the low end)
(     speed_limit      <= test->get_topspeed()  &&  test->get_topspeed() <  best->get_topspeed()) || // closer to desired speed (from the top end)


In r2487, if no way fulfills the timeline, the first way found is returned. This is also changed in the patch.

Patch:
Index: bauer/wegbauer.cc
===================================================================
--- bauer/wegbauer.cc   (revision 2487)
+++ bauer/wegbauer.cc   (working copy)
@@ -120,26 +120,33 @@
}


-/**
+/*
  * Finds a way with a given speed limit for a given waytype
+ * It finds:
+ *  - the slowest way, as fast as speed limit
+ *  - if no way faster than speed limit, the fastest way.
+ * The timeline is also respected.
  * @author prissi
  */
const weg_besch_t* wegbauer_t::weg_search(const waytype_t wtyp, const uint32 speed_limit, const uint16 time, const weg_t::system_type system_type)
{
        const weg_besch_t* best = NULL;
+       bool best_allowed = false; // Does the best way fulfill the timeline?
        for(  stringhashtable_iterator_tpl<const weg_besch_t*> iter(alle_wegtypen); iter.next();  ) {
                const weg_besch_t* const test = iter.get_current_value();
                if(  ((test->get_wtyp()==wtyp  &&
                             (test->get_styp()==system_type  ||  system_type==weg_t::type_all))  ||  (test->get_wtyp()==track_wt  &&  test->get_styp()==weg_t::type_tram  &&  wtyp==tram_wt))
                             &&  test->get_cursor()->get_bild_nr(1)!=IMG_LEER  ) {
-                       if(  best==NULL  ||  time==0  ||  (test->get_intro_year_month()<=time  &&  time<test->get_retire_year_month())) {
+                       bool test_allowed = test->get_intro_year_month()<=time  &&  time<test->get_retire_year_month();
+                       if(  !best_allowed  ||  time==0  ||  test_allowed  ) {
                                if(  best==NULL  ||
-                                               (best->get_topspeed() < speed_limit  &&  test->get_topspeed() <= speed_limit  &&  best->get_topspeed() < test->get_topspeed())  ||      // not yet there but this is ...
-                                               (test->get_topspeed() <=  speed_limit  &&  best->get_topspeed() < test->get_topspeed()) ||      // closer to desired speed (from the low end)
-                                               (best->get_topspeed() > speed_limit  &&  test->get_topspeed() < best->get_topspeed())  ||       // closer to desired speed (from the top end)
-                                               (time!=0  &&  (best->get_intro_year_month()>time  ||  time>=best->get_retire_year_month()))     // current choice is acutally not really allowed, timewise
+                                               ( best->get_topspeed() <      speed_limit       &&      speed_limit      <= test->get_topspeed()) || // test is faster than speed_limit
+                                               ( best->get_topspeed() <  test->get_topspeed()  &&  test->get_topspeed() <=     speed_limit  )    || // closer to desired speed (from the low end)
+                                               (     speed_limit      <= test->get_topspeed()  &&  test->get_topspeed() <  best->get_topspeed()) || // closer to desired speed (from the top end)
+                                               (time!=0  &&  !best_allowed  &&  test_allowed)                                                       // current choice is acutally not really allowed, timewise
                                        ) {
                                        best = test;
+                                       best_allowed = test_allowed;
                                }
                        }
                }

gerw

In my opinion, the commit in r2545 was wrong.
(     speed_limit      <  best->get_topspeed()  &&  test->get_topspeed() <   best->get_topspeed()) || // respects speed_limit better
will select test, albeit it's slower than speed_limit.

Dwachs

as prissi pm'ed me, speed_limit is a hard limit, so this condition select test when its nearer to feasibility.
Parsley, sage, rosemary, and maggikraut.

gerw

But what is the sense of this hard limit??

prissi

No cityroads with more than 50km/h which are then downgraded by city AI to 50kmh.

gerw

Which AI downgrade the streets?

prissi

The citybuilder uses this routine to find a cityroad, when non is defined or the current one is not yet available.

gerw

And what is the problem, if a city builds a road with more than 50 km/h?

prissi

It has the speed of 50kmh nevertheless, just confusing players.

gerw

But then it would be better, if weg_search retruns a way with a speed of at least the speedlimit, if one exists. If an AI wants to build a way for a vehicle, it should be faster than the vehicle, shouldn't it?

prissi

Maybe just a routine for a way less or same and one for the cehapest. This would keep the logic much cleaner?

gerw

Quote from: prissi on June 28, 2009, 08:20:26 PM
Maybe just a routine for a way less or same and one for the cehapest. This would keep the logic much cleaner?
This sounds reasonable. Maybe, we could just add a parameter?