Commit 73aaf75a authored by Thierry Martinez's avatar Thierry Martinez

Faster table deletion

parent cfdda700
......@@ -766,9 +766,13 @@ write_doc_item(devdoc(DocBody), Stream, Type) :-
).
write_doc_item(biocham_silent(Command), _Stream, _Type) :-
print(Command),
nl,
command(Command).
write_doc_item(biocham(Command), Stream, _Type) :-
print(Command),
nl,
with_output_to(
atom(Output),
command(Command)
......
......@@ -30,7 +30,7 @@ add_event(Condition, ParameterValues) :-
biocham(set_parameter(k = 1)),
biocham(add_event(b > 0.5, k = 0)),
biocham(present(a)),
biocham(numerical_simulation(2, method: msbdf, maximum_step_size: 1e-3)),
biocham(numerical_simulation(2, maximum_step_size: 1e-3)),
biocham(plot),
doc('
\\end{example}
......
......@@ -40,6 +40,7 @@
list_ids/1,
list_ids/2,
print_item/1,
deleting/1,
delete_item/1,
delete_items/1,
add_dependency/2,
......@@ -506,6 +507,9 @@ print_item(Id) :-
).
:- dynamic(deleting/1).
delete_item(Options) :-
list(Options),
!,
......@@ -514,10 +518,21 @@ delete_item(Options) :-
delete_item(Id) :-
(
deleting(Id)
->
throw(error(circular_delete(Id), delete_item))
;
assertz(deleting(Id))
),
\+ (
at_delete_goal(Id, Goal),
\+ (
Goal
->
true
;
throw(error(delete_goal_failure(Id), delete_item))
)
),
retract(item(Id, _Model, KindItem, _Item)),
......@@ -563,7 +578,8 @@ delete_item(Id) :-
)
;
true
).
),
retract(deleting(Id)).
delete_items(Options) :-
......
......@@ -8,6 +8,7 @@
patch_solution/2,
kinetics/1,
arithmetic_expression/1,
patch_arithmetic_expression/2,
condition/1,
op(720, fy, not),
op(740, xfy, and),
......@@ -89,31 +90,34 @@ solution(Object) :-
object(Object).
patch_solution(Solution0 + Solution1, NewSolution0 + NewSolution1) :-
patch_solution(A - B, Result) :-
!,
patch_solution(Solution0, NewSolution0),
patch_solution(Solution1, NewSolution1).
patch_solution(A, RA),
patch_solution(B, RB),
patch_solution_effective(RA - RB, Result).
patch_solution(Solution0 - Solution1, NewSolution) :-
patch_solution(A + B, RA + RB) :-
!,
patch_solution(Solution0, Solution1, NewSolution).
patch_solution(A, RA),
patch_solution(B, RB).
patch_solution(Solution, Solution).
patch_solution(Solution0 + Solution1, Solution2, Solution0 + NewSolution) :-
patch_solution_effective(A + B - C, A + BC) :-
!,
patch_solution(Solution1, Solution2, NewSolution).
patch_solution(B - C, BC).
patch_solution(Solution0 * Solution1, Solution2, Solution0 * NewSolution) :-
patch_solution_effective(A * B - C, A * BC) :-
!,
patch_solution(Solution1, Solution2, NewSolution).
patch_solution(B - C, BC).
patch_solution(Solution0 - Solution1, Solution2, NewSolution) :-
patch_solution_effective(A - B * C, AB * C) :-
!,
patch_solution(Solution0, Solution1 - Solution2, NewSolution).
patch_solution(A - B, AB).
patch_solution(Solution0, Solution1, Solution0 - Solution1).
patch_solution_effective(A - B, A - B).
:- grammar(kinetics).
......@@ -238,6 +242,27 @@ arithmetic_expression(Name) :-
name(Name).
patch_arithmetic_expression(
if Condition then IfBody,
if Condition then IfTrue else IfFalse
) :-
!,
(
extract_if_body(IfBody, IfTrue, IfFalse)
->
true
;
throw(
error(
illformed_conditional(if Condition then IfBody),
patch_arithmetic_expression
)
)
).
patch_arithmetic_expression(Expression, Expression).
:- devdoc('\\section{Public API}').
......@@ -247,3 +272,17 @@ reaction_predicate(_ for Reaction) :-
reaction_predicate(_ => _).
reaction_predicate(_ <=> _).
:- devdoc('\\section{Internal predicates}').
extract_if_body(IfTrue else IfFalse, IfTrue, IfFalse).
extract_if_body(
if Condition then Cont,
if Condition then SubTrue else SubFalse,
Tail
) :-
extract_if_body(Cont, SubTrue, SubTail),
extract_if_body(SubTail, SubFalse, Tail).
:- use_module(library(plunit)).
:- begin_tests(reaction_rules).
test(
'patch_arithmetic_expression',
[Patched == (if a then (if b then c else d) else (if e then f else g))]
) :-
patch_arithmetic_expression(
if a then
if b then c else d
else
if e then f else g,
Patched
).
test(
'patch_solution',
[Patched == a * (b-c-d) + e * (f-g-h)]
) :-
patch_solution(a * b-c-d + e * f-g-h, Patched).
:- end_tests(reaction_rules).
......@@ -306,40 +306,52 @@ declare_column(Id, ColumnIndex, Name) :-
perform_column_delete(ColumnId) :-
get_parent(ColumnId, TableId),
get_annotation(ColumnId, index, ColumnIndex),
\+ (
item([parent:TableId, kind: row, item: Row, id: RowId]),
(
deleting(TableId)
->
true
;
get_annotation(ColumnId, index, ColumnIndex),
\+ (
get_annotation(RowId, index, RowIndex),
Row =.. [row | RowItems],
nth0(ColumnIndex, RowItems, _Deleted, NewRowItems),
NewRow =.. [row | NewRowItems],
replace_item(RowId, row, RowIndex, NewRow)
)
),
\+ (
item([parent:TableId, kind: column, item: Column0, id: ColumnId0]),
get_annotation(ColumnId0, index, ColumnIndex0),
ColumnIndex0 > ColumnIndex,
item([parent:TableId, kind: row, item: Row, id: RowId]),
\+ (
get_annotation(RowId, index, RowIndex),
Row =.. [row | RowItems],
nth0(ColumnIndex, RowItems, _Deleted, NewRowItems),
NewRow =.. [row | NewRowItems],
replace_item(RowId, row, RowIndex, NewRow)
)
),
\+ (
ColumnIndex1 is ColumnIndex0 - 1,
replace_item(ColumnId0, column, ColumnIndex1, Column0),
set_annotation(ColumnId0, index, ColumnIndex1)
item([parent:TableId, kind: column, item: Column0, id: ColumnId0]),
get_annotation(ColumnId0, index, ColumnIndex0),
ColumnIndex0 > ColumnIndex,
\+ (
ColumnIndex1 is ColumnIndex0 - 1,
replace_item(ColumnId0, column, ColumnIndex1, Column0),
set_annotation(ColumnId0, index, ColumnIndex1)
)
)
).
perform_row_delete(RowId) :-
get_parent(RowId, TableId),
get_annotation(RowId, index, RowIndex),
\+ (
item([parent:TableId, kind: row, item: Row0, id: RowId0]),
get_annotation(RowId0, index, RowIndex0),
RowIndex0 > RowIndex,
(
deleting(TableId)
->
true
;
get_annotation(RowId, index, RowIndex),
\+ (
RowIndex1 is RowIndex0 - 1,
replace_item(RowId0, row, RowIndex1, Row0),
set_annotation(RowId0, index, RowIndex1)
item([parent:TableId, kind: row, item: Row0, id: RowId0]),
get_annotation(RowId0, index, RowIndex0),
RowIndex0 > RowIndex,
\+ (
RowIndex1 is RowIndex0 - 1,
replace_item(RowId0, row, RowIndex1, Row0),
set_annotation(RowId0, index, RowIndex1)
)
)
).
......
......@@ -172,6 +172,10 @@ check_type(Grammar, Item, NewItem) :-
Grammar = inputs
->
patch_inputs(Item, Item0)
;
Grammar = arithmetic_expression
->
patch_arithmetic_expression(Item, Item0)
;
Item0 = Item
),
......
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