Commits

Yiliang Xiong committed 421ae0b

bugfix: plot westbound train route correctly

  • Participants
  • Parent commits 0fc4b81

Comments (0)

Files changed (3)

File exportsol.run

 # export the solution to MATLAB
 
+# origin and destination
+printf "OD = [\n" > sol.m;
+for {i in T} {
+    printf "%d\t%d\n", orig[i], dest[i] > sol.m;
+}
+printf "];\n\n" > sol.m;
 # edges
 printf "E = [\n" > sol.m;
 for {(r,s) in E} {
-function plotroute(leng, route, atime, dtime)
+function plotroute(leng, route, atime, dtime, orig, dest)
 
 % cummulative track length
-adist = leng(1:end-1)';
-ddist = leng(2:end)';
+leng1 = leng(1:end-1)';
+leng2 = leng(2:end)';
 % route-specified points
-adist = adist(route==1);
-ddist = ddist(route==1);
-atime = atime(route==1);
-dtime = dtime(route==1);
+if orig < dest
+    ax = leng1(route==1);
+    dx = leng2(route==1);
+else
+    ax = fliplr(leng2(route==1));
+    dx = fliplr(leng1(route==1));
+end
+at = atime(route==1);
+dt = dtime(route==1);
 % line sections
-xx = [adist;ddist];
-yy = [atime;dtime];
+xx = [ax;dx];
+yy = [at;dt];
 % plot the route
 line(xx, yy, 'Marker', 'o')
 figure; hold on; grid on
 cumleng = plotedge(edge, leng);
 for i = 1:size(a,1)
-    route = a(i,:,3);
+    route = y(i,:,3);
     atime = a(i,:,4);
     dtime = d(i,:,4);
-    plotroute(cumleng, route, atime, dtime)
+    orig = OD(i,1);
+    dest = OD(i,2);
+    plotroute(cumleng, route, atime, dtime, orig, dest)
 end