Наличие некоторого файла XML / Json для компиляции в Graphiz / Finite State Automaton.Какие-либо предложения? - PullRequest
1 голос
/ 02 ноября 2010

У меня есть задача, где мне нужно сделать несколько существующих снимков [которые показывают некоторые автоматы (DFA, NFA, машины Тьюринга)] и каким-то образом преобразовать их в формат, который позволяет мне использовать данные для представления их как автоматов а также скомпилировать его в некоторое графическое представление. Кто-нибудь из вас делал что-то подобное раньше? Существуют ли какие-либо библиотеки / фреймворки Python, которые позволяют мне представлять некоторые автоматические данные графически?

1 Ответ

1 голос
/ 06 ноября 2010

Graphviz может предоставить решение. Представление данных для направленного ациклического графа (DAG) является прямым и простым на рисунке. Его легко можно «прочитать» на диаграмме, если вы делаете это вручную, как подсказывает ваш комментарий. Представление сложной диаграммы (несколько отдельных панелей, каждая из которых содержит независимый DAG, перечислены ниже. Как говорит @Constantin, DFA и NFA могут быть представлены в виде DAG. Я не уверен в том, какие обозначения используются для машин Тьюринга, но несколько видов структурированной диаграммы можно считывать аналогичным образом, например, древовидные структуры; неориентированные графы. Я также прилагаю копию получившейся диаграммы. Отдельные строки файла .dot представляют собой элементы данных, которые вы ищете.

    Digraph {
graph [label="Problem Frame\nmapping editor\n",labelloc=t,fontsize=18,compound=true];
node[shape = record,fontsize = 10];
edge[arrowtail=none,arrowhead=none,arrowsize=0.8,color=ivory4,fontsize=8];

subgraph "cluster0" {
graph [label = "Model Fragment"];
A01 [label = "{Domain|class::marking\lisTemplate::boolean default false\lname::name\ltype::domain type\l}"];
A02 [label = "{Requirement|isTemplate::boolean default false\lname::name\l}"];
A03 [label = "{Requirement Reference\n\<\<associative\>\>|content::name\lis template::boolean default false\ltype::requirement reference type\l}",shape=Mrecord,style=dotted];
A04 [label = "{Shared Phenomena Set\n\<\<associative\>\>|content::name\lis template::boolean default false\ltype::phenomena type\l}",shape=Mrecord,style=dotted];

/* 1:1-0:M */
edge[dir=both,arrowhead=crowodot,arrowtail=none];
A01 -> A03 [style=dashed];
A01 -> A04 [style = dashed];
A01 -> A04 [style = dashed];
A02 -> A03 [style = dashed];
}

subgraph "cluster1" {
graph [label = "\>\>\>",fontsize = 24];
B01 [label = "{Domain}"];
B02 [label = "{Requirement}"];
B03 [label = "{Requirement\nReference\n}",shape=Mrecord,style=dotted];
B04 [label = "{Shared\nPhenomena\nSet\n}",shape=Mrecord,style=dotted];
F01 [label = "{C0001|if \[-\> controls -\> describes.isTemplate\]\l}"];
F02 [label = "{C0002|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F03 [label = "{C0003|if \[-\> controls -\> describes.type = designed\]\l}"];
F04 [label = "{C0004|if \[-\> controls -\> describes.type = given\]\l}"];
F05 [label = "{C0005|if \[-\> controls -\> describes.type = machine\]\l}"];
F06 [label = "{C0006|if \[-\> controls -\> describes.marking = biddable\]\l}"];
F07 [label = "{C0007|if \[-\> controls -\> describes.marking = causal\]\l}"];
F08 [label = "{C0008|if \[-\> controls -\> describes.marking = lexical\]\l}"];
F09 [label = "{C0009|if \[-\> controls -\> describes.marking = null\]\l}"];
F10 [label = "{C0010|if \[-\> controls -\> describes.isTemplate\]\l}"];
F11 [label = "{C0011|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F12 [label = "{C0012|if \[-\> controls -\> describes.isTemplate\]\l}"];
F13 [label = "{C0013|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F14 [label = "{C0014|if \[-\> controls -\> describes.type = non-constraining\]\l}"];
F15 [label = "{C0015|if not \[-\> controls -\> describes.type = constraining\]\l}"];
F16 [label = "{C0016|if \[-\> controls -\> describes.isTemplate\]\l}"];
F17 [label = "{C0017|if not \[-\> controls -\> describes.isTemplate\]\l}"];
F18 [label = "{C0018|if \[-\> controls -\> describes.type = causal\]\l}"];
F19 [label = "{C0019|if \[-\> controls -\> describes.type = event\]\l}"];
F20 [label = "{C0020|if \[-\> controls -\> describes.type = symbolic\]\l}"];

edge [style = solid];
B01 -> F01 -> F02 -> F03 -> F04 -> F05 -> F06 -> F07 -> F08 -> F09;
B02 -> F10 -> F11;
B03 -> F12 -> F13 -> F14 -> F15;
B04 -> F16 -> F17 -> F18 -> F19 -> F20;

edge [style = invis];
B01 -> B02 -> B03 -> B04;
}

subgraph "cluster2" {
graph [label = "\<\<\<",fontsize = 24];
C01 [label = "{Edge|name := Constraining Reference\larrowtail := normal\ldir := both\lpermitted node1 := domain icon\lpermitted node2 := requirement icon\lstyle := dotted\l}"];
D02 [label = "{Attribute|name::oName\lvalue::-\> describes\l-\> described by.content\l}"];
C02 [label = "{Diagram|name := Frame Diagram\l}"];
C03 [label = "{Node|name := Domain Icon\lcolor = gray\lfillcolor = gold\lfontsize := 12\llabel := describes.preLabel\l + oName + describes.postLabel\lshape := Mrecord\lstyle := filled\l}"];
D03 [label = "{Attribute|name::oClass\lvalue :=-\> describes\l-\> described by.class\l}"];
D04 [label = "{Attribute|name::oName\lvalue := -\> describes\l-\> described by.name\l}"];
D05 [label = "{Attribute|name::postlabel\lvalue := \}\"\l}"];
D06 [label = "{Attribute|name::postlabel\lvalue := \|\{\|b\}\}\"\l}"];
D07 [label = "{Attribute|name::postlabel\lvalue := \|\{\|c\}\}\"\l}"];
D08 [label = "{Attribute|name::postlabel\lvalue := \|\{\|x\}\}\"\l}"];
D09 [label = "{Attribute|name::prelabel\lvalue := \"\{\|\l}"];
D10 [label = "{Attribute|name::prelabel\lvalue := \"\{\l}"];
D11 [label = "{Attribute|name::prelabel\lvalue := \"\{\|\|\l}"];
D12 [label = "{Attribute|name::oType\lvalue := -\> describes \l-\> described by.type\l}"];
C04 [label = "{Holding Box|name := Domain Template\lcolor := slategray\lfillcolor := white\lfontcolor := slategray\lfontsize := 9\llabel := oName\lreadonly := true\l}"];
D13 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.name\l}"];
C05 [label = "{Edge|name := Edge Template\lcolor := white\llabel = oName\lstyle := invis\l}"];
D14 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.contents\l}"];
C06 [label = "{Node|name := Phenomena\l}"];
D15 [label = "{Attribute|name::oName\lvalue::-\> describes\l\-\> described by.contents\l}"];
C07 [label = "{Edge|name := Reference\l}"];
D16 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.contents\l}"];
C08 [label = "{Node|name := Requirement Icon\l}"];
D17 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.name\l}"];
C09 [label = "{Edge|name := Shared Phenomena\l}"];
D18 [label = "{Attribute|name::oName\lvalue := -\> describes \l-\> described by.contents\l}"];
D19 [label = "{Attribute|name::oType\lvalue := C\l}"];
D20 [label = "{Attribute|name::oType\lvalue := E\l}"];
D21 [label = "{Attribute|name::oType\lvalue := Y\l}"];

C01 -> D02;
C03 -> D03 -> D04 -> D05 -> D06 -> D07 -> D08 -> D09 -> D10 -> D11 -> D12;
C04 -> D13;
C05 -> D14;
C06 -> D15;
C07 -> D16;
C08 -> D17;
C09 -> D18 -> D19 -> D20 -> D21;

edge[style="invis"];
C01 -> C02 -> C03 -> C04 -> C05 -> C06 -> C07 -> C08 -> C09;
}

subgraph "cluster5" {
graph [label = "Editor Elements"];
E01 [label = "{Node\n|color::color\lfillcolor::fillcolor\lfontname::font\lfontsize::fontsize\llabel::name\lname::name\lreadonly::boolean default false\lshape::shape\lstyle::style\l}"];
E02 [label = "{Edge\n|arrowtail::edge end\ldir::dir\lname::name\lpermitted node1::name\lpermitted node2::name\lstyle::style\l}"];
E03 [label = "{Attribute\n|name::name\lvalue::text\l}"];
E04 [label = "{Diagram\n|defaults::attributes\ledge defaults::attributes\lname::name\lnode attributes::attributes\l}"];
E05 [label = "{Holding Box|color::color\lfillcolor::fillcolor\lfontname::font\lfontsize::fontsize\llabel::name\lname::name\lreadonly::boolean default false\lshape::shape\lstyle::style\l}"];

/* 0:1-N:M */
E01 -> E02 [arrowhead = crowodot, label = "links", taillabel = " 2:2"];

/* 1:1-0:M  */
edge[dir=both,arrowtail=none,arrowhead=crowodot];
E04 -> E01 [label = nodes];
E04 -> E02 [label = edges];
E04 -> E05 [label = "holding boxes"];

/* 0:1-0:M  */
edge[dir=both,arrowtail=odot,arrowhead=crowodot];
E05 -> E01 [label = "contained nodes"];
E05 -> E02 [label = "contained edges"];
E05 -> E05 [label = contains];

/* 0:1-0:M  */
edge[dir=both,arrowtail=odot,arrowhead=crowodot];
E01 -> E03 [label = characteristics];
E02 -> E03 [label = parameters];
E04 -> E03 [label = attributes];
E04 -> E03 [label = attributes];
E04 -> E03 [label = attributes];
}

{rank = min B01 C01}

edge[style="solid"];
F01 -> C04 [ltail = cluster1];
F02 -> C03 [ltail = cluster1];
F03 -> D09 [ltail = cluster1];
F04 -> D10 [ltail = cluster1];
F05 -> D11 [ltail = cluster1];
F06 -> D06 [ltail = cluster1];
F07 -> D07 [ltail = cluster1];
F08 -> D08 [ltail = cluster1];
F09 -> D05 [ltail = cluster1];
F10 -> C04 [ltail = cluster1];
F11 -> C06 [ltail = cluster1];
F11 -> C08 [ltail = cluster1];
F12 -> C05 [ltail = cluster1];
F14 -> C07 [ltail = cluster1];
F15 -> C01 [ltail = cluster1];
F16 -> C05 [ltail = cluster1];
F17 -> C06 [ltail = cluster1];
F17 -> C09 [ltail = cluster1];
F18 -> D19 [ltail = cluster1];
F19 -> D20 [ltail = cluster1];
F20 -> D21 [ltail = cluster1]; 
}

alt text

...