Yiliang Xiong avatar Yiliang Xiong committed 421ae0b

bugfix: plot westbound train route correctly

Comments (0)

Files changed (3)

 # 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);
+    ax = fliplr(leng2(route==1));
+    dx = fliplr(leng1(route==1));
+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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.