Ticket #456: route_harder.patch

File route_harder.patch, 2.4 KB (added by nioui, 9 years ago)

If routing fails, try again with more roads included.

  • navit/route.c

     
    253253        int route_status;               /**< Route Status */
    254254        struct pcoord pc;
    255255        struct vehicle *v;
     256        int try_harder;
    256257};
    257258
    258259/**
     
    726727                        route_status.u.num=route_status_path_done_incremental;
    727728                else
    728729                        route_status.u.num=route_status_path_done_new;
    729         } else
     730        } else {
    730731                route_status.u.num=route_status_not_found;
     732
     733                dbg(0,"try harder\n");
     734                // Try to rebuild the graph with smaller roads
     735                if (this->try_harder == 0) {
     736                        this->try_harder = 1;
     737                        route_graph_destroy(this->graph);
     738                        this->graph=NULL;
     739                        route_path_update(this, 1, 1);
     740                }
     741        }
    731742        route_set_attr(this, &route_status);
    732743}
    733744
     
    927938 * @param c2 Corder 2 of the rectangle
    928939 */
    929940static struct map_selection *
    930 route_calc_selection(struct coord *c, int count)
     941route_calc_selection(struct coord *c, int count, int try_harder)
    931942{
    932943        struct map_selection *ret,*sel;
    933944        int i;
     
    939950        r.rl=c[0];
    940951        for (i = 1 ; i < count ; i++)
    941952                coord_rect_extend(&r, &c[i]);
    942         sel=route_rect(4, &r.lu, &r.rl, 25, 0);
     953        sel=route_rect(try_harder?8:4, &r.lu, &r.rl, 25, 0);
    943954        ret=sel;
    944955        for (i = 0 ; i < count ; i++) {
    945956                sel->next=route_rect(8, &c[i], &c[i], 0, 40000);
     
    10171028        route_graph_destroy(this->graph);
    10181029        this->graph=NULL;
    10191030        this->current_dst=route_get_dst(this);
     1031        this->try_harder=0;
    10201032        route_path_update(this, 1, async);
    10211033        profile(0,"end");
    10221034}
     
    24652477 * @return The new route graph.
    24662478 */
    24672479static struct route_graph *
    2468 route_graph_build(struct mapset *ms, struct coord *c, int count, struct callback *done_cb, int async)
     2480route_graph_build(struct mapset *ms, struct coord *c, int count, struct callback *done_cb, int async, int try_harder)
    24692481{
    24702482        struct route_graph *ret=g_new0(struct route_graph, 1);
    24712483
    24722484        dbg(1,"enter\n");
    24732485
    2474         ret->sel=route_calc_selection(c, count);
     2486        ret->sel=route_calc_selection(c, count, try_harder);
    24752487        ret->h=mapset_open(ms);
    24762488        ret->done_cb=done_cb;
    24772489        ret->busy=1;
     
    25222534                c[i++]=dst->c;
    25232535                tmp=g_list_next(tmp);
    25242536        }
    2525         this->graph=route_graph_build(this->ms, c, 2, this->route_graph_done_cb, async);
     2537        this->graph=route_graph_build(this->ms, c, 2, this->route_graph_done_cb, async, this->try_harder);
    25262538        if (! async) {
    25272539                while (this->graph->busy)
    25282540                        route_graph_build_idle(this->graph);