function f = plot_stats(stats, P)

depth = round(P.planner_horizon/P.action_duration);
max_feasible = 5;
max_tree_nodes = (max_feasible^(depth+1) - 1)/(max_feasible - 1);

panels = 4;

subplot(1, panels, 1)
%semilogy(1:length(stats), [stats.tree_size], '-o', ...
%         1:length(stats), [stats.pruned_nodes], '-^', ...
%         1:length(stats), ones(1,length(stats))*max_tree_nodes, '-'); 
plot(1:length(stats), [stats.tree_size], '-o', ...
     1:length(stats), [stats.pruned_nodes], '-^', ...
     1:length(stats), [stats.tree_size] + [stats.pruned_nodes]); 

title(['Tree nodes (out of ' num2str(max_tree_nodes) ' max possible nodes)'])
legend('valid tree nodes', 'valid pruned subtrees', 'total valid branches')
xlabel('execution cycle')

subplot(1, panels, 2)
%semilogy(1:length(stats), [stats.max_ave_total_reward]);
plot(1:length(stats), [stats.violation_count]); 
legend('total violations')
xlabel('execution cycle')
title('Failed Actions')

subplot(1, panels, 3)
%semilogy(1:length(stats), [stats.max_ave_total_reward]);
plot(1:length(stats), [stats.max_ave_total_reward]); 
title('Total Reward')
legend('max ave total reward')
xlabel('execution cycle')

subplot(1, panels, 4)
%semilogy(1:length(stats), [stats.max_ave_total_reward]);
plot(1:length(stats), [stats.cpu_time]); 
title('CPU time')
xlabel('execution cycle')
ylabel('seconds')
