saleks28

oii8

Jan 28th, 2020
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 4.22 KB | None | 0 0
  1. :- dynamic time/2.
  2. :- dynamic attacks/2.
  3. :- dynamic attack_prob/2.
  4.  
  5. elem(zero,0).
  6. elem(low,20).
  7. elem(below_medium,40).
  8. elem(above_medium,60).
  9. elem(high,80).
  10. elem(definite,100).
  11.  
  12. timeFuzzification(DurationTime):-
  13.     DurationTime =< 10, Rang is (10 - DurationTime) / 10 ,assert(time(tiny,Rang)),fail;
  14.     DurationTime =< 10, Rang is DurationTime / 10 ,assert(time(small,Rang)),fail;
  15.     DurationTime > 10, DurationTime =< 40, Rang is (40 - DurationTime) / (40 - 10) ,assert(time(small,Rang)),fail;
  16.     DurationTime > 10, DurationTime =< 40, Rang is (DurationTime - 10) / (40 - 10) ,assert(time(medium,Rang)),fail;
  17.     DurationTime > 40, DurationTime =< 150, Rang is (40- - DurationTime) / (150 - 40) ,assert(time(medium,Rang)),fail;
  18.     DurationTime > 40, DurationTime =< 150, Rang is (DurationTime - 40) / (150 - 40) ,assert(time(large,Rang)),fail;
  19.     DurationTime > 150, Rang is 1 , assert(time(large,Rang)),fail;
  20.     true.
  21.  
  22. packetsFuzzification(PacketsNumber):-
  23.     PacketsNumber =< 10, Rang is (10 - PacketsNumber) / 10 ,assert(attacks(few,Rang)),fail;
  24.     PacketsNumber =< 10, Rang is PacketsNumber / 10 ,assert(attacks(medium,Rang)),fail;
  25.     PacketsNumber > 10, PacketsNumber =< 300, Rang is (300 - PacketsNumber) / (300 - 10) ,assert(attacks(medium,Rang)),fail;
  26.     PacketsNumber > 10, PacketsNumber =< 300, Rang is (PacketsNumber - 10) / (300 - 10) ,assert(attacks(many,Rang)),fail;
  27.     PacketsNumber > 300, PacketsNumber =< 1000, Rang is (1000 - PacketsNumber) / (1000 - 300) ,assert(attacks(many,Rang)),fail;
  28.     PacketsNumber > 300, PacketsNumber =< 1000, Rang is (PacketsNumber - 300) / (1000 - 300) ,assert(attacks(enormous,Rang)),fail;
  29.     PacketsNumber > 10000, Rang is 1 , assert(attacks(enormous,Rang)),fail;
  30.     true.
  31.        
  32. control_block_impl(DurationTime,Rt,PacketsNumber,Ra):-
  33.     DurationTime == tiny,(
  34.         PacketsNumber == few,     Rang is min(Rt,Ra),assert(attack_prob(zero,Rang));
  35.         PacketsNumber == medium,  Rang is min(Rt,Ra),assert(attack_prob(below_medium,Rang));
  36.         PacketsNumber == many,    Rang is min(Rt,Ra),assert(attack_prob(above_medium,Rang));
  37.         PacketsNumber == enormous, Rang is min(Rt,Ra),assert(attack_prob(definite,Rang))
  38.     );
  39.     DurationTime == small,(
  40.         PacketsNumber == few,     Rang is min(Rt,Ra),assert(attack_prob(zero,Rang));
  41.         PacketsNumber == medium,  Rang is min(Rt,Ra),assert(attack_prob(low,Rang));
  42.         PacketsNumber == many,    Rang is min(Rt,Ra),assert(attack_prob(above_medium,Rang));
  43.         PacketsNumber == enormous, Rang is min(Rt,Ra),assert(attack_prob(definite,Rang))
  44.     );
  45.     DurationTime == medium,(
  46.         PacketsNumber == few,     Rang is min(Rt,Ra),assert(attack_prob(zero,Rang));
  47.         PacketsNumber == medium,  Rang is min(Rt,Ra),assert(attack_prob(low,Rang));
  48.         PacketsNumber == many,    Rang is min(Rt,Ra),assert(attack_prob(below_medium,Rang));
  49.         PacketsNumber == enormous, Rang is min(Rt,Ra),assert(attack_prob(above_medium,Rang))
  50.     );
  51.     DurationTime == large,(
  52.         PacketsNumber == few,     Rang is min(Rt,Ra),assert(attack_prob(zero,Rang));
  53.         PacketsNumber == medium,  Rang is min(Rt,Ra),assert(attack_prob(zero,Rang));
  54.         PacketsNumber == many,    Rang is min(Rt,Ra),assert(attack_prob(low,Rang));
  55.         PacketsNumber == enormous, Rang is min(Rt,Ra),assert(attack_prob(below_medium,Rang))
  56.     ).
  57.    
  58. control_block():-
  59.     time(T,Rt), attacks(A,Ra), control_block_impl(T,Rt,A,Ra), fail;
  60.     true.    
  61.    
  62.  
  63. sum_res(Nominator, Denominator, Nres, Dres) :-
  64.   attack_prob(Fuzzy_set,Rang),
  65.   elem(Fuzzy_set,A),
  66.   Area is 10 * (2 * Rang - Rang * Rang),
  67.   NextNominator is Nominator + A * Area,
  68.   NextDenominator is Denominator + Area,
  69.   retract(attack_prob(Fuzzy_set,Rang)),
  70.   sum_res(NextNominator, NextDenominator, Nres, Dres).
  71. sum_res(N,D,N,D).
  72.  
  73.    
  74. defuzzification(Result):-
  75.     sum_res(0,0,N,D), Result is N / D.
  76.    
  77. syn_flood():-
  78.     write("Response time = "), read(Time),
  79.     write("SYN =  "), read(SYN),
  80.     write("ACK = "), read(ACK),
  81.     retractall(time(_,_)),retractall(attacks(_,_)),
  82.     timeFuzzification(Time),
  83.     Packets is SYN - ACK,
  84.     packetsFuzzification(Packets),
  85.     control_block(),
  86.     defuzzification(Result),
  87.     format("SYN-flood probability is ~f.\n", Result).
Add Comment
Please, Sign In to add comment