Commit fe0887ee authored by Thierry Martinez's avatar Thierry Martinez

Multi-events

parent f69c8dc9
......@@ -58,8 +58,16 @@ list_model_events :-
(auxiliary predicate of list_model).
'),
\+ (
item([no_inheritance, kind: event, item: event(Condition, ParameterValue)]),
item(
[no_inheritance, kind: event, item: event(Condition, ParameterValues)]
),
\+ (
format('add_event(~w, ~w).\n', [Condition, ParameterValue])
format('add_event(~w, ', [Condition]),
write_successes(
member(Parameter = Value, ParameterValues),
write(', '),
format('~w = ~w', [Parameter, Value])
),
write(').\n')
)
).
......@@ -96,19 +96,10 @@ list_model_functions :-
item([no_inheritance, kind: function])
->
write('function(\n'),
assertz(first),
\+ (
write_successes(
item([no_inheritance, kind: function, item: function(Head = Body)]),
\+ (
(
retract(first)
->
true
;
write(',\n')
),
format(' ~w = ~w', [Head, Body])
)
write(',\n'),
format(' ~w = ~w', [Head, Body])
),
write('\n).\n')
;
......
......@@ -317,19 +317,29 @@ events(int e[], double p[], double x[])
{
'),
\+ (
nth0(EventIndex, Events, (Condition -> ParameterIndex = Value)),
nth0(EventIndex, Events, (Condition -> ParameterValues)),
\+ (
format(' if (!e[~d] && (', [EventIndex]),
write_condition(Condition),
format(
')) {
e[~d] = 1;
e[~d] = 1;',
[EventIndex]
),
\+ (
member(ParameterIndex = Value, ParameterValues),
\+ (
format(
'
p[~d] = ',
[EventIndex, ParameterIndex]
[ParameterIndex]
),
write_arithmetic_expression(Value),
write(';')
)
),
write_arithmetic_expression(Value),
format(
';
'
}
else if (e[~d] && !(',
[EventIndex]
......
......@@ -87,7 +87,7 @@ numerical_simulation(Time) :-
numerical_simulation:variable/2,
numerical_simulation:equation/2,
numerical_simulation:parameter/2,
numerical_simulation:conditional_event/1
numerical_simulation:conditional_event/2
],
(
numerical_simulation:solve(
......@@ -111,8 +111,7 @@ numerical_simulation(Time) :-
:- dynamic(parameter/2).
:- dynamic(conditional_event/1).
:- dynamic(conditional_event/2).
solve(
......@@ -204,18 +203,33 @@ gather_events(Events) :-
findall(
Event,
(
item([kind: event, item: event(Condition, Parameter = Value)]),
bagof(
ParameterValue,
ParameterValues ^ (
item([kind: event, item: event(Condition, ParameterValues)]),
member(ParameterValue, ParameterValues)
),
ParameterValues
),
convert_condition(Condition, ConditionIndexed),
parameter(Parameter, ParameterIndex),
convert_expression(Value, ValueIndexed),
Event = (ConditionIndexed -> ParameterIndex = ValueIndexed)
maplist(convert_parameter, ParameterValues, IndexedParameterValues),
Event = (ConditionIndexed -> IndexedParameterValues)
;
conditional_event(Event)
conditional_event(ConditionIndexed, ParameterIndex),
(
Event = (ConditionIndexed -> [ParameterIndex = 1])
;
Event = (not ConditionIndexed -> [ParameterIndex = 0])
)
),
Events
).
convert_parameter(Parameter = Value, ParameterIndex = ValueIndexed) :-
parameter(Parameter, ParameterIndex),
convert_expression(Value, ValueIndexed).
enumerate_variables :-
set_counter(variable_counter, 0),
......@@ -272,10 +286,15 @@ convert_name(Parameter, p(ParameterIndex)) :-
convert_expression(if Condition then IfTrue else IfFalse, IndexedExpression) :-
!,
count(parameter_counter, ParameterIndex),
convert_condition(Condition, IndexedCondition),
assertz(conditional_event(IndexedCondition -> ParameterIndex = 1)),
assertz(conditional_event(not IndexedCondition -> ParameterIndex = 0)),
(
conditional_event(IndexedCondition, ParameterIndex)
->
true
;
count(parameter_counter, ParameterIndex),
assertz(conditional_event(IndexedCondition, ParameterIndex))
),
convert_expression(IfTrue, IndexedIfTrue),
convert_expression(IfFalse, IndexedIfFalse),
IndexedExpression =
......
......@@ -73,18 +73,10 @@ list_model_parameters :-
->
write('set_parameter(\n'),
assertz(first),
\+ (
write_successes(
item([kind: parameter, item: parameter(Parameter = Value)]),
\+ (
(
retract(first)
->
true
;
write(',\n')
),
format(' ~w = ~w', [Parameter, Value])
)
write(',\n'),
format(' ~w = ~w', [Parameter, Value])
),
write('\n).\n')
;
......
......@@ -200,19 +200,10 @@ list_model_options :-
item([no_inheritance, kind: option])
->
write('option(\n'),
assertz(first),
\+ (
write_successes(
item([kind: option, item: option(Option: Value)]),
\+ (
(
retract(first)
->
true
;
write(',\n')
),
format(' ~w: ~w', [Option, Value])
)
write(',\n'),
format(' ~w: ~w', [Option, Value])
),
write('\n).\n')
;
......
......@@ -5,6 +5,7 @@
camel_case/2,
set_to_list/2,
list_enumeration/2,
write_successes/3,
equals_to_list/2,
list_to_equals/2,
list/1,
......@@ -93,6 +94,26 @@ list_enumeration([H | List], (H, Enum)) :-
list_enumeration(List, Enum).
:- dynamic(first/0).
write_successes(Goal, WriteSeparator, WriteSuccess) :-
assertz(first),
\+ (
Goal,
\+ (
(
retract(first)
->
true
;
WriteSeparator
),
WriteSuccess
)
).
equals_to_list(A = B, List) :-
!,
equals_to_list(A, LA),
......
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