Search code examples
graphvizdot

Reducing edge weight to zero in graphviz


I have created a graph using graphviz that I'm pretty happy with and I need to add one more edge to it. I currently have this:

Current Graph

(source for this in dot below)

I need to add an edge from T to S (in green!) but when I do so all the rest of the graph is thrown in to disarray. I know that I'm meant to just let graphviz take care of the layout but this graph forms one of a sequence and I'd like them to at least mostly look alike. I've tried various things with graph clusters and using weights to make all the other edges very high weight and the new edge very low but nothing seems to help. How can I add an edge from T to S which doesn't worry about the fact that that edge will have to be quite long.

The dot source for what I have is

digraph G {
  rankdir=LR
  subgraph clusterD3 {
  vSource [label="S*"]
    subgraph clusterD2 {
      color=white
      S
      T
      subgraph clusterD1 {
        color=white
        {rank=same; B A}
        {rank=same; D C}
        A->C 
        B->D  
        A->D 
        C->D 
        B->A 
        }   
        S->A 
        S->B 
        C->T 
        D->T 
     }
  vSink [label="T*"]
  vSource->A [color=red]
  vSource->B [color=red]
  vSource->C [color=red]
  vSource->D [color=red]
  vSource->T [color=red]
  A->vSink   [color=blue]
  B->vSink   [color=blue]
  C->vSink   [color=blue]
  D->vSink   [color=blue]
  S->vSink   [color=blue]
  }  
}

Solution

  • Adding

    {rank=same;vSource;S}
    

    solves the issue:

    digraph G {
      rankdir=LR
      subgraph clusterD3 {
      vSource [label="S*"]
        subgraph clusterD2 {
          color=white
          S
          T
          {rank=same;vSource;S}
          subgraph clusterD1 {
            color=white
            {rank=same; B A}
            {rank=same; D C}
            A->C 
            B->D  
            A->D 
            C->D 
            B->A 
            }   
            S->A 
            S->B 
            C->T 
            D->T 
         }
      vSink [label="T*"]
      vSource->A [color=red]
      vSource->B [color=red]
      vSource->C [color=red]
      vSource->D [color=red]
      vSource->T [color=red]
      A->vSink   [color=blue]
      B->vSink   [color=blue]
      C->vSink   [color=blue]
      D->vSink   [color=blue]
      S->vSink   [color=blue]
      T -> S     [color=green]
      }
    }