TARGETS= yarrg
-all: clean-other-directory $(TARGETS)
+default: clean-other-directory $(TARGETS)
+all: default routesearch
CONVERT_OBJS= convert.o ocr.o pages.o structure.o common.o rgbimage.o resolve.o
+ROUTESEARCH_OBJS= rsvalue.o rsmain.o
+
yarrg: $(CONVERT_OBJS) -lnetpbm -lXtst -lX11 -lpcre -lm
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(CONVERT_OBJS): ocr.h convert.h structure.h common.h
+routesearch: $(ROUTESEARCH_OBJS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
+$(ROUTESEARCH_OBJS): rscommon.h
+
clean:
rm -f *.o core core.* *~ vgcore.*
rm -f t t.* u u.* v v.* *.tmp *.orig *.rej
--- /dev/null
+/**/
+
+#include "rscommon.h"
+
+void value_route(int nislands, const int *islands) {
+ char stmt[1024+80*nislands+40*nislands*nislands], *sp;
+ int s,d;
+
+ sp= stmt;
+ sp += sprintf(sp,
+ "SELECT\n"
+ " sell.islandid src_id,\n"
+ " sell.price src_price,\n"
+ " sum(sell.qty) src_qty,\n"
+ " buy.islandid dst_id,\n"
+ " buy.price dst_price,\n"
+ " sum(buy.qty) dst_qty,\n"
+ " commods.commodid commodid,\n"
+ " commods.unitmass unitmass,\n"
+ " commods.unitvolume unitvolume,\n"
+ " dist dist,\n"
+ " buy.price-sell.price unitprofit\n"
+ " FROM commods\n"
+ " JOIN sell ON commods.commodid = sell.commodid\n"
+ " JOIN buy ON commods.commodid = buy.commodid\n"
+ " JOIN dists ON aiid = sell.islandid AND biid = buy.islandid\n"
+ " WHERE buy.price > sell.price\n"
+ " AND (");
+ for (s=0; s<nislands; s++) {
+ sp += sprintf(sp, "%s(sell.islandid=%d AND (",
+ !s ? "" : "\n OR ",
+ islands[s]);
+ for (d=s; d<nislands; d++) {
+ sp += sprintf(sp, "%sbuy.islandid=%d",
+ d==s ? "" : " OR ",
+ islands[d]);
+ }
+ sp += sprintf(sp, "))");
+ }
+ sp += sprintf(sp,
+ ")\n"
+ " GROUP BY commods.commodid,\n"
+ " sell.islandid, sell.price,\n"
+ " buy.islandid, buy.price\n"
+ );
+
+ assert(sp < stmt + sizeof(stmt) - 1);
+
+ printf("SQL\n[\n%s\n]\n", stmt);
+
+ //char *tail;
+ //struct sqlite_vm *sth;
+ //r= sqlite_compile(db, stmt, &tail, &sth,
+}