influence_graphs.pl 1.99 KB
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
:- 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),
68 69
      set_attribute(TransitionId, sign = Sign),
      set_attribute(TransitionId, force = Force),
Thierry Martinez's avatar
Thierry Martinez committed
70 71 72 73 74
      \+ (
        member(PositiveInput, PositiveInputs),
        \+ (
          place(GraphId, PositiveInput, PlaceId),
          add_edge(GraphId, PlaceId, TransitionId, EdgeId),
75
          set_attribute(EdgeId, sign = '+')
Thierry Martinez's avatar
Thierry Martinez committed
76 77 78 79 80 81 82
        )
      ),
      \+ (
        member(NegativeInput, NegativeInputs),
        \+ (
          place(GraphId, NegativeInput, PlaceId),
          add_edge(GraphId, PlaceId, TransitionId, EdgeId),
83
          set_attribute(EdgeId, sign = '-')
Thierry Martinez's avatar
Thierry Martinez committed
84 85
        )
      ),
86 87
      place(GraphId, Output, OutputId),
      add_edge(GraphId, TransitionId, OutputId, _)
Thierry Martinez's avatar
Thierry Martinez committed
88 89
    )
  ).