Home > src > BN_pol_rec > Hsand > simulationLoop_Final_RealData.m

simulationLoop_Final_RealData

PURPOSE ^

SIMULATIONLOOP_FINAL

SYNOPSIS ^

function [ALL_policy_stuct] = simulationLoop_Final_RealData( varargin )

DESCRIPTION ^

 SIMULATIONLOOP_FINAL
 SIMULATIONLOOP_FINAL( VARARGIN )

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ALL_policy_stuct] = simulationLoop_Final_RealData( varargin )
0002 % SIMULATIONLOOP_FINAL
0003 % SIMULATIONLOOP_FINAL( VARARGIN )
0004 %
0005 
0006 load namesOfNodes;
0007 
0008 % Folowing graph will be implemented
0009 
0010 % changed: 040517 - rj - new calls to allocation_scheme
0011 % changed: 040518 - rj - new return values from allocation_scheme
0012 % changed: 040519 - rj - minor changes to function calls
0013 % changed: 040521 - rj - additional changes
0014 % changed: 040528 - rj - important changes
0015 % changed: 040529 - rj - made simulationLoop_Final a function with arguments
0016 
0017 % check input arguments
0018 
0019 % start and stop timesteps
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   % start and stop arguments
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   % video argument
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   % diary argument
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   % sensor data file
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 %% checking input arguments
0079 
0080 % warnings
0081 warning off MATLAB:nonIntegerTruncatedInConversionToChar;
0082 
0083 %clear, clf
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 % constants
0098 preemption_allowed = 1;
0099 preemption_not_allowed = 0;
0100 
0101 % interesting variables
0102 great_data_struct = struct('enemy', {}, 'own', {}, 'sensors', {}, 'threat', {}, 'tasks', {}, 'services', {}, 'allocs', {});   
0103 % stores almost all interesting data (it will be a struct array with one element for each timestep)
0104 
0105 % Init
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 %updateWorld;
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 %                     Loop
0129 %------------------------------------------------------------------
0130 
0131 for i = start:stop  
0132     disp(' ');
0133     disp(['timestep = ' num2str(i)]);
0134     %i
0135     simulationTime = i;
0136     cp_oldData_Mx = oldData_Mx; % for use with task management
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 %            toc
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     %Save infered results in this simulation step
0155     ALL_policy_stuct{simulationTime} =  curr_policy_stuct;
0156 end
0157

Generated on Wed 16-Mar-2005 09:17:47 by m2html © 2003