7

問題を次の簡単な例に減らしました。

digraph {
subgraph {rank=same; 0 -> 1 -> 2;}
0 -> 2 [label="A"];
2 -> 0 [label="B"];
}

生産する

ここに画像の説明を入力

0、1、2 を同じランクに保ちながら (元の例はより大きなグラフのコンテキストにあります)、A と B のエッジを識別できるようにする必要があります。つまり、エッジがラベルと明確に一致し、ラベルが読み取れるようにします。

私が想像した1つの解決策は、によって指定されたエッジ接続でポートを使用することでした

0:ne -> 2:nw [label="A"];
2:sw -> 0:se [label="B"];

しかし、これは生成します

ここに画像の説明を入力

他のアイデア?同じ問題でより大きなグラフを生成しているため、エッジ/ラベルを完全にアドホックに手動で配置するのが最善の解決策ではありません。

編集:生成されたより大きなグラフの(まだ単純化された)例は次のとおりです。

digraph {
size = "6,8.5";
ratio = "fill";
node [shape = circle];
node [fontsize = 24];
edge [fontsize = 24];
{graph [rank=same]; edge[color=invis];1;}
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;}
0 -> 0 [label="6: 0.1764"];
0 -> 4 [label="4: 0.1304"];
0 -> 3 [label="5: 0.1551"];
0 -> 2 [label="7: 0.1489"];
0 -> 1 [label="Z: 0.3893"];
4 -> 0 [label="6: 0.1237"];
4 -> 3 [label="5: 0.05201"];
4 -> 2 [label="7: 0.15  "];
4 -> 1 [label="Z: 0.4585"];
3 -> 0 [label="6: 0.1658"];
3 -> 4 [label="4: 0.13  "];
3 -> 3 [label="5: 0.1038"];
3 -> 2 [label="7: 0.1616"];
3 -> 1 [label="Z: 0.4388"];
2 -> 0 [label="6: 0.1661"];
2 -> 4 [label="4: 0.1295"];
2 -> 3 [label="5: 0.2078"];
2 -> 2 [label="7: 0.1406"];
2 -> 1 [label="Z: 0.356 "];
1 -> 0 [label="6: 0.1103"];
1 -> 4 [label="4: 0.2591"];
1 -> 3 [label="5: 0.1382"];
1 -> 2 [label="7: 0.08581"];
1 -> 1 [label="Z: 0.1906"];
}

これにより、次が生成されます。

ここに画像の説明を入力

これは、上記の単純な例と同じエッジ/ラベルのオーバーラップの問題を示しています。

その他の注意事項:

  • この問題は、同じランク サブグラフ内で双方向に接続されたノードのペアの中間にノードがある場合に発生します。これは、バグが見られる条件のサブセットである可能性があります。
  • この問題は、無向グラフにも存在します。
4

3 に答える 3

1

ssteveemdenの両方からの回答は非常に役に立ち、賛成票が投じられました。(あなたがた両方に感謝します!)

私は両方からの意見を取り入れて、この質問にもっと複雑なバージョンで答えています。ソリューションが完璧であるとはまだ感じていませんが、これまでのところ生成できる最高のものです. これを改善し(まだ不足していると思われるものについては以下を参照)、自動化できる方法でより大きなグラフバージョン(質問を参照)に対処する将来の回答は、この回答の代わりに受け入れられます。

まず、要約すると、これまでの最善の解決策です。一部のエッジ (たとえば、すべての双方向エッジの半分をランダムに選択) のラベルを xlabels に変換し、エッジと対応するラベルをランダムに色付けします ( 経由fontcolor)。

具体的には、エッジがランダムに赤、緑、または黒であるこのソリューションのインスタンス化を次に示します。

digraph {
size = "6,10.5";
ratio = "fill";
node [shape = circle];
node [fontsize = 24];
edge [fontsize = 24];
{graph [rank=same]; edge[color=invis];1;}
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;}
0 -> 0 [label="6: 0.1764"];
0 -> 4 [xlabel="4: 0.1304" color=blue fontcolor=blue];
0 -> 3 [xlabel="5: 0.1551" color=green fontcolor=green];
0 -> 2 [label="7: 0.1489" color=red fontcolor=red];
0 -> 1 [label="Z: 0.3893"];
4 -> 0 [xlabel="6: 0.1237" color=green fontcolor=green];
4 -> 3 [xlabel="5: 0.05201 " color=green fontcolor=green];
4 -> 2 [xlabel="7: 0.15" color=blue fontcolor=blue];
4 -> 1 [label="Z: 0.4585" color=red fontcolor=red];
3 -> 0 [xlabel="6: 0.1658"];
3 -> 4 [xlabel="4: 0.13" color=red fontcolor=red];
3 -> 3 [label="5: 0.1038" color=blue fontcolor=blue];
3 -> 2 [xlabel="7: 0.1616"];
3 -> 1 [label="Z: 0.4388"];
2 -> 0 [label="6: 0.1661" color=blue fontcolor=blue];
2 -> 4 [xlabel="4: 0.1295" color=red fontcolor=red];
2 -> 3 [label="5: 0.2078" color=green fontcolor=green];
2 -> 2 [label="7: 0.1406"];
2 -> 1 [label="Z: 0.356 "];
1 -> 0 [label="6: 0.1103" color=red fontcolor=red];
1 -> 4 [label="4: 0.2591" color=blue fontcolor=blue];
1 -> 3 [label="5: 0.1382" color=green fontcolor=green];
1 -> 2 [label="7: 0.08581 "];
1 -> 1 [label="Z: 0.1906"];
}  

これにより、次が生成されます。 ここに画像の説明を入力

これはまだ完全に満足できるものではありません。理由は次のとおりです。

  1. ラベルをエッジまでトレースするのが簡単になりましたが、xlabel を使用すると、一部のラベルが奇妙な場所に表示されます。(例: 2 -> 4 ラベルの上)
  2. どのラベルが xlables になるかをランダムに選択するのは恣意的なようです。また、これが常にうまくいくことを保証する方法 (私が知っている) はありません。

私が試した他のこと:

  • すべてのラベルを xlabel にします。結果: すべてが圧縮され、ラベルが重なり合って互いに不明瞭になります。
  • すべての双方向エッジに xlabel を使用します。結果: 上記と同じ問題。
  • 色なしで xlabels を使用します。結果: どのラベルが何に属しているかを追跡するのは困難です。
  • ssteve のdir="both"+ colorlistソリューションを使用します。エッジにランダムに色を付けます。labeldistanceまた、ノードでのラベルの重複を避けるために、頭と尾のラベルに 3 ~ 11 の間でランダムに設定します。結果: これは自動化が難しく、依然としてエッジ ラベルの重複と、対応するエッジまでたどるのが困難なラベルの両方が発生します。(下記参照)

上記の「その他に試したこと」の解決策リストの最後の項目の例を次に示します。

size = "6,8.5";
ratio = "fill";
node [shape = circle];
node [fontsize = 24];
edge [fontsize = 24];
{graph [rank=same]; edge[color=invis];1;}
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;}
0 -> 0 [label="6: 0.1764"];
0 -> 4 [dir="both", color="yellow:blue", labeldistance="5", headlabel=<<font color="yellow">4: 0.1304</font>>, taillabel=<<font color="blue">6: 0.1237</font>>];
0 -> 3 [dir="both", color="blue:black", labeldistance="8", headlabel=<<font color="blue">5: 0.1551</font>>, taillabel=<<font color="black">6: 0.1658</font>>];
0 -> 1 [label="Z: 0.3893"];
4 -> 1 [label="Z: 0.4585"];
3 -> 4 [dir="both", color="green:red", labeldistance="5", headlabel=<<font color="green">4: 0.13</font>>, taillabel=<<font color="red">5: 0.05201</font>>];
3 -> 3 [label="5: 0.1038"];
3 -> 1 [label="Z: 0.4388"];
2 -> 0 [dir="both", color="yellow:blue", labeldistance="11", headlabel=<<font color="yellow">6: 0.1661</font>>, taillabel=<<font color="blue">7: 0.1489</font>>];
2 -> 4 [dir="both", color="black:red", labeldistance="5", headlabel=<<font color="black">4: 0.1295</font>>, taillabel=<<font color="red">7: 0.15</font>>];
2 -> 3 [dir="both", color="blue:green", labeldistance="8", headlabel=<<font color="blue">5: 0.2078</font>>, taillabel=<<font color="green">7: 0.1616</font>>];
2 -> 2 [label="7: 0.1406"];
2 -> 1 [label="Z: 0.356 "];
1 -> 0 [label="6: 0.1103"];
1 -> 4 [label="4: 0.2591"];
1 -> 3 [label="5: 0.1382"];
1 -> 2 [label="7: 0.08581 "];
1 -> 1 [label="Z: 0.1906"];
}

これにより、次が生成されます。

ここに画像の説明を入力

その他のアイデア/改善のお願い...

于 2014-05-06T01:50:16.317 に答える