1

I want to search route from one place to one another.

The places are referenced in a SQLite Database.

I think I should make loop in the SQL query but I don't know how to perform this.

2
  • puchka, cna you refine a little bit the question? What is bus_stop_id1 and bus_stop_id2? I suppose input (call :bus_stop_id1, :bus_stop_id2). What means "search for 3 or more bus lines to join the 2 bus_stop with possible intermediary bus_stop". Are you trying to build a path like busline1 (stop1) -> busline2 -> busline3 (stop2) Commented Jan 19, 2014 at 8:48
  • Yes, bus_stop_id1 and bus_stop_id2 are inputs. Yes, I try to make a path. Commented Jan 19, 2014 at 8:51

1 Answer 1

0

puchka,

if I understood the question, you need a routing algorithm or graph search algorithm; in other words you cannot iterate simply on the table because you could find infinite sub-optimal solutions and you need the sortest; see Dijkastra and the related java implementation or http://www.cs.nyu.edu/~vs667/development/~DijkstraAlgorithm/ or related .

See also these SO question on

  1. The best shortest path algorithm.
  2. k-shortest (alternative) path algorithm, java implementations
Sign up to request clarification or add additional context in comments.

6 Comments

So have I to transform my database to a graph?
Unfortunatly yes; any different way will be not optimal. If the databse is not big you can simply search for 2 or 3 consecutive lines and no more
@puchka Constructing all the possible routes for a bounded number of changes (e.g., 2 or 3) should leave the data relatively manageable, but it is something that you'd want to compute once and reuse rather than building on each query. (That is, you'd be denormalizing the data to improve search performance. A classic tradeoff.)
That's true but it's a mobile application so there is a constraint in the memory too.
@puchka you got any solution?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.