#Copyright (c) 2006 EPFL/Switzernet/Intarnet by Emin Gabrielyan reset; print "Drawing..."; commands network-config.txt; commands diagram-config.txt; shell "rmdir /s /q diagram"; shell "mkdir diagram"; shell "del /q diagram\*"; shell "copy randomwalk-config.txt diagram > nul"; printf "%%!PS\n" > (ps); printf " [/View [/XYZ null null 1]\n" > (ps); printf " /Page 1\n" > (ps); printf " /PageMode /FullScreen\n" > (ps); printf " /DOCVIEW pdfmark\n" > (ps); printf "/Courier findfont %f scalefont setfont\n",fontsz > (ps); table params IN "ODBC" "data/randomwalk.mdb": [], x_max, y_max, source_node, sink_node, N, T; read table params; table coordinates IN "ODBC" "data/randomwalk.mdb": [Timeframe,NODES], x,y; read table coordinates; param layers{1..T} default 0; param pump{t in 1..T, 1..layers[t]}; set BOTTLENECKS{t in 1..T,1..layers[t]} dimen 2; set PATH{t in 1..T,1..layers[t]} dimen 2; set INITLINKS{1..T} dimen 2; param load{t in 1..T, l in 1..layers[t], (i,j) in PATH[t,l]} >=0; data data/flow.txt; param layer; param diagram_pos; for{t in 1..T} { printf "gsave 0 %f translate\n",page_height > (ps); printf "0 %f translate 0 0 moveto ( frame: %d) show\n", -fontsz,t > (ps); printf "0 %f translate 0 0 moveto ( links: %d) show\n", -fontsz,card(INITLINKS[t]) > (ps); printf "0 %f translate 0 0 moveto (loaded: %d) show\n", -fontsz,sum{l in 1..layers[t]} card(BOTTLENECKS[t,l]) > (ps); printf "0 %f translate 0 0 moveto (layers: %d) show\n", -fontsz,layers[t] > (ps); printf "0 %f translate\n",-1/2*fontsz > (ps); for{l in 1..layers[t]} if BOTTLENECKS[t,l] not within {} then { if l*fontsz>page_height-4.5*fontsz then break; let showload := 1/prod{ll in 1..l}pump[t,ll]; print view > (ps); printf "0 %f moveto\n",-fontsz*l > (ps); printf "(%2d: %.5f) dup stringwidth pop\n",l,showload > (ps); printf "0 rlineto stroke\n" > (ps); printf "0 %f moveto 0 setgray show\n",-fontsz*l > (ps); } printf "grestore\n" > (ps); printf "%f 0 translate\n",page_bar > (ps); let layer := if diagram_display == "firsts" then 1 else layers[t]; let diagram_pos := if diagram_display == "firsts" then 1 else diagram_num; repeat while layer in {1..layers[t]} and diagram_pos in {1..diagram_num} { printf "gsave\n" > (ps); printf "%f %f translate\n", diagram_width*((diagram_pos-1) mod diagram_cols), diagram_height*(diagram_rows-1 - (diagram_pos-1) div diagram_cols) > (ps); printf "0.5 setgray\n" > (ps); printf "%f %f moveto (layer %d) dup stringwidth pop -2 div 0 rmoveto show\n", diagram_width/2,fontsz/4,layer > (ps); printf "%f %f translate\n",nodesz,nodesz > (ps); # passive links if "links" in diagram_details then { printf "[2 2] 0 setdash 0.5 setgray %f setlinewidth\n",view_thickness/10 > (ps); for { (i,j) in INITLINKS[t] diff union{(i,j) in union{l in 1..layer} BOTTLENECKS[t,l]} {(i,j),(j,i)} diff union{(i,j) in PATH[t,layer]} {(i,j),(j,i)} : i (ps); } } # bottlenecks if "bottlenecks" in diagram_details then { printf "[] 0 setdash\n" > (ps); printf "1 setlinecap\n" > (ps); for{l in 1..layer} if BOTTLENECKS[t,l] not within {} then { let showload := 1/prod{i in 1..l}pump[t,i]; print view > (ps); for{(i,j) in BOTTLENECKS[t,l]} { printf "%f %f moveto %f %f lineto stroke\n",x[t,i],y[t,i],x[t,j],y[t,j] > (ps); } } } # lables of bottlenecks if "bottlenecklabels" in diagram_details then { for{l in 1..layer} { for{(i,j) in BOTTLENECKS[t,l]} { printf "0 setgray\n" > (ps); printf "gsave\n" > (ps); printf "%f %f translate\n", x[t,i]+(x[t,j]-x[t,i])/2.5, y[t,i]+(y[t,j]-y[t,i])/2.5 > (ps); printf "%f rotate\n",45*atan2(y[t,j]-y[t,i],x[t,j]-x[t,i])/atan(1) > (ps); printf "(%d>) dup stringwidth pop -2 div %f moveto show\n",l,-fontsz/4 > (ps); printf "grestore\n" > (ps); } } } # path (non bottleneck path links) if "path" in diagram_details then { printf "[1 2] 0 setdash\n" > (ps); printf "0 setlinecap\n" > (ps); for{(i,j) in PATH[t,layer] diff BOTTLENECKS[t,layer]} { let showload := load[t,layer,i,j]*1/prod{l in 1..layer}pump[t,l]; print view > (ps); printf "%f %f moveto %f %f lineto stroke\n",x[t,i],y[t,i],x[t,j],y[t,j] > (ps); } } # lables of the path if "pathlabels" in diagram_details then { for{(i,j) in PATH[t,layer] diff BOTTLENECKS[t,layer]} { printf "0 setgray\n" > (ps); printf "gsave\n" > (ps); printf "%f %f translate\n",x[t,i]+(x[t,j]-x[t,i])/2.5,y[t,i]+(y[t,j]-y[t,i])/2.5 > (ps); printf "%f rotate\n",45*atan2(y[t,j]-y[t,i],x[t,j]-x[t,i])/atan(1) > (ps); printf "(%.0f%%>) dup stringwidth pop -2 div %f moveto show\n", 100*load[t,layer,i,j],-fontsz/4 > (ps); printf "grestore\n" > (ps); } } # nodes if "nodes" in diagram_details then { for{i in NODES diff {source_node,sink_node}} { printf "%s setrgbcolor\n", if "nodelabels" in diagram_details then "0.8 0.8 0.85" else "0.95 0.7 0.7" > (ps); printf "newpath %f %f %f 0 360 arc fill\n",x[t,i],y[t,i],nodesz > (ps); } } # parties (end nodes) if "parties" in diagram_details then { for{i in {source_node,sink_node}} { printf "0.8 0 0 setrgbcolor\n" > (ps); printf "newpath %f %f %f 0 360 arc fill\n",x[t,i],y[t,i],nodesz > (ps); } } # lables of nodes if "nodelabels" in diagram_details then { for{i in NODES} { printf "0 setgray %f %f moveto (%d) dup stringwidth pop -2 div %f rmoveto show\n", x[t,i],y[t,i],i,-fontsz/4 >(ps) } } printf "grestore\n" > (ps); let layer := layer + if diagram_display == "firsts" then 1 else if diagram_display == "lasts" then -1 else -max(1,layers[t] div diagram_num); let diagram_pos := diagram_pos + if diagram_display == "firsts" then 1 else -1; } printf "showpage\n" > (ps); } close (ps); table page OUT "ODBC" "data/diagram.xls": [], page_width, page_height; write table page;