2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
:- object(performance,
|
2006-12-28 13:03:34 +00:00
|
|
|
implements(monitoring)).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
:- info([
|
2006-12-28 13:03:34 +00:00
|
|
|
version is 1.3,
|
2003-02-05 00:15:28 +00:00
|
|
|
author is 'Paulo Moura',
|
2006-12-28 13:03:34 +00:00
|
|
|
date is 2006/12/14,
|
2001-06-06 20:40:57 +01:00
|
|
|
comment is 'Performance monitor for state space searches.']).
|
|
|
|
|
|
|
|
|
|
|
|
:- uses(event_registry).
|
|
|
|
:- uses(before_event_registry).
|
|
|
|
:- uses(after_event_registry).
|
2005-12-24 18:00:21 +00:00
|
|
|
|
2004-08-16 17:41:11 +01:00
|
|
|
:- uses(list, [length/2]).
|
|
|
|
:- uses(numberlist, [min/2, max/2, sum/2]).
|
|
|
|
:- uses(time, [cpu_time/1]).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
:- private(transitions_/3).
|
|
|
|
:- dynamic(transitions_/3).
|
|
|
|
:- mode(transitions_(?state, ?state, ?integer), zero_or_more).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
:- private(solution_length_/1).
|
|
|
|
:- dynamic(solution_length_/1).
|
|
|
|
:- mode(solution_length_(?integer), zero_or_one).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
:- private(time_/1).
|
|
|
|
:- dynamic(time_/1).
|
|
|
|
:- mode(time_(-number), zero_or_one).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
:- public(time/1).
|
|
|
|
:- mode(time(-number), zero_or_one).
|
|
|
|
|
|
|
|
:- public(transitions/1).
|
|
|
|
:- mode(transitions(-number), zero_or_one).
|
|
|
|
|
|
|
|
:- public(branching/3).
|
|
|
|
:- mode(branching(-integer, -float, -integer), zero_or_one).
|
|
|
|
|
|
|
|
:- public(report/0).
|
|
|
|
:- mode(report, zero_or_one).
|
|
|
|
|
|
|
|
:- public(init/0).
|
|
|
|
:- mode(init, one).
|
|
|
|
|
|
|
|
:- public(stop/0).
|
|
|
|
:- mode(stop, one).
|
|
|
|
|
|
|
|
|
|
|
|
report :-
|
2005-12-24 18:00:21 +00:00
|
|
|
solution_length_(Length),
|
|
|
|
transitions(Number),
|
2001-06-06 20:40:57 +01:00
|
|
|
Ratio is Length / Number,
|
2005-12-24 18:00:21 +00:00
|
|
|
branching(Minimum, Average, Maximum),
|
|
|
|
time(Time),
|
2001-06-06 20:40:57 +01:00
|
|
|
write('solution length: '), write(Length), nl,
|
2005-12-24 18:00:21 +00:00
|
|
|
write('state transitions (including past solutions): '), write(Number), nl,
|
2001-06-06 20:40:57 +01:00
|
|
|
write('ratio solution length / state transitions: '), write(Ratio), nl,
|
|
|
|
write('minimum branching degree: '), write(Minimum), nl,
|
|
|
|
write('average branching degree: '), write(Average), nl,
|
|
|
|
write('maximum branching degree: '), write(Maximum), nl,
|
2005-12-24 18:00:21 +00:00
|
|
|
write('time: '), write(Time), nl.
|
|
|
|
|
|
|
|
report :- % clean up for next solution
|
|
|
|
retractall(time_(_)),
|
|
|
|
retractall(solution_length_(_)),
|
|
|
|
cpu_time(Start),
|
|
|
|
asserta(time_(Start)),
|
|
|
|
fail.
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
transitions(Number) :-
|
2005-12-24 18:00:21 +00:00
|
|
|
findall(N, transitions_(_, _, N), List),
|
2004-08-16 17:41:11 +01:00
|
|
|
sum(List, Number).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
time(Time) :-
|
2005-12-24 18:00:21 +00:00
|
|
|
cpu_time(End),
|
|
|
|
retract(time_(Start)),
|
2001-06-06 20:40:57 +01:00
|
|
|
Time is End - Start.
|
|
|
|
|
|
|
|
|
|
|
|
branching(Minimum, Average, Maximum) :-
|
|
|
|
findall(
|
|
|
|
Length,
|
2005-12-24 18:00:21 +00:00
|
|
|
(transitions_(State1, _, _),
|
|
|
|
findall(State2, transitions_(State1, State2, _), States2),
|
2004-08-16 17:41:11 +01:00
|
|
|
length(States2, Length)),
|
2001-06-06 20:40:57 +01:00
|
|
|
Lengths),
|
2004-08-16 17:41:11 +01:00
|
|
|
min(Lengths, Minimum),
|
|
|
|
max(Lengths, Maximum),
|
|
|
|
sum(Lengths, Sum),
|
|
|
|
length(Lengths, Length),
|
2001-06-06 20:40:57 +01:00
|
|
|
Average is Sum / Length.
|
|
|
|
|
|
|
|
|
|
|
|
init :-
|
|
|
|
self(Self),
|
|
|
|
event_registry::set_monitor(_, solve(_, _, _), _, Self),
|
|
|
|
after_event_registry::set_monitor(_, next_state(_, _), _, Self),
|
|
|
|
event_registry::set_monitor(_, solve(_, _, _, _), _, Self),
|
|
|
|
after_event_registry::set_monitor(_, next_state(_, _, _), _, Self),
|
2005-12-24 18:00:21 +00:00
|
|
|
retractall(transitions_(_, _, _)),
|
|
|
|
retractall(time_(_)),
|
|
|
|
retractall(solution_length_(_)).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
stop :-
|
|
|
|
self(Self),
|
|
|
|
before_event_registry::del_monitors(_, _, _, Self),
|
|
|
|
after_event_registry::del_monitors(_, _, _, Self).
|
|
|
|
|
|
|
|
|
|
|
|
before(_, solve(_, _, _), _) :-
|
|
|
|
!,
|
2005-12-24 18:00:21 +00:00
|
|
|
retractall(transitions_(_, _, _)),
|
|
|
|
cpu_time(Start),
|
|
|
|
retractall(time_(_)),
|
|
|
|
asserta(time_(Start)).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
before(_, solve(_, _, _, _), _) :-
|
|
|
|
!,
|
2005-12-24 18:00:21 +00:00
|
|
|
retractall(transitions_(_, _, _)),
|
|
|
|
cpu_time(Start),
|
|
|
|
retractall(time_(_)),
|
|
|
|
asserta(time_(Start)).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
after(_, next_state(S1, S2), _) :-
|
|
|
|
!,
|
2005-12-24 18:00:21 +00:00
|
|
|
(retract(transitions_(S1, S2, N)) ->
|
2001-06-06 20:40:57 +01:00
|
|
|
N2 is N + 1
|
|
|
|
;
|
|
|
|
N2 is 1),
|
2005-12-24 18:00:21 +00:00
|
|
|
assertz(transitions_(S1, S2, N2)).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
after(_, next_state(S1, S2, _), _) :-
|
|
|
|
!,
|
2005-12-24 18:00:21 +00:00
|
|
|
(retract(transitions_(S1, S2, N)) ->
|
2001-06-06 20:40:57 +01:00
|
|
|
N2 is N + 1
|
|
|
|
;
|
|
|
|
N2 is 1),
|
2005-12-24 18:00:21 +00:00
|
|
|
assertz(transitions_(S1, S2, N2)).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
after(_, solve(_, _, Solution), _) :-
|
|
|
|
!,
|
2004-08-16 17:41:11 +01:00
|
|
|
length(Solution, Length),
|
2005-12-24 18:00:21 +00:00
|
|
|
retractall(solution_length_(_)),
|
|
|
|
asserta(solution_length_(Length)).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
after(_, solve(_, _, Solution, _), _) :-
|
|
|
|
!,
|
2004-08-16 17:41:11 +01:00
|
|
|
length(Solution, Length),
|
2005-12-24 18:00:21 +00:00
|
|
|
retractall(solution_length_(_)),
|
|
|
|
asserta(solution_length_(Length)).
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
:- end_object.
|