Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VIGNET Pierre
cadbiom
Commits
a9d98e92
Commit
a9d98e92
authored
Jun 03, 2017
by
VIGNET Pierre
Browse files
Rework functions in trajectories processing;fix typos;fix filenames
parent
34445a83
Changes
1
Hide whitespace changes
Inline
Side-by-side
command_line/cadbiom_cmd/solution_repr.py
View file @
a9d98e92
...
...
@@ -366,12 +366,11 @@ def parse_condition(condition, all_nodes, inhibitors_nodes):
# print(dir(ret))
def
build_graph
(
i
,
sol
,
steps
,
transitions
):
def
build_graph
(
sol
ution
,
steps
,
transitions
):
"""Build a graph for the given solution.
- Get & make all needed edges
- Draw graph
- Save graph in svg/graphml
- Build graph
:param arg1: Frontier places.
:param arg2: List of steps (with events in each step).
...
...
@@ -380,6 +379,13 @@ def build_graph(i, sol, steps, transitions):
:type arg1: <str>
:type arg2: <list <list>>
:type arg3: <dict <list <tuple <str>, <str>, <dict <str>: <str>>>>
:return:
- Networkx graph object.
- Nodes corresponding to transitions with conditions.
- All nodes in the model
- Edges between transition node and nodes in condition
- Normal transitions without condition
:rtype: <networkx.classes.digraph.DiGraph>, <list>, <list>, <list>, <list>
"""
def
filter_transitions
(
step_event
):
...
...
@@ -478,7 +484,7 @@ def build_graph(i, sol, steps, transitions):
# Get & make all needed edges ##############################################
LOGGER
.
info
(
"BUILD GRAPH FOR SOL: "
+
str
(
sol
))
LOGGER
.
info
(
"BUILD GRAPH FOR SOL: "
+
str
(
sol
ution
))
LOGGER
.
debug
(
"STEPS: "
+
str
(
steps
))
#
# print(transitions['_h_2755'])
...
...
@@ -487,7 +493,7 @@ def build_graph(i, sol, steps, transitions):
# print(transitions['_h_3426'])
# exit()
frontier_places
=
sol
.
split
(
' '
)
frontier_places
=
sol
ution
.
split
(
' '
)
edges_with_cond
=
list
()
# Edges between ori <-> transition node <-> ext
edges_in_cond
=
list
()
# Edges between transition node and nodes in condition
transition_nodes
=
list
()
# Nodes inserted because of condition in transition
...
...
@@ -525,6 +531,35 @@ def build_graph(i, sol, steps, transitions):
G
.
add_edges_from
(
edges_with_cond
)
G
.
add_edges_from
(
edges_in_cond
)
return
G
,
transition_nodes
,
all_nodes
,
edges_in_cond
,
edges
def
draw_graph
(
solution
,
solution_index
,
G
,
transition_nodes
,
all_nodes
,
edges_in_cond
,
edges
):
"""Draw graph with colors and export it to graphml format.
.. note:: Legend:
- red: frontier places (in solution variable),
- white: middle edges,
- blue: transition edges
:param arg1: Solution string (mostly a set of frontier places).
:param arg2: Index of the solution in the Cadbiom result file
(used to distinguish exported filenames).
:param arg3: Networkx graph object.
:param arg4: Nodes corresponding to transitions with conditions.
:param arg5: All nodes in the model
:param arg6: Edges between transition node and nodes in condition
:param arg7: Normal transitions without condition
:type arg1: <str>
:type arg2: <int>
:type arg3: <networkx.classes.digraph.DiGraph>
:type arg4: <list>
:type arg5: <list>
:type arg6: <list>
:type arg7: <list>
"""
# Drawing ##################################################################
# draw_circular(G, **kwargs) On a circle.
...
...
@@ -550,6 +585,7 @@ def build_graph(i, sol, steps, transitions):
# - red: frontier places (in solution variable),
# - white: middle edges,
# - blue: transition edges
frontier_places
=
set
(
solution
.
split
(
' '
))
def
color_map
(
node
):
# print("color for:", node)
if
node
in
frontier_places
:
# Test first (see cond below)
...
...
@@ -578,26 +614,26 @@ def build_graph(i, sol, steps, transitions):
edges_labels
=
{(
edge
[
0
],
edge
[
1
]):
edge
[
2
][
'label'
]
for
edge
in
edges
}
nx
.
draw_networkx_edge_labels
(
G
,
pos
,
edges_labels
,
label_pos
=
0.3
)
# Save & show
date
=
dt
.
datetime
.
now
().
strftime
(
"%H-%M-%S
-%f
"
)
date
=
dt
.
datetime
.
now
().
strftime
(
"%H-%M-%S"
)
plt
.
legend
()
# plt.savefig(GRAPHS_DIR + date + '_' + sol[:75] + ".svg", format="svg")
# plt.show()
nx
.
write_graphml
(
G
,
GRAPHS_DIR
+
date
+
'_'
+
str
(
i
)
+
'_'
+
sol
[:
75
]
+
".graphml"
"{}{}_{}_{}.graphml"
.
format
(
GRAPHS_DIR
,
date
,
solution_index
,
solution
[:
75
]
)
)
#nx.write_gml(G, date + '_' + sol + ".gml")
def
process_solutions
(
sol_steps
,
transitions
):
"""Build a graph per solution"""
for
i
,
(
sol
,
steps
)
in
enumerate
(
sol_steps
):
for
sol_index
,
(
sol
,
steps
)
in
enumerate
(
sol_steps
):
build_graph
(
i
,
sol
,
steps
,
transitions
)
draw_graph
(
sol
,
sol_index
,
*
build_graph
(
sol
,
steps
,
transitions
)
)
def
test_main
():
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment