Home > src > BN_pol_rec > Hsand > DemoHsand.m

DemoHsand

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

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