title: How to enforce the left-to-right node ordering in GraphViz rank layout?
body: <p>I am visualizing a collection of process with GraphViz. Each process consists of some Read or Write operations in program order. Naturally, it is desirable to arrange the operations in the <em>left-to-right</em> order with respect to each process.</p>
  <p>Using GraphViz (version 2.28), my code goes like this:</p>
  <pre><code>digraph G 
  {
  ranksep = 1.0; size = &quot;10,10&quot;;
  { 
      node [shape = plaintext, fontsize = 20];
      0 -&gt; 1 -&gt; 2 -&gt; 3 -&gt; 4;
  }
  node [shape = box];
  {rank = same;0;wy1;rf1;rc1;rz1;ry1;ra1;rb1;rx2;}
  {rank = same;1;wf1;}
  {rank = same;2;wx2;wc1;}
  {rank = same;3;wf2;wz2;wx3;wa1;}
  {rank = same;4;wz1;wy2;wx5;wb1;}
  wy1 -&gt; rf1;
  rf1 -&gt; rc1;
  rc1 -&gt; rz1;
  rz1 -&gt; ry1;
  ry1 -&gt; ra1;
  ra1 -&gt; rb1;
  rb1 -&gt; rx2;
  wx2 -&gt; wc1;
  wf2 -&gt; wz2;
  wz2 -&gt; wx3;
  wx3 -&gt; wa1;
  wz1 -&gt; wy2;
  wy2 -&gt; wx5;
  wx5 -&gt; wb1;
  wf1 -&gt; rf1[color = blue];
  wc1 -&gt; rc1[color = blue];
  wz1 -&gt; rz1[color = blue];
  wy1 -&gt; ry1[color = blue];
  wa1 -&gt; ra1[color = blue];
  wb1 -&gt; rb1[color = blue];
  wx2 -&gt; rx2[color = blue];
  
  // W'WR Order:
  wx3 -&gt; wx2[style = dashed, color = red];
  
  // W'WR Order:
  wx5 -&gt; wx2[style = dashed, color = red];
  }
  </code></pre>
  <p><em>I am sorry to say that I am not allowed to post the output picture with too low reputation.</em> If you can run the code, you will see that the result is not so satisfying due to the out of order in process with pid = 3. Specifically, GraphViz layout algorithm has rearranged the (ideal) order &quot;wf2-&gt; wz2 -&gt; wa1 -&gt; wx3&quot; to &quot;wx3, wf2, wz2, wa1&quot;. Therefore, my problem is:</p>
  <blockquote>
  <p><strong>My Problem</strong>: How to enforce the <em>left-to-right</em> node ordering in the rank environment?</p>
  </blockquote>
  <p>With exploring in this site, I have found some similar problems and potential solutions. <strong>However, they just did not work in my specific example:</strong></p>
  <ul>
  <li><p><a href="https://stackoverflow.com/q/7627904/1833118">Graphviz .dot node ordering</a>: the <em>constraint = false</em> option made my PDF picture worse. I checked the <a href="https://stackoverflow.com/q/12746224/1833118">dot User's Manual</a> which says:</p>
  <blockquote>
  <p>During rank assignment, the head node of an edge is constrained to be on a higher rank than the    tail node. If the edge has constraint=false, however, this requirement is not enforced.</p>
  </blockquote>
  <p>Based on the above statements, (I guess) <em>constraint = false</em> option takes effect between different ranks instead of in the same rank.</p>
  </li>
  <li><p><a href="https://stackoverflow.com/q/12746224/1833118">Graphviz---random node order and edges going through labels</a>: With surprise, the <em>constraint = false</em> option helped the &quot;finite state machine&quot; a lot <em>in the same rank</em>. Again, it does not save me from the trouble.</p>
  </li>
  <li><p><a href="https://stackoverflow.com/q/4242949/1833118">graphviz: circular layout while preserving node order</a>: The process graph is dynamic both in number of nodes and edges. So, it maybe not attractive to use the absolute position for nodes (to cause many edge crossing?).</p>
  <p>Thanks for any suggestions. And executable code will be appreciated very much.</p>
  </li>
  </ul>
  <p><img src="https://i.stack.imgur.com/XO11k.png" alt="dot file" /></p>