function [trace, violations, stats] = execute_planner(world_state, planner_horizon, number_executed_actions, P)

if ~isfield(world_state, 'car_controls')
  world_state.car_controls = [];
end

trace = [];
violations = [];
stats = [];

while ~terminal_state(world_state, P)

  P.animate_motion = 0;
  % plannning
  [action_sequence, traces, tree, status] = mdp_planner(world_state, 1, planner_horizon, P);  
  status
  stats = [stats, status];
  
  P.cars(1).traces = traces;
  P.tree = tree;
  
  if isempty(action_sequence)
    disp('planning failed')
    break
  end
  action_sequence
  
  if P.visualize_each_horizon
    P.animate_motion = 1;
  end
  
  animate_callback(world_state, P);
  
  actions_trace = [];
  for i=1:min(length(action_sequence), number_executed_actions)
    action_policies{1} = @(world_state,P)fixed_action_policy(world_state, action_sequence(i), P);
    for k=2:length(P.cars)
      distribution = P.cars(k).action_distribution(world_state, P);
      action_policies{k} = @(world_state,P)fixed_action_policy(world_state, ...
                                                        distribution.samples(1).action, P);
    end
    [action_trace, violations, terminal] = rollout(world_state, action_policies, 1, P);

    if ~isempty(action_trace)
      actions_trace = [actions_trace, action_trace];
      world_state = action_trace(end);
    end
      
    if ~isempty(violations)
      disp('execution failed')
      terminal
      violations.type
      violations.world_state
      break
    end
  end

  trace = [trace, actions_trace];
end
