Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graph Mathematica,修改转换列表_Graph_Wolfram Mathematica - Fatal编程技术网

Graph Mathematica,修改转换列表

Graph Mathematica,修改转换列表,graph,wolfram-mathematica,Graph,Wolfram Mathematica,谷歌没有给我提供答案的原因是我不知道本例中列表元素的正确名称(*)。这里我有一些输入数据: edges = ReadList["some\\external\\data\\source\\1"] (* edges = { 0 -> 1, 1 -> 2, 2 -> 3 } *) labels = ReadList["some\\external\\data\\source\\2"] (* labels = { 0 -> A, 1 -> B, 2 -> A,

谷歌没有给我提供答案的原因是我不知道本例中列表元素的正确名称(*)。这里我有一些输入数据:

edges = ReadList["some\\external\\data\\source\\1"]
 (* edges = { 0 -> 1, 1 -> 2, 2 -> 3 } *)

labels = ReadList["some\\external\\data\\source\\2"]
 (* labels = { 0 -> A, 1 -> B, 2 -> A, 3 -> B } *)
我想创建一个新的列表样式,从标签替换为a红色B绿色,这样我就可以得到:

styles = { 0 -> Red, 1 -> Green, 2 -> Red, 3 -> Green }
我用它来画图表:

Graph [ edges, VertexLabels -> labels, VertexStyle -> styles ]
(*)尝试了成对列表、过渡列表、边列表,但发现RightArrow运算符具有一般意义…

从“数据库”开始如何:

然后是一些替换规则:

s["A"] = "Red"; s["B"] = "Green";
它允许您定义新的
标签
功能:

styles[e_] := s[labels[e]]

In[9]:= Table[styles[i], {i, 0, 3}]

Out[9]= {"Red", "Green", "Red", "Green"}
等等。

我想你想要这个:

edges = {0 -> 1, 1 -> 2, 2 -> 3}

labels = {0 -> A, 1 -> B, 2 -> A, 3 -> B}
styles = labels /. {A -> Red, B -> Green}
Graph[edges, VertexLabels -> labels, VertexStyle -> styles]

对不起,你说右箭头有一般意义,但我不清楚你的意思。我的意思是,我找不到a->B是关系、分配、层次还是过渡?@Bartek
a->B
FullForm
规则[a,B]
。换句话说,这是一个转换规则。这在Mathematica中有明确的含义。请看@David,谢谢你提供的信息。但是,基于此,我无法独自解决此问题。我正在读取一个外部数据:edges=ReadList[“\\Workspace\\data\\graph\\1.edg”];labels=ReadList[“\\Workspace\\data\\graph\\1.lab”];我需要一个有效的解决方案,而且我不知道如何在“数据库”方法和图形数据之间转换。
edges = {0 -> 1, 1 -> 2, 2 -> 3}

labels = {0 -> A, 1 -> B, 2 -> A, 3 -> B}
styles = labels /. {A -> Red, B -> Green}
Graph[edges, VertexLabels -> labels, VertexStyle -> styles]