Home > src > BN_pol_rec > Demo.m

Demo

PURPOSE ^

Folowing graph will be implemented

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 Folowing graph will be implemented

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 
0002 % Folowing graph will be implemented
0003 
0004 clear, clf
0005 
0006 %-------------------------------------------------------------------
0007 %               Read observations
0008 %-------------------------------------------------------------------
0009 [A, map] = imread('AmundTorp.bmp', 'BMP');
0010 attack_beh = 1; j = 1;
0011 %--------------------------------------------------------------------------
0012 %              Make BN Structure
0013 %--------------------------------------------------------------------------
0014 %Inference nodes
0015 Prev_Discovered = 1;
0016 Prev_PolicyCompany = 2; 
0017 Prev_PolicyPlatoon1 = 3; 
0018 Prev_PolicyPlatoon2 = 4;
0019 Prev_PolicyPlatoon3 = 5;
0020 Prev_Formation21 = 6;
0021 ForceBalance = 7;
0022 Distance = 8;
0023 Visibility = 9;
0024 Discovered = 10; 
0025 PolicyCompany = 11;
0026 Formation21 = 12;
0027 PolicyPlatoon1 = 13;
0028 PolicyPlatoon2 = 14;
0029 PolicyPlatoon3 = 15;
0030 %-------------Platoon one----------------------------------------------
0031 DirOfGuns1 = 16;
0032 % T1 = Tank one maneuverability
0033 T1 = 17; 
0034 T2 = 18;
0035 T3 = 19;
0036 % JM = Joint Manuverability
0037 JM1 = 20;
0038 Carrying = 21;
0039 Cover = 22;
0040 P1atoon1Manuverability = 23;
0041 % Formation on level one for platoon one
0042 Formation11 = 24;
0043 Velocity = 25;
0044 PolicyT1 = 26;
0045 PolicyT2 = 27;
0046 PolicyT3 = 28;
0047  ObsFormation11 = 29;
0048  br = 14;
0049 %%-------------Platoon two----------------------------------------------
0050 DirOfGuns2 = 16 + br;
0051 % T4 = Tank fouth maneuverability
0052 T4 = 17+ br; 
0053 T5 = 18+ br;
0054 T6 = 19+ br;
0055 % JM = Joint Manuverability
0056 JM2 = 20+ br;
0057 Carrying2 = 21+ br;
0058 Cover2 = 22+ br;
0059 P1atoon1Manuverability2 = 23+ br;
0060 % Formation on level one for platoon one
0061 Formation12 = 24+ br;
0062 Velocity2 = 25+ br;
0063 PolicyT4 = 26+ br;
0064 PolicyT5 = 27+ br;
0065 PolicyT6 = 28+ br;
0066 ObsFormation12 = 29 + br;
0067 br = 28;
0068 %%-------------Platoon three----------------------------------------------
0069 DirOfGuns3 = 16 + br;
0070 % T1 = Tank one maneuverability
0071 T7 = 17 + br; 
0072 T8 = 18 + br;
0073 T9 = 19 + br;
0074 % JM = Joint Manuverability
0075 JM3 = 20 + br;
0076 Carrying3 = 21 + br;
0077 Cover3 = 22 + br;
0078 P1atoon1Manuverability3 = 23 + br;
0079 % Formation on level one for platoon one
0080 Formation13 = 24 + br;
0081 Velocity3 = 25 + br;
0082 PolicyT7 = 26 + br;
0083 PolicyT8 = 27 + br;
0084 PolicyT9 = 28 + br;
0085  ObsFormation13 = 29 + br;
0086 %--------------------------------------------------------------------------
0087 N = ObsFormation13 ;
0088 unit_grph = zeros(N,N);
0089 unit_grph(Prev_Discovered, Discovered) = 1;
0090 unit_grph(Prev_PolicyCompany, PolicyCompany) = 1;
0091 unit_grph(Prev_PolicyPlatoon1, PolicyPlatoon1) = 1;
0092 unit_grph(Prev_PolicyPlatoon2, PolicyPlatoon2) = 1;
0093 unit_grph(Prev_PolicyPlatoon3, PolicyPlatoon3) = 1;
0094 unit_grph(Prev_Formation21, Formation21) = 1;
0095 unit_grph(ForceBalance, PolicyCompany) = 1;
0096 unit_grph(Visibility,Discovered) = 1;
0097 unit_grph(Distance, Discovered) = 1;
0098 unit_grph(Discovered, PolicyCompany) = 1;
0099 unit_grph(PolicyCompany, Formation21) = 1;
0100 unit_grph(PolicyCompany, PolicyPlatoon1) = 1;
0101 unit_grph(PolicyCompany, PolicyPlatoon2) = 1;
0102 unit_grph(PolicyCompany, PolicyPlatoon3) = 1;
0103 %---- Platoon one -----------
0104 unit_grph(PolicyPlatoon1, PolicyT1) = 1;
0105 unit_grph(PolicyPlatoon1, PolicyT2) = 1;
0106 unit_grph(PolicyPlatoon1, PolicyT3) = 1;
0107 unit_grph(T1, JM1) = 1;
0108 unit_grph(T2, JM1) = 1;
0109 unit_grph(T3, JM1) = 1;
0110 unit_grph(JM1, P1atoon1Manuverability ) = 1;
0111 unit_grph(Carrying, P1atoon1Manuverability) = 1;
0112 unit_grph(PolicyPlatoon1 , Formation11) = 1;
0113 unit_grph(PolicyPlatoon1, DirOfGuns1) = 1;
0114 unit_grph(Formation11, Velocity) = 1;
0115 unit_grph(Cover, Formation11) = 1;
0116 unit_grph(P1atoon1Manuverability, Formation11 ) = 1;
0117 unit_grph(Formation11, ObsFormation11) = 1;
0118 %---- Platoon two -------------
0119 unit_grph(PolicyPlatoon2, PolicyT4) = 1;
0120 unit_grph(PolicyPlatoon2, PolicyT5) = 1;
0121 unit_grph(PolicyPlatoon2, PolicyT6) = 1;
0122 unit_grph(T4, JM2) = 1;
0123 unit_grph(T5, JM2) = 1;
0124 unit_grph(T6, JM2) = 1;
0125 unit_grph(JM2, P1atoon1Manuverability2 ) = 1;
0126 unit_grph(Carrying2, P1atoon1Manuverability2) = 1;
0127 unit_grph(PolicyPlatoon2 , Formation12) = 1;
0128 unit_grph(PolicyPlatoon2, DirOfGuns2) = 1;
0129 unit_grph(Formation12, Velocity2) = 1;
0130 unit_grph(Cover2, Formation12) = 1;
0131 unit_grph(P1atoon1Manuverability2, Formation12 ) = 1;
0132 unit_grph(Formation12, ObsFormation12) = 1;
0133 %---- Platoon three -----------
0134 unit_grph(PolicyPlatoon3, PolicyT7) = 1;
0135 unit_grph(PolicyPlatoon3, PolicyT8) = 1;
0136 unit_grph(PolicyPlatoon3, PolicyT9) = 1;
0137 unit_grph(T7, JM3) = 1;
0138 unit_grph(T8, JM3) = 1;
0139 unit_grph(T9, JM3) = 1;
0140 unit_grph(JM3, P1atoon1Manuverability3 ) = 1;
0141 unit_grph(Carrying3, P1atoon1Manuverability3) = 1;
0142 unit_grph(PolicyPlatoon3 , Formation13) = 1;
0143 unit_grph(PolicyPlatoon3, DirOfGuns3) = 1;
0144 unit_grph(Formation13, Velocity3) = 1;
0145 unit_grph(Cover3, Formation13) = 1;
0146 unit_grph(P1atoon1Manuverability3, Formation13 ) = 1;
0147 unit_grph(Formation13, ObsFormation13) = 1;
0148 %-------------------------------------------
0149 dag = unit_grph;
0150 node_sizes = [2 5 4 4 4 4 3 3 2 2 5 4 4 4 4 3 2 2 2 2 2 2 2 4 3 3 3 3 4 3 2 2 2 2 2 2 2 4 3 3 3 3 4 3 2 2 2 2 2 2 2 4 3 3 3 3 4]; 
0151 
0152 bnet = mk_bnet(dag, node_sizes);
0153 %draw_graph(bnet.dag);
0154 %--------------------------------------------------------------------------
0155 %  Formulate CPD
0156 %----------------------------------------------------------------------------
0157   
0158   % Start values for time dependent variables
0159   bnet.CPD{Prev_Discovered} = tabular_CPD(bnet, Prev_Discovered, [0.5 0.5]);
0160   bnet.CPD{Prev_PolicyCompany} = tabular_CPD(bnet, Prev_PolicyCompany, [0.2 0.2 0.2 0.2 0.2]);
0161   bnet.CPD{Prev_PolicyPlatoon1} = tabular_CPD(bnet, Prev_PolicyPlatoon1, [0.25 0.25 0.25 0.25]);
0162   bnet.CPD{Prev_PolicyPlatoon2} = tabular_CPD(bnet, Prev_PolicyPlatoon2, [0.25 0.25 0.25 0.25]); 
0163   bnet.CPD{Prev_PolicyPlatoon3} = tabular_CPD(bnet, Prev_PolicyPlatoon3, [0.25 0.25 0.25 0.25]);
0164   bnet.CPD{Prev_Formation21} = tabular_CPD(bnet, Prev_Formation21, [0.25 0.25 0.25 0.25]);
0165   
0166   % Input nodes
0167   bnet.CPD{ForceBalance} = tabular_CPD(bnet, ForceBalance, [0.33 0.34 0.33]);
0168   bnet.CPD{Distance} = tabular_CPD(bnet, Distance, [0.33 0.34 0.33]);
0169   bnet.CPD{Visibility} = tabular_CPD(bnet, Visibility , [0.5 0.5]);
0170   
0171   % Inference nodes
0172   bnet.CPD{Discovered} = tabular_CPD(bnet, Discovered, [0.99 0.8 0.9 0.65 0.8 0.4 0.9 0.7 0.8 0.4 0.6 0.15 0.01 0.2 0.1 0.35 0.2 0.6 0.1 0.3 0.2 0.6 0.4 0.8]);
0173   attackFrontal = [0.75 0.37 0.25 0.2 0.5 0.455 0.24 0.24 0.19 0.25 0.2 0.1 0.1 0.1 0.1 0.4 0.1 0.1 0.05 0.1 0.25 0.1 0.05 0.05 0.05 0.1 0.05 0.05 0.05 0.02];
0174   attackFrontFlange = [ 0.21 0.585 0.23 0.295 0.2 0.25 0.44 0.165 0.19 0.35 0.1 0.2 0.1 0.1 0.1 0.1 0.4 0.1 0.05 0.1 0.15 0.25 0.05 0.05 0.05 0.05 0.1 0.05 0.05 0.05];
0175   delayBat = [0.03 0.03 0.5 0.2 0.1 0.15 0.165 0.44 0.25 0.18 0.495 0.495 0.595 0.395 0.3 0.13 0.13 0.3 0.1 0.1 0.17 0.12 0.3 0.1 0.1 0.27 0.27 0.3 0.2 0.08];
0176   defence = [0.005 0.01 0.015 0.3 0.1 0.14 0.15 0.15 0.35 0.12 0.2 0.2 0.2 0.4 0.2 0.07 0.07 0.1 0.6 0.1 0.13 0.13 0.1 0.3 0.1 0.28 0.28 0.2 0.3 0.1];
0177   march = [0.005 0.005 0.005 0.005 0.1 0.005 0.005 0.005 0.02 0.1 0.005 0.005 0.005 0.005 0.3 0.3 0.3 0.4 0.2 0.6 0.3 0.4 0.5 0.5 0.7 0.3 0.3 0.4 0.4 0.75];
0178   bnet.CPD{PolicyCompany} = tabular_CPD(bnet, PolicyCompany, [attackFrontal attackFrontFlange delayBat defence march]);
0179   leadComp = [ 0.2 0.1 0.01 0.01 0.05 0.01 0.03 0.01 0.05 0.1 0.01 0.01 0.1 0.05 0.01 0.01 0.8 0.4 0.7 0.5];
0180   compactComp = [0.1 0.2 0.05 0.01 0.01 0.15 0.01 0.01 0.1 0.3 0.01 0.01 0.1 0.1 0.2 0.05 0.1 0.2 0.01 0.01];
0181   spreadComp = [0.3 0.4 0.24 0.1 0.39 0.6 0.7 0.1 0.4 0.4 0.55 0.43 0.5 0.55 0.29 0.3 0.07 0.3 0.24 0.4];
0182   verySpreadComp = [0.4 0.3 0.7 0.88 0.55 0.24 0.26 0.88 0.45 0.2 0.43 0.55 0.3 0.3 0.5 0.64 0.03 0.1 0.05 0.09];  
0183   bnet.CPD{Formation21} = tabular_CPD(bnet, Formation21, [leadComp compactComp spreadComp verySpreadComp]);
0184   attack_pl = [0.95 0.88 0.93 0.9 0.87 0.74 0.69 0.8 0.5 0.45 0.3 0.35 0.4 0.1 0.05 0.01 0.15 0.01 0.01 0.01];
0185   defend_pl =[0.02 0.1 0.01 0.06 0.07 0.1 0.01 0.1 0.4 0.45 0.3 0.25 0.49 0.7 0.79 0.85 0.05 0.2 0.05 0.01];
0186   reconn_pl = [0.02 0.01 0.05 0.01 0.05 0.15 0.25 0.03 0.05 0.05 0.33 0.3 0.1 0.13 0.15 0.1 0.25 0.29 0.4 0.15];
0187   march_pl = [0.01 0.01 0.01 0.03 0.01 0.01 0.05 0.07 0.05 0.05 0.07 0.1 0.01 0.07 0.01 0.04 0.55 0.5 0.54 0.83];
0188   bnet.CPD{PolicyPlatoon1} = tabular_CPD(bnet,PolicyPlatoon1 , [attack_pl defend_pl reconn_pl march_pl]);
0189   bnet.CPD{PolicyPlatoon2} = tabular_CPD(bnet,PolicyPlatoon2 , [attack_pl defend_pl reconn_pl march_pl]);
0190   bnet.CPD{PolicyPlatoon3} = tabular_CPD(bnet,PolicyPlatoon3 , [attack_pl defend_pl reconn_pl march_pl]);
0191   
0192   %----------------------------------------------Platoon one ------
0193   % Input nodes
0194   bnet.CPD{DirOfGuns1} = tabular_CPD(bnet, DirOfGuns1, [0.25 0.25 0.33 0.1 0.7 0.5 0.34 0.8 0.05 0.25 0.33 0.1]);
0195   bnet.CPD{T1} = tabular_CPD(bnet, T1, [0.5 0.5]);
0196   bnet.CPD{T2} = tabular_CPD(bnet, T2, [0.5 0.5]);
0197   bnet.CPD{T3} = tabular_CPD(bnet, T3, [0.5 0.5]);
0198   
0199   % Inference node
0200   bnet.CPD{JM1} = tabular_CPD(bnet, JM1 , [0.99 0.66 0.66 0.34 0.66 0.34 0.34 0.1 0.01 0.34 0.34 0.66 0.34 0.66 0.66 0.9]);
0201   
0202    % Input nodes
0203   bnet.CPD{Carrying} = tabular_CPD(bnet,Carrying , [0.5 0.5]);
0204   bnet.CPD{Cover} = tabular_CPD(bnet, Cover, [0.5 0.5]);
0205   
0206   
0207   % Inference nodes
0208   bnet.CPD{P1atoon1Manuverability} = tabular_CPD(bnet, P1atoon1Manuverability, [0.99 0.2 0.8 0.08 0.01 0.8 0.2 0.992]);
0209   lead_pl = [0.05 0.05 0.35 0.9 0.01 0.01 0.3 0.7 0.08 0.08 0.3 0.75 0.08 0.02 0.2 0.56];
0210   battleLine_pl = [0.75 0.60 0.2 0.01 0.79 0.53 0.3 0.2 0.5 0.55 0.13 0.01 0.3 0.2 0.38 0.08];
0211   stare_pl = [0.15 0.3 0.25 0.01 0.1 0.41 0.35 0.08 0.25 0.35 0.47 0.04 0.2 0.5 0.4 0.12];
0212   triangle_pl = [0.05 0.05 0.2 0.08 0.1 0.05 0.05 0.02 0.17 0.02 0.1 0.2 0.42 0.28 0.02 0.24];
0213   bnet.CPD{Formation11} = tabular_CPD(bnet, Formation11 , [lead_pl battleLine_pl stare_pl triangle_pl]);
0214   bnet.CPD{Velocity} = tabular_CPD(bnet,Velocity  , [0.8 0.05 0.4 0.5 0.15 0.15 0.4 0.3 0.05 0.8 0.2 0.2]);
0215   bnet.CPD{PolicyT1} = tabular_CPD(bnet,PolicyT1, [0.8 0.2 0.3 0.1 0.15 0.3 0.4 0.8 0.05 0.5 0.3 0.1]);
0216   bnet.CPD{PolicyT2} = tabular_CPD(bnet,PolicyT2, [0.8 0.2 0.3 0.1 0.15 0.3 0.4 0.8 0.05 0.5 0.3 0.1]);
0217   bnet.CPD{PolicyT3} = tabular_CPD(bnet,PolicyT3, [0.8 0.2 0.3 0.1 0.15 0.3 0.4 0.8 0.05 0.5 0.3 0.1]);
0218   
0219   %Observation nodes
0220    bnet.CPD{ObsFormation11} = tabular_CPD(bnet, ObsFormation11, [0.8 0.01 0.1 0.1 0.01 0.8 0.2 0.01 0.09 0.09 0.69 0.2 0.1 0.1 0.01 0.69]);
0221  %----------------------------------------------Platoon two ------
0222    bnet.CPD{DirOfGuns2} = tabular_CPD(bnet, DirOfGuns2, [0.25 0.25 0.33 0.1 0.7 0.5 0.34 0.8 0.05 0.25 0.33 0.1]);
0223   bnet.CPD{T4} = tabular_CPD(bnet, T4, [0.5 0.5]);
0224   bnet.CPD{T5} = tabular_CPD(bnet, T5, [0.5 0.5]);
0225   bnet.CPD{T6} = tabular_CPD(bnet, T6, [0.5 0.5]);
0226   
0227   % Inference node
0228   bnet.CPD{JM2} = tabular_CPD(bnet, JM2 , [0.99 0.66 0.66 0.34 0.66 0.34 0.34 0.1 0.01 0.34 0.34 0.66 0.34 0.66 0.66 0.9]);
0229   
0230    % Input nodes
0231   bnet.CPD{Carrying2} = tabular_CPD(bnet,Carrying2 , [0.5 0.5]);
0232   bnet.CPD{Cover2} = tabular_CPD(bnet, Cover2, [0.5 0.5]);
0233   
0234   
0235   % Inference nodes
0236   bnet.CPD{P1atoon1Manuverability2} = tabular_CPD(bnet, P1atoon1Manuverability2, [0.99 0.2 0.8 0.08 0.01 0.8 0.2 0.992]);
0237   bnet.CPD{Formation12} = tabular_CPD(bnet, Formation12 , [lead_pl battleLine_pl stare_pl triangle_pl]);
0238   bnet.CPD{Velocity2} = tabular_CPD(bnet,Velocity2  , [0.8 0.05 0.4 0.5 0.15 0.15 0.4 0.3 0.05 0.8 0.2 0.2]);
0239   bnet.CPD{PolicyT4} = tabular_CPD(bnet,PolicyT4, [0.8 0.2 0.3 0.1 0.15 0.3 0.4 0.8 0.05 0.5 0.3 0.1]);
0240   bnet.CPD{PolicyT5} = tabular_CPD(bnet,PolicyT5, [0.8 0.2 0.3 0.1 0.15 0.3 0.4 0.8 0.05 0.5 0.3 0.1]);
0241   bnet.CPD{PolicyT6} = tabular_CPD(bnet,PolicyT6, [0.8 0.2 0.3 0.1 0.15 0.3 0.4 0.8 0.05 0.5 0.3 0.1]);
0242   
0243   %Observation nodes
0244    bnet.CPD{ObsFormation12} = tabular_CPD(bnet, ObsFormation12, [0.8 0.01 0.1 0.1 0.01 0.8 0.2 0.01 0.09 0.09 0.69 0.2 0.1 0.1 0.01 0.69]);
0245   %----------------------------------------------Platoon three ------
0246     bnet.CPD{DirOfGuns3} = tabular_CPD(bnet, DirOfGuns3, [0.25 0.25 0.33 0.1 0.7 0.5 0.34 0.8 0.05 0.25 0.33 0.1]);
0247   bnet.CPD{T7} = tabular_CPD(bnet, T7, [0.5 0.5]);
0248   bnet.CPD{T8} = tabular_CPD(bnet, T8, [0.5 0.5]);
0249   bnet.CPD{T9} = tabular_CPD(bnet, T9, [0.5 0.5]);
0250   
0251   % Inference node
0252   bnet.CPD{JM3} = tabular_CPD(bnet, JM3 , [0.99 0.66 0.66 0.34 0.66 0.34 0.34 0.1 0.01 0.34 0.34 0.66 0.34 0.66 0.66 0.9]);
0253   
0254    % Input nodes
0255   bnet.CPD{Carrying3} = tabular_CPD(bnet,Carrying3 , [0.5 0.5]);
0256   bnet.CPD{Cover3} = tabular_CPD(bnet, Cover3, [0.5 0.5]);
0257   
0258   
0259   % Inference nodes
0260   bnet.CPD{P1atoon1Manuverability3} = tabular_CPD(bnet, P1atoon1Manuverability3, [0.99 0.2 0.8 0.08 0.01 0.8 0.2 0.992]);
0261   bnet.CPD{Formation13} = tabular_CPD(bnet, Formation13 , [lead_pl battleLine_pl stare_pl triangle_pl]);
0262   bnet.CPD{Velocity3} = tabular_CPD(bnet,Velocity3  , [0.8 0.05 0.4 0.5 0.15 0.15 0.4 0.3 0.05 0.8 0.2 0.2]);
0263   bnet.CPD{PolicyT7} = tabular_CPD(bnet,PolicyT7, [0.8 0.2 0.3 0.1 0.15 0.3 0.4 0.8 0.05 0.5 0.3 0.1]);
0264   bnet.CPD{PolicyT8} = tabular_CPD(bnet,PolicyT8, [0.8 0.2 0.3 0.1 0.15 0.3 0.4 0.8 0.05 0.5 0.3 0.1]);
0265   bnet.CPD{PolicyT9} = tabular_CPD(bnet,PolicyT9, [0.8 0.2 0.3 0.1 0.15 0.3 0.4 0.8 0.05 0.5 0.3 0.1]);
0266   
0267   %Observation nodes
0268    bnet.CPD{ObsFormation13} = tabular_CPD(bnet, ObsFormation13, [0.8 0.01 0.1 0.1 0.01 0.8 0.2 0.01 0.09 0.09 0.69 0.2 0.1 0.1 0.01 0.69]);
0269 
0270 %-----------------------------------------------------------------------------------------------------------------------------------------
0271 %                   Intial condtions
0272 %--------------------------------------------------------------------------
0273 
0274  engine = jtree_inf_engine(bnet);
0275  soft_ev = cell(1,N);
0276  soft_ev{ForceBalance} = [0.8 0.2 0]; %Intial belief abot force balace. May also change but in this example is the same during whole simulation.
0277 i = 1;
0278 CompPol = []; areViDiscovered = [];  policyPl_1 = []; policyPl_2 = []; policyPl_3 = []; TanPol1 = [];
0279 pos_old = getPos(i, attack_beh);
0280 %--------------------------------------------------------------------
0281 %                     Loop
0282 %------------------------------------------------------------------
0283 Step = 9;
0284 for i = 1:Step
0285     i = i+1;
0286     [pos_new, vi_pos] = getPos(i,attack_beh);
0287     % Get soft values
0288     soft_ev{Distance} = getDistance(i,attack_beh);
0289     %bnet.CPD{Visibility} = [0.8 0.2];
0290     fi_vec = pos_new - pos_old;
0291     soft_ev{PolicyT1} = tankPolicy(vi_pos, pos_old(1,:), fi_vec(1, :));
0292     soft_ev{PolicyT2} = tankPolicy(vi_pos, pos_old(2,:), fi_vec(2, :));
0293     soft_ev{PolicyT3} = tankPolicy(vi_pos, pos_old(3,:), fi_vec(3, :));
0294     soft_ev{PolicyT4} = tankPolicy(vi_pos, pos_old(4,:), fi_vec(4, :));
0295     soft_ev{PolicyT5} = tankPolicy(vi_pos, pos_old(5,:), fi_vec(5, :));
0296     soft_ev{PolicyT6} = tankPolicy(vi_pos, pos_old(6,:), fi_vec(6, :));
0297     soft_ev{PolicyT7} = tankPolicy(vi_pos, pos_old(7,:), fi_vec(7, :));
0298     soft_ev{PolicyT8} = tankPolicy(vi_pos, pos_old(8,:), fi_vec(8, :));
0299     soft_ev{PolicyT9} = tankPolicy(vi_pos, pos_old(9,:), fi_vec(9, :));
0300     soft_ev{Cover} = findCover(A, pos_new(1:3,:));
0301     soft_ev{Cover2} = findCover(A, pos_new(4:6,:));
0302     soft_ev{Cover3} = findCover(A, pos_new(7:9,:));
0303     soft_ev{T1} = passable(A, pos_new(1,:));
0304     soft_ev{T2} = passable(A, pos_new(2,:));
0305     soft_ev{T3} = passable(A, pos_new(3,:));
0306     soft_ev{T4} = passable(A, pos_new(4,:));
0307     soft_ev{T5} = passable(A, pos_new(5,:));
0308     soft_ev{T6} = passable(A, pos_new(6,:));
0309     soft_ev{T7} = passable(A, pos_new(7,:));
0310     soft_ev{T8} = passable(A, pos_new(8,:));
0311     soft_ev{T9} = passable(A, pos_new(9,:));
0312     soft_ev{ObsFormation11} = formationType(pos_old(1,:), pos_old(2,:), pos_old(3,:), fi_vec(1, :), fi_vec(2, :), fi_vec(3, :));
0313     i
0314     formationType(pos_old(1,:), pos_old(2,:), pos_old(3,:), fi_vec(1, :), fi_vec(2, :), fi_vec(3, :))
0315     soft_ev{ObsFormation12} = formationType(pos_old(4,:), pos_old(5,:), pos_old(6,:), fi_vec(4, :), fi_vec(5, :), fi_vec(6, :));
0316     soft_ev{ObsFormation13} = formationType(pos_old(7,:), pos_old(8,:), pos_old(9,:), fi_vec(7, :), fi_vec(8, :), fi_vec(9, :));
0317     soft_ev{Formation21} = findCompFormation(mediumPoint(pos_old(1,:), pos_old(2,:), pos_old(3,:)), mediumPoint(pos_old(4,:), pos_old(5,:), pos_old(6,:)), mediumPoint(pos_old(7,:), pos_old(8,:), pos_old(9,:)), fi_vec(1, :) + fi_vec(2, :) + fi_vec(3, :),  fi_vec(4, :) + fi_vec(5, :) + fi_vec(6, :), fi_vec(7, :) + fi_vec(8, :) + fi_vec(9, :));
0318     
0319     % Inference
0320      [engine, ll2] = enter_evidence(engine, cell(1,N), 'soft', soft_ev);
0321      marg = marginal_nodes(engine,Discovered);
0322      disc = marg.T;
0323      marg = marginal_nodes(engine,PolicyCompany);
0324      comp_pol = marg.T;
0325      marg = marginal_nodes(engine,PolicyPlatoon1);
0326      pl_1__pol = marg.T;
0327      marg = marginal_nodes(engine,PolicyPlatoon2);
0328      pl_2__pol = marg.T;
0329      marg = marginal_nodes(engine,PolicyPlatoon3);
0330      pl_3__pol = marg.T;
0331      marg = marginal_nodes(engine,Formation21);
0332      comp_form21 = marg.T;
0333      % Save values
0334      TanPol1 = [TanPol1 pl_1__pol];
0335      CompPol = [CompPol comp_pol];
0336      policyPl_1 = [policyPl_1 pl_1__pol];
0337      policyPl_2 = [policyPl_2  pl_2__pol];
0338      policyPl_3 = [policyPl_3  pl_3__pol];
0339      areViDiscovered = [areViDiscovered disc];
0340      %Update
0341      soft_ev{Prev_Discovered} = disc';
0342      soft_ev{Prev_PolicyCompany} = comp_pol';
0343      soft_ev{Prev_PolicyPlatoon1} = pl_1__pol';
0344      soft_ev{Prev_PolicyPlatoon2} = pl_2__pol'; 
0345      soft_ev{Prev_PolicyPlatoon3} = pl_3__pol';
0346      soft_ev{Prev_Formation21} = comp_form21';
0347      pos_old = pos_new;
0348 end
0349 
0350 %-----------------------------------------------------------------
0351 %                    Plot results
0352 %----------------------------------------------------------------
0353 % X =[2:Step];
0354 % figure(1)
0355 % plot(X, CompPol(1,1:8),'blue'), hold on
0356 % title('Company policy, proability for Frontal attack')
0357 % plot(X, CompPol(2,1:8),'yellow')
0358 % Comp_att = CompPol(1,1:8) + CompPol(2,1:8);
0359 % plot(X, Comp_att , 'red')
0360 % ylabel ProabilityForAatack
0361 % xlabel StepNo
0362 % figure(2)
0363 % plot(X,TanPol1(1,1:8))
0364 % title('Tank one policy')
0365 % ylabel ApproachingProbability
0366 % xlabel StepNo
0367 % figure(3)
0368 % plot(X, areViDiscovered(1,1:8))
0369 % title('Are vi discovered?')
0370 % ylabel DicoveringProabbility
0371 % xlabel StepNo
0372 % figure(4)
0373 % plot(X, policyPl_1(1,1:8))
0374 % title('Platton one policy')
0375 % ylabel ProabilityForAatack
0376 % xlabel StepNo
0377 %
0378 % figure(5)
0379 % plot(X, policyPl_2(1,1:8))
0380 % title('Platton two policy')
0381 % ylabel ProabilityForAatack
0382 % xlabel StepNo
0383 %
0384 % figure(6)
0385 % plot(X, policyPl_3(1,1:8))
0386 % title('Platton threepolicy')
0387 % ylabel ProabilityForAatack
0388 % xlabel StepNo
0389 
0390 
0391 for t = 1:8
0392     pause
0393 figure(1)
0394 clf
0395 dispProgress(A, t, attack_beh);
0396 figure(2)
0397 X = [1:t];
0398 %title('Company Policy')
0399 Comp_att = CompPol(1,1:t) + CompPol(2,1:t);
0400 plot(X, Comp_att , 'red', 'LineWidth',3), hold on
0401 plot(X,Comp_att ,'ks','LineWidth',2,...
0402                 'MarkerEdgeColor','black',...
0403                 'MarkerFaceColor','green',...
0404                 'MarkerSize',8) 
0405 %xlabel StepNo
0406 
0407 plot(X,CompPol(5,1:t), 'black', 'LineWidth',3)
0408 plot(X,CompPol(5,1:t) ,'ks','LineWidth',2,...
0409                 'MarkerEdgeColor','black',...
0410                 'MarkerFaceColor','yellow',...
0411                 'MarkerSize',8)
0412 
0413 legend('Attack', '', 'March', ''),hold off
0414 %figure(3)
0415 % plot(X, areViDiscovered(1,1:t))
0416 % title('Are vi discovered?')
0417 % ylabel DicoveringProabbility
0418 % xlabel StepNo
0419 X = [];Comp_att = [];
0420 pause
0421 end;
0422 %movie(F)
0423 
0424 
0425 
0426   
0427

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