5 typedef struct Neighbour {
6 struct Neighbour *next;
11 static Neighbour **neighbours; /* neighbours[islandid]->islandid etc. */
12 static sqlite3_stmt *ss_neigh;
14 static int ports[MAX_ROUTELEN];
16 static Neighbour *get_neighbours(int isle) {
17 Neighbour **np= &neighbours[isle];
19 if (head) return head;
21 SQL_BIND(ss_neigh, 1, isle);
22 while (SQL_STEP(ss_neigh)) {
23 Neighbour *add= mmalloc(sizeof(*add));
24 add->islandid= sqlite3_column_int(ss_neigh, 0);
25 add->dist= sqlite3_column_int(ss_neigh, 1);
29 SQL_MUST( sqlite3_reset(ss_neigh) );
35 static double bestsofar;
37 static void process_route(int nports) {
38 double value= value_route(nports, ports);
39 if (value < bestsofar) return;
41 fprintf(stderr,"value %20f route", value);
43 for (i=0; i<nports; i++)
44 fprintf(stderr," %d",ports[i]);
50 static void recurse(int last_isle,
51 int nports, /* excluding last_isle */
52 int totaldist /* including last_isle */) {
53 ports[nports++]= last_isle;
54 process_route(nports);
55 if (nports >= MAX_ROUTELEN) return;
58 for (add= get_neighbours(last_isle); add; add=add->next) {
59 int newdist= totaldist + add->dist;
60 if (newdist > max_dist) continue;
62 recurse(add->islandid, nports, newdist);
66 void search(int start_isle) {
67 recurse(start_isle,0,0);
70 void setup_search(void) {
71 neighbours= mcalloc(sizeof(*neighbours) * islandtablesz);
74 "SELECT biid, dist FROM routes WHERE aiid=?");