function [scene, traj_t, traj_x, traj_u, zcm, best_params] = runVehicleScenarioCEM(scenario_file, ad, vd, stop_duration)
% Executes the Cross Entropy Method implemented by 
% TrajectoryExploreCEM
% Inputs:
%   scenario_file is name of file holding the scenario description read by
%     ScenarioDescription.m
%   ad is desired acceleration
%   vd is desired velocity
%   stop_duration is required stop duration at stop sign.
% 
% Outputs:
%   scene is the scenario object corresponding to scenario_file
%   traj_t, traj_x, traj_u give the trajectory of the solution
%   zcm is the cross entropy object.
%   best_params are the solution parameters
    
    do_animate = true;
    
    if ~exist(scenario_file, 'file')
        error('File Does Not Exist');
    end

    if nargin <= 3
        stop_duration = 0.5;
    end
    
    scene = ScenarioDescription(scenario_file);

    
    [params, variable_params, knot_types, Xstops] = initKnots(scene, ad, vd, stop_duration);
    num_segs = numel(params)/3;
    
    proposition_handler = vehicleScenarioHandler(scene);
    LTL_automata = LTLAutomata('vehiclescenario.aut');
%     zcm = ZOOXStateKnotsStraightCEM(num_segs, scene, LTL_automata, proposition_handler);
    zcm = TrajectoryExploreCEM(num_segs, scene, LTL_automata, proposition_handler, Xstops);
    
    best_params = zcm.runCE(params, knot_types);
    

    best_params

    [traj_t, traj_x, traj_u] = zcm.traj(best_params);
    
    figure;
    ax = gca;
    scene.drawFrame(ax, [0,0], scene.start_pos, scene.start_angle);
    plot(traj_x(:,1),traj_x(:,2))
    
    if do_animate
        animatePath(scenario_file, traj_t, traj_x);
    end

end

