0001 function [ALL_policy_stuct] = simulationLoop_Final_RealData( varargin )
0002
0003
0004
0005
0006 load namesOfNodes;
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 start = 1;
0021 stop = 160;
0022
0023 diary_on = 0;
0024 video_on = 0;
0025 alt_sensordata = 0;
0026 for n=1:nargin
0027
0028 if strcmp(varargin{n}, 'start') == 1
0029 if (nargin > n) && (isa(varargin{n+1}, 'numeric') == 1)
0030 start = varargin{n+1};
0031 else
0032 error('Please supply a start time!');
0033 end
0034 end
0035
0036 if strcmp(varargin{n}, 'stop') == 1
0037 if (nargin > n) && (isa(varargin{n+1}, 'numeric') == 1)
0038 stop = varargin{n+1};
0039 else
0040 error('Please supply a start time!');
0041 end
0042 end
0043
0044
0045 if strcmp(varargin{n}, 'video') == 1
0046 video_on = 1;
0047 if (nargin > n) && isa(varargin{n+1}, 'char') == 1
0048 video_filename = varargin{n+1}
0049 mov = avifile( video_filename , 'quality', 100, 'fps', 2);
0050 else
0051 error('Please supply a video filename');
0052 end
0053 end
0054
0055
0056 if strcmp(varargin{n}, 'diary') == 1
0057 diary_on = 1;
0058 if (nargin > n) && isa(varargin{n+1}, 'char') == 1
0059 diary_filename = varargin{n+1};
0060 diary( diary_filename );
0061 diary on;
0062 else
0063 error('Please supply a diary filename');
0064 end
0065 end
0066
0067
0068 if strcmp(varargin{n}, 'sensordata') == 1
0069 alt_sensordata = 1;
0070 if (nargin > n) && isa(varargin{n+1}, 'char') == 1
0071 sensor_data_filename = varargin{n+1}
0072 else
0073 error('Please supply a sensor datafile filename');
0074 end
0075 end
0076 end
0077
0078
0079
0080
0081 warning off MATLAB:nonIntegerTruncatedInConversionToChar;
0082
0083
0084 global image_struct;
0085 global roads_struct;
0086 global simulationTime;
0087 global struct_own_forces;
0088 global struct_sensors;
0089 global struct_enemy_comps;
0090 global noOfOwn_forces;
0091 global noOfEnemyCompanies;
0092 global noOfSensors;
0093 global south_enemy;
0094 global north_enemy1;
0095 global north_enemy2;
0096
0097
0098 preemption_allowed = 1;
0099 preemption_not_allowed = 0;
0100
0101
0102 great_data_struct = struct('enemy', {}, 'own', {}, 'sensors', {}, 'threat', {}, 'tasks', {}, 'services', {}, 'allocs', {});
0103
0104
0105
0106 load enemy_positions;
0107 simulationTime = 1;
0108 attack_beh = 0;
0109 [struct_own_forces,noOfOwn_forces] = initializeOwn_forces;
0110 [struct_enemy_comps, noOfEnemyCompanies] = initializeEnemy;
0111 [tasks] = initializeTasks;
0112 [allocations] = initializeAllocations;
0113 if alt_sensordata == 0
0114 [struct_sensors, noOfSensors] = initializeSensors;
0115 disp('initializeSensors')
0116 else
0117 [struct_sensors, noOfSensors] = initializeSensors(sensor_data_filename);
0118 end
0119 [services] = initializeServices( struct_sensors );
0120
0121 enemy_ids = [1 2 3];
0122 own_force_ids = [1 2];
0123 [DBN_Mx, soft_ev_Mx, oldData_Mx] = initDBNMx(own_force_ids, enemy_ids);
0124 initializeImageStruct;
0125
0126 i = 1;
0127
0128
0129
0130
0131 for i = start:stop
0132 disp(' ');
0133 disp(['timestep = ' num2str(i)]);
0134
0135 simulationTime = i;
0136 cp_oldData_Mx = oldData_Mx;
0137 curr_policy_stuct = cell(length(own_force_ids), length(enemy_ids));
0138 updateWorld;
0139 updateSituationPicture;
0140 old_DBN_Mx = DBN_Mx;
0141 old_soft_ev_Mx = soft_ev_Mx;
0142 for own_force = 1:length(own_force_ids)
0143 for currEnemy = 1:length(enemy_ids)
0144 [struct_currentData] = getCurrentEsimatedData(own_force, currEnemy);
0145 [enemy_pos] = getGround_TruthPos(currEnemy);
0146 struct_currentData.enemy_pos = enemy_pos;
0147 [plan_rec_struct, soft_ev_elem, oldData_elem]= getPolicy(DBN_Mx{own_force, currEnemy}, soft_ev_Mx{own_force, currEnemy}, oldData_Mx{own_force, currEnemy}, struct_currentData.own_force_pos, struct_currentData.enemy_pos, struct_currentData.enemy_vel, own_force, currEnemy);
0148
0149 soft_ev_Mx{own_force, currEnemy} = soft_ev_elem;
0150 oldData_Mx{own_force, currEnemy} = oldData_elem;
0151 curr_policy_stuct{own_force, currEnemy} = plan_rec_struct;
0152 end;
0153 end;
0154
0155 ALL_policy_stuct{simulationTime} = curr_policy_stuct;
0156 end
0157