import java.io.*; import java.util.*; public class MWGPathfinder { static int vertices,vstart,vend,histlen; static ArrayList[] adjlist; // array of arraylist of edges static double distance[]; static int reps = 10000; static History globhist; static String datafile = "dv2.in"; public static void main(String args[]) throws IOException { BufferedReader f = new BufferedReader(new FileReader(datafile)); StringTokenizer st = new StringTokenizer(f.readLine()); vertices = Integer.parseInt(st.nextToken()); int edges = Integer.parseInt(st.nextToken()); vstart = Integer.parseInt(st.nextToken()); vend = Integer.parseInt(st.nextToken()); histlen = Integer.parseInt(st.nextToken()); adjlist = new ArrayList[vertices]; globhist = new History(vertices); for(int n=0; nn) // System.out.println( n+" "+ ((Edge)adjlist[n].get(i)).getVertex(n)+" "+globhist.predictMutations( ((Edge)adjlist[n].get(i)).getWeight() ,5) ); /* distance = new double[vertices]; for(int n=0; n0) { Vertex v = (Vertex)heap.removeMin(); System.out.println("hit vertex "+v.getIndex()+" with value "+v.getValue()); if(v.getIndex()==curvertex) break; for(int n=0; n=inf) continue; double x = globhist.predictMutations(E.getWeight(),t) + prevvals[E.getVertex(v)]; if(x0; t--) { System.out.println(t + " " + btrack); btrack = bestprev[btrack][t].getVertex(btrack); } return bestprev[btrack][0]; } /*pseudoalg -bfs to find shortest path using predicted values -for each timestep -for each vertex find the best of each edge it could come from */ } class History { TreeMap hmap; int hvertices; public History(int numv) { hmap = new TreeMap(); hvertices = numv; } public void addEntry(int v1, int v2, double w1, double w2) { while(hmap.containsKey(new Double(w1))) w1+=0.0000000001; hmap.put(new Double(w1), new Double(w2)); } public double predictMutation(double w1) { double ti=0; double pred=0; Iterator it = hmap.keySet().iterator(); while(it.hasNext()) { double d = ((Double)it.next()).doubleValue(); double i = 1.0/(1+(d-w1)*(d-w1)*(d-w1)*(d-w1)); ti+=i; pred+=i*(((Double)hmap.get(d)).doubleValue()-d); } return w1+pred/ti; } public double predictMutations(double w1, int steps) { for(int n=0; n0) return 1; if(d<0) return -1; return 0; } } class Heap { ArrayList hal; ArrayList keys; int size; public Heap() { hal = new ArrayList(); keys = new ArrayList(); size=0; } public void add(Comparable o) { keys.add(new Integer(size)); if(hal.size()==size) hal.add(size, o); else hal.set(size, o); size++; reheap(size-1); } public Object getMin() { return hal.get(0); } public int getKey(int k) { return ((Integer)keys.get(k)).intValue(); } public Object removeMin() { if(size()==0) return null; Object o = hal.get(0); size--; swap(0,size); keys.set(((Vertex)hal.get(size)).getIndex(), new Integer(-1)); hal.set(size, null); reheap(0); return o; } public void reheap(int pos) { int cur = pos; while(cur>0&&((Comparable)hal.get(cur)).compareTo((Comparable)hal.get((cur-1)/2))<0) { swap(cur, (cur-1)/2); cur=(cur-1)/2; } while(size>cur*2+1) { if(size>cur*2+2&&((Comparable)hal.get(cur*2+2)).compareTo((Comparable)hal.get(cur*2+1))<0) { if(((Comparable)hal.get(cur*2+2)).compareTo((Comparable)hal.get(cur))<0) { swap(cur, cur*2+2); cur=cur*2+2; } else break; } else { if(((Comparable)hal.get(cur*2+1)).compareTo((Comparable)hal.get(cur))<0) { swap(cur, cur*2+1); cur=cur*2+1; } else break; } } } public int size() { return size; } public void print() { for(int n=0; n=hal.size()||i2>=hal.size()||i1==i2) return; Object o = hal.get(i1); hal.set(i1, hal.get(i2)); keys.set(((Vertex)hal.get(i2)).getIndex(),i1); hal.set(i2, o); keys.set(((Vertex)o).getIndex(),i2); } } /* bfs: for each time period for each vertex v for each edge of v update shortest distance to that vertex in time t greedily */