我试图用点语言绘制稀疏矩阵图,实际上节点连接没问题,但问题是这些节点的垂直对齐,我试图使用pos和放置x和y值的节点,但是只是没有工作(我认为是因为默认布局)。如果你能帮助我一个有压力的学生会感谢你。我的点代码低于下面,是生成图像的链接。
https://github.com/Gualtix/Learn_CPP/blob/master/Matrix.png
谢谢。
digraph Sparce_Matrix {
node [shape=box]
Mt [label = "Matrix" width = 1.5 style = filled, fillcolor = firebrick1];
//(^< ............ ............ ............ ............ ............ U S U A R I O S
U0 [label = "Estructuras" pos = "5.3,3.5!" width = 1.5 style = filled, fillcolor = bisque1];
U1 [label = "Redes" width = 1.5 style = filled, fillcolor = bisque1];
U2 [label = "Compiladores" width = 1.5 style = filled, fillcolor = bisque1];
U3 [label = "Investigacion" width = 1.5 style = filled, fillcolor = bisque1];
U4 [label = "Lenguajes" width = 1.5 style = filled, fillcolor = bisque1];
//(^< ............ Links
U0 -> U1 { constraint = true };
U1 -> U0 { constraint = true };
U1 -> U2 { constraint = true };
U2 -> U1 { constraint = true };
U2 -> U3 { constraint = true };
U3 -> U2 { constraint = true };
U3 -> U4 { constraint = true };
U4 -> U3 { constraint = true };
//(^< ............ ............ ............ ............ ............ A R C H I V O S
A0 [label = "Josefina" width = 1.5 style = filled, fillcolor = lightskyblue];
A1 [label = "Alejandro" width = 1.5 style = filled, fillcolor = lightskyblue];
A2 [label = "Marco" width = 1.5 style = filled, fillcolor = lightskyblue];
A3 [label = "Julian" width = 1.5 style = filled, fillcolor = lightskyblue];
A4 [label = "Pamela" width = 1.5 style = filled, fillcolor = lightskyblue];
//(^< ............ Links
A0 -> A1;
A1 -> A0;
A1 -> A2;
A2 -> A1;
A2 -> A3;
A3 -> A2;
A3 -> A4;
A4 -> A3;
Mt -> U0;
Mt -> A0 { constraint = true };
{ rank = same; Mt; A0; A1; A2; A3; A4; }
//(^< ............ ............ ............ ............ ............ P E R M I S O S
//(^< ............ ............ L E V E L 0
N0_L0 [label = "Jose-Estr" width = 1.5];
N1_L0 [label = "Marc-Estr" width = 1.5];
N2_L0 [label = "Juli-Estr" width = 1.5];
//(^< ............ ............ L E V E L 2
N0_L2 [label = "Marc-Comp" width = 1.5];
N1_L2 [label = "Juli-Comp" width = 1.5];
//(^< ............ ............ L E V E L 4
N0_L4 [label = "Marc-Leng" width = 1.5];
N1_L4 [label = "Juli-Leng" width = 1.5];
N2_L4 [label = "Pame-Leng" width = 1.5];
//(^< ............ ............ ............ ............ ............ L I N K I N G
//(^< ............ ............ L E V E L 0
U0 -> N0_L0;
A0 -> N0_L0;
N0_L0 -> N1_L0;
N1_L0 -> N0_L0;
A2 -> N1_L0;
N1_L0 -> N2_L0;
N2_L0 -> N1_L0;
A3 -> N2_L0;
{ rank = same; U0; N0_L0;N1_L0;N2_L0; }
//(^< ............ ............ L E V E L 2
U2 -> N0_L2;
N0_L2 ->N1_L0;
N1_L0 ->N0_L2;
N0_L2 -> N1_L2;
N1_L2 -> N0_L2;
N1_L2 ->N2_L0;
N2_L0 ->N1_L2;
{ rank = same; U2; N0_L2;N1_L2; }
//(^< ............ ............ L E V E L 4
U4 -> N0_L4;
N0_L4 ->N0_L2;
N0_L2 ->N0_L4;
N0_L4 -> N1_L4;
N1_L4 -> N0_L4;
N1_L4 ->N1_L2;
N1_L2 ->N1_L4;
N1_L4 -> N2_L4;
N2_L4 -> N1_L4;
A4 -> N2_L4;
{ rank = same; U4; N0_L4;N1_L4;N2_L4; }
}
enter code here
答案 0 :(得分:1)
更接近所需稀疏矩阵的最重要工具是group
:
<强>组强>
如果边缘的端点属于同一组,即具有相同的组属性,则设置参数以避免交叉并保持边缘平直。
由于稀疏矩阵非常稀疏,我也需要一些空节点。我还删除了[constraint = true]
,因为它是默认值。我所做的更改是源代码中的注释:
digraph Sparce_Matrix {
node [shape=box]
/* add group 1 for vertical alignment */
Mt[ label = "Matrix", width = 1.5, style = filled, fillcolor = firebrick1, group = 1 ];
/* empty nodes, needed to override graphiz' default node placement */
e0[ shape = point, width = 0 ];
e1[ shape = point, width = 0 ];
//(^< ............ ............ ............ ............ ............ U S U A R I O S
/* groups added for vertical alignment */
U0 [label = "Estructuras" pos = "5.3,3.5!" width = 1.5 style = filled, fillcolor = bisque1, group = 1 ];
U1 [label = "Redes" width = 1.5 style = filled, fillcolor = bisque1, group = 1 ];
U2 [label = "Compiladores" width = 1.5 style = filled, fillcolor = bisque1, group = 1 ];
U3 [label = "Investigacion" width = 1.5 style = filled, fillcolor = bisque1, group = 1 ];
U4 [label = "Lenguajes" width = 1.5 style = filled, fillcolor = bisque1, group = 1 ];
//(^< ............ Links
U0 -> U1;
U1 -> U0;
U1 -> U2;
U2 -> U1;
U2 -> U3;
U3 -> U2;
U3 -> U4;
U4 -> U3;
//(^< ............ ............ ............ ............ ............ A R C H I V O S
/* groups 2 to 6 added for vertical alignment */
A0 [label = "Josefina" width = 1.5 style = filled, fillcolor = lightskyblue, group = 2 ];
A1 [label = "Alejandro" width = 1.5 style = filled, fillcolor = lightskyblue, group = 3 ];
A2 [label = "Marco" width = 1.5 style = filled, fillcolor = lightskyblue, group = 4 ];
A3 [label = "Julian" width = 1.5 style = filled, fillcolor = lightskyblue, group = 5 ];
A4 [label = "Pamela" width = 1.5 style = filled, fillcolor = lightskyblue, group = 6 ];
//(^< ............ Links
A0 -> A1;
A1 -> A0;
A1 -> A2;
A2 -> A1;
A2 -> A3;
A3 -> A2;
A3 -> A4;
A4 -> A3;
Mt -> U0;
Mt -> A0;
{ rank = same; Mt; A0; A1; A2; A3; A4; }
//(^< ............ ............ ............ ............ ............ P E R M I S O S
//(^< ............ ............ L E V E L 0
/* groups 2 to 6 added for vertical alignment */
N0_L0 [label = "Jose-Estr" width = 1.5, group = 2 ];
N1_L0 [label = "Marc-Estr" width = 1.5, group = 4 ];
N2_L0 [label = "Juli-Estr" width = 1.5, group = 5 ];
//(^< ............ ............ L E V E L 2
N0_L2 [label = "Marc-Comp" width = 1.5, group = 4 ];
N1_L2 [label = "Juli-Comp" width = 1.5, group = 5 ];
//(^< ............ ............ L E V E L 4
N0_L4 [label = "Marc-Leng" width = 1.5, group = 4 ];
N1_L4 [label = "Juli-Leng" width = 1.5, group = 5 ];
N2_L4 [label = "Pame-Leng" width = 1.5, group = 6 ];
//(^< ............ ............ ............ ............ ............ L I N K I N G
//(^< ............ ............ L E V E L 0
U0 -> N0_L0;
A0 -> N0_L0;
N0_L0 -> N1_L0;
N1_L0 -> N0_L0;
A2 -> N1_L0;
N1_L0 -> N2_L0;
N2_L0 -> N1_L0;
A3 -> N2_L0;
{ rank = same; U0; N0_L0;N1_L0;N2_L0; }
//(^< ............ ............ L E V E L 2
U2 -> N0_L2;
N0_L2 ->N1_L0;
N1_L0 ->N0_L2;
N0_L2 -> N1_L2;
N1_L2 -> N0_L2;
N1_L2 ->N2_L0;
N2_L0 ->N1_L2;
{ rank = same; U2; N0_L2;N1_L2; }
//(^< ............ ............ L E V E L 4
U4 -> N0_L4;
N0_L4 -> N0_L2;
N0_L2 -> N0_L4;
N0_L4 -> N1_L4;
N1_L4 -> N0_L4;
N1_L4 -> N1_L2;
N1_L2 -> N1_L4;
N1_L4 -> N2_L4;
N2_L4 -> N1_L4;
{ rank = same; U4; N0_L4;N1_L4;N2_L4; }
/* we divide the edge from A4 to N2_L4 into 'sub-edges',
thus indirectly making sure that the U nodes stay in their place */
{ rank = same; U2; e0 }
{ rank = same; U3; e1 }
A4 -> e0 -> e1[ dir = none ];
e1 -> N2_L4;
}
产量