-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRun_Bellman_Recursion.m
More file actions
65 lines (48 loc) · 2.29 KB
/
Run_Bellman_Recursion.m
File metadata and controls
65 lines (48 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PURPOSE: Runs bellman recursion particular scenario under a given configuration.
% INPUT:
% scenarioID = the string id of the scenario to use
% configurationID = the numeric id of the configuration to use
% [optional "hot start" file)
% /staging/{configurationID}/{scenarioID}/checkpoint.mat :
% a file containing any previously completed recursion steps
% OUTPUT:
% [file] (after each recursion step) :
% /staging/{configurationID}/{scenarioID}/Bellman_checkpoint.mat -
% a file containing results for any completed recursion steps
% [file] (after each recursion step) :
% /staging/{configurationID}/{scenarioID}/times.txt -
% a file containing the bellman
% [file] (after all recursion steps)
% /staging/{configurationID}/{scenarioID}/Bellman_complete.mat : a
% file containing results for all recursion steps
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[] = Run_Bellman_Recursion(scenarioID, configurationID)
% declare globals so they are saved with results
global ambient;
global scenario;
global config;
% check staging area for scenarioID, configurationID
staging_area = get_staging_directory(scenarioID, configurationID);
checkpoint_file = strcat([staging_area,'Bellman_checkpoint.mat']);
% if checkpoint file is available, load it, otherwise start fresh
if isfile(checkpoint_file)
load(checkpoint_file);
else
% Initialize variables used in value iteration
[Js, mus, Zs, N] = setup_reachability(scenarioID, configurationID);
end
start_point = max(find(cellfun(@isempty,Js),N+1));
for k = start_point: -1: 1
% record stage start
write_log_start_stage(staging_area, k);
% run stage
[ Zs{k}, Js{k} , mus{k} ] = perform_Bellman_backup_step(Js{k+1});
% save checkpoint
save(strcat([staging_area,'Bellman_checkpoint.mat']));
% record stage complete
write_log_end_stage(staging_area, k);
end
% save checkpoint
save(strcat([staging_area,'Bellman_complete.mat']));
end