events.pl 1.59 KB
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1 2 3
:- module(
  events,
  [
Thierry Martinez's avatar
Thierry Martinez committed
4
    % Public API
Thierry Martinez's avatar
Thierry Martinez committed
5
    add_event/2,
Thierry Martinez's avatar
Thierry Martinez committed
6 7
    list_events/0,
    list_model_events/0
Thierry Martinez's avatar
Thierry Martinez committed
8 9 10 11
  ]
).


Thierry Martinez's avatar
Thierry Martinez committed
12 13 14
:- devdoc('\\section{Commands}').


Thierry Martinez's avatar
Thierry Martinez committed
15 16 17
add_event(Condition, ParameterValues) :-
  biocham_command(*),
  type(Condition, condition),
Thierry Martinez's avatar
Thierry Martinez committed
18
  type(ParameterValues, '*'(parameter = arithmetic_expression)),
Thierry Martinez's avatar
Thierry Martinez committed
19 20 21 22 23 24
  doc('
    sets up an event that will be fired each time the condition given as first
    argument goes from false to true.
    This command is effective in numerical simulations only.
    Upon firing, the parameters receive new values
    computed from the expression.
Thierry Martinez's avatar
Thierry Martinez committed
25 26 27 28 29 30 31 32
    The initial values of the parameters are restored after the simulation.
    \\begin{example}
  '),
  biocham_silent(clear_model),
  biocham('MA'(k) for a => b),
  biocham(set_parameter(k = 1)),
  biocham(add_event(b > 0.5, k = 0)),
  biocham(present(a)),
Thierry Martinez's avatar
Thierry Martinez committed
33
  biocham(numerical_simulation(2, maximum_step_size: 1e-3)),
Thierry Martinez's avatar
Thierry Martinez committed
34 35 36 37
  biocham(plot),
  doc('
    \\end{example}
  '),
Thierry Martinez's avatar
Thierry Martinez committed
38
  add_item([kind: event, item: event(Condition, ParameterValues)]).
Thierry Martinez's avatar
Thierry Martinez committed
39 40 41 42 43 44


list_events :-
  biocham_command,
  doc('lists all the declared events.'),
  list_items([kind: event]).
Thierry Martinez's avatar
Thierry Martinez committed
45 46 47 48 49 50 51 52 53 54 55


:- devdoc('\\section{Private predicates}').


list_model_events :-
  devdoc('
    lists all the events in a loadable syntax
    (auxiliary predicate of list_model).
  '),
  \+ (
Thierry Martinez's avatar
Thierry Martinez committed
56 57 58
    item(
      [no_inheritance, kind: event, item: event(Condition, ParameterValues)]
    ),
Thierry Martinez's avatar
Thierry Martinez committed
59
    \+ (
Thierry Martinez's avatar
Thierry Martinez committed
60 61 62 63 64 65 66
      format('add_event(~w, ', [Condition]),
      write_successes(
        member(Parameter = Value, ParameterValues),
        write(', '),
        format('~w = ~w', [Parameter, Value])
      ),
      write(').\n')
Thierry Martinez's avatar
Thierry Martinez committed
67 68
    )
  ).