Commit e36e4831 authored by Thierry Martinez's avatar Thierry Martinez

Influence graphs

parent 5c2ec4e5
......@@ -34,10 +34,14 @@
get_attribute/3,
set_attribute/3,
place/2,
place/3,
transition/2,
transition/3,
kind/3,
kind/4,
add_vertex/3,
add_edge/3
add_edge/3,
add_edge/4
]
).
......@@ -349,10 +353,18 @@ place(GraphId, NameList) :-
kind(GraphId, NameList, place).
place(GraphId, Name, VertexId) :-
kind(GraphId, Name, place, VertexId).
transition(GraphId, NameList) :-
kind(GraphId, NameList, transition).
transition(GraphId, Name, VertexId) :-
kind(GraphId, Name, transition, VertexId).
kind(GraphId, NameList, Kind) :-
list(NameList),
!,
......@@ -364,6 +376,10 @@ kind(GraphId, NameList, Kind) :-
).
kind(GraphId, Name, Kind) :-
kind(GraphId, Name, Kind, _).
kind(GraphId, Name, Kind, VertexId) :-
add_vertex(GraphId, Name, VertexId),
set_attribute(VertexId, kind: Kind).
......@@ -382,6 +398,20 @@ add_edge(GraphId, Edge, EdgeId) :-
Edge = (From -> To),
add_vertex(GraphId, From, FromId),
add_vertex(GraphId, To, ToId),
add_edge(GraphId, Edge, FromId, ToId, EdgeId).
add_edge(GraphId, FromId, ToId, EdgeId) :-
item([id: FromId, item: From]),
item([id: ToId, item: To]),
Edge = (From -> To),
add_edge(GraphId, Edge, FromId, ToId, EdgeId).
:- devdoc('\\section{Private predicates}').
add_edge(GraphId, Edge, FromId, ToId, EdgeId) :-
(
item([parent: GraphId, kind: edge, key: Edge, id: EdgeId])
->
......@@ -393,9 +423,6 @@ add_edge(GraphId, Edge, EdgeId) :-
).
:- devdoc('\\section{Private predicates}').
find_vertex(GraphId, Name, Id) :-
find_item([parent: GraphId, kind: vertex, key: Name, id: Id]).
......
......@@ -8,6 +8,7 @@
% Public API
is_influence_model/0,
check_influence_model/0,
with_influence_model/1,
list_model_influences/0,
influence/6
]
......@@ -90,6 +91,28 @@ check_influence_model :-
).
with_influence_model(G) :-
(
is_influence_model
->
G
;
single_model(ReactionModel),
setup_call_cleanup(
new_model(InfluenceModel),
(
influence_model(ReactionModel, InfluenceModel),
set_current_models([InfluenceModel]),
G
),
(
delete_item(InfluenceModel),
set_current_models([ReactionModel])
)
)
).
list_model_influences :-
devdoc('
lists all the influence rules in a loadable syntax
......
:- module(
influence_graphs,
[
% Commands
influence_graph/0,
draw_influences/0,
% Public API
influence_graph/1
]
).
:- devdoc('\\section{Commands}').
influence_graph :-
biocham_command,
doc('builds the influence graph of the current model.'),
new_graph,
set_graph_name(influence_graph),
get_current_graph(GraphId),
influence_graph(GraphId).
draw_influences :-
biocham_command,
doc('
Draws the influence graph of the current model.
\\begin{example}
'),
biocham_silent(clear_model),
biocham(load(library:examples/mapk/mapk)),
biocham(draw_influences),
doc('
\\end{example}
'),
setup_call_cleanup(
new_graph(GraphId),
(
influence_graph(GraphId),
draw_graph(GraphId)
),
delete_item(GraphId)
).
:- devdoc('\\section{Public API}').
influence_graph(GraphId) :-
with_influence_model((
influence_graphs:influence_graph_aux(GraphId)
)).
:- devdoc('\\section{Private predicates}').
influence_graph_aux(GraphId) :-
set_counter(influence, 0),
\+ (
item([kind: influence, item: Item]),
influence(Item, Force, PositiveInputs, NegativeInputs, Sign, Output),
\+ (
count(influence, InfluenceCount),
format(atom(InfluenceCounter), 'influence~d', [InfluenceCount]),
transition(GraphId, InfluenceCounter, TransitionId),
set_attribute(TransitionId, sign: Sign),
set_attribute(TransitionId, force: Force),
\+ (
member(PositiveInput, PositiveInputs),
\+ (
place(GraphId, PositiveInput, PlaceId),
add_edge(GraphId, PlaceId, TransitionId, EdgeId),
set_attribute(EdgeId, sign: '+')
)
),
\+ (
member(NegativeInput, NegativeInputs),
\+ (
place(GraphId, NegativeInput, PlaceId),
add_edge(GraphId, PlaceId, TransitionId, EdgeId),
set_attribute(EdgeId, sign: '-')
)
),
place(GraphId, Output, PlaceId),
add_edge(GraphId, TransitionId, Output, _)
)
).
......@@ -25,6 +25,7 @@
current_models/1,
single_model/1,
new_model/1,
set_current_models/1,
add_item/1,
replace_item/4,
change_item/4,
......@@ -302,6 +303,16 @@ new_model(Id) :-
).
set_current_models(Models) :-
(
Models = []
->
throw(error(cannot_select_no_models))
;
set_selection(top, current_models, Models)
).
add_item(Options) :-
memberchk(kind: Kind, Options),
optional(item: Item, Options),
......@@ -924,16 +935,6 @@ load_biocham_stream(Stream) :-
).
set_current_models(Models) :-
(
Models = []
->
throw(error(cannot_select_no_models))
;
set_selection(top, current_models, Models)
).
not_fresh :-
retractall(fresh).
......
......@@ -69,6 +69,7 @@
- plot.pl
** Listing and editing graphs
- reaction_graphs.pl
- influence_graphs.pl
- graph_editor.pl
- graphviz.pl
** Numerical temporal properties
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment