% experiment 3 
% Martin Radvansky 
% Diplomova prace 2022

% do FIS zmeni intervaly funkci prislusnosti podle vstupu 0-1
% nastaveni 5-ti funkci prislusnosti

function [sugeno_fis] = ComputeIntMF(fis, input_data, default_data)
  sugeno_fis = fis;
  v_b11 = input_data(1); 
  v_b12 = input_data(2); 
  v_b13 = input_data(3);
  v_b21 = input_data(4);
  v_b22 = input_data(5);
  v_b23 = input_data(6);
  v_b31 = input_data(7);
  v_b32 = input_data(8);
  v_b33 = input_data(9);
  v_b41 = input_data(10);
  v_b42 = input_data(11);
  v_b43 = input_data(12);
  v_b51 = input_data(13);
  v_b52 = input_data(14);
  v_b53 = input_data(15);
  
  def_a11 = default_data(1);
  def_a12 = default_data(2);
  def_a13 = default_data(3);
  def_s1 = default_data(4);  

  def_a21 = default_data(5);
  def_a22 = default_data(6);
  def_a23 = default_data(7);
  def_s2 = default_data(8);  

  def_a31 = default_data(9);
  def_a32 = default_data(10);
  def_a33 = default_data(11);
  def_s3 = default_data(12);  

  def_a41 = default_data(13);
  def_a42 = default_data(14);
  def_a43 = default_data(15);
  def_s4 = default_data(16);  
  
  def_a51 = default_data(17);
  def_a52 = default_data(18);
  def_a53 = default_data(19);
  def_s5 = default_data(20);  
    
  %koeficienty sirky
  kb1 = 2;
  kb2 = 2;
  kb3 = 1;
  kb4 = 1;
  kb5 = 2;
  
  %prvni pravdivostni funkce
  sirka_b1 = def_a13-def_a11;
  zmena_b11  = (kb1*sirka_b1) * v_b11; %zmensime max o 2x sirka
  b11 = def_a11 - zmena_b11;

  zmena_b13  = (kb1*sirka_b1) * v_b13; %zvetsime o max 2x sirka
  b13 = def_a13 + zmena_b13; 
  b12 = min(b11+((b13-b11)*v_b12),b13); %maximalne do b13
  
  %druha pravdivostni funkce
  sirka_b2 = def_a23-def_a21;
  zmena_b21  = (kb2*sirka_b2) * v_b21; %zmensime max o 2x sirka
  b21 = def_a21 - zmena_b21;

  zmena_b23  = (kb2*sirka_b2) * v_b23; %zvetsime o max 2x sirka
  b23 = def_a23 + zmena_b23; 
  b22 = min(b21+((b23-b21)*v_b22),b23);
  
  %treti pravdivostni funkce
  sirka_b3 = def_a33-def_a31;
  zmena_b31  = (kb3*sirka_b3) * v_b31; %zmensime max o 2x sirka
  b31 = def_a31 - zmena_b31;

  zmena_b33  = (kb3*sirka_b3) * v_b33; %zvetsime o max 2x sirka
  b33 = def_a33 + zmena_b33; 
  b32 = min(b31+((b33-b31)*v_b32),b33);
    
  %ctvrta pravdivostni funkce
  sirka_b4 = def_a43-def_a41;
  zmena_b41  = (kb4*sirka_b4) * v_b41; %zmensime max o 2x sirka
  b41 = def_a41 - zmena_b41;

  zmena_b43  = (kb4*sirka_b4) * v_b43; %zvetsime o max 2x sirka
  b43 = def_a43 + zmena_b43; 
  b42 = min(b41+((b43-b41)*v_b42),b43);
  
  
  %pata pravdivostni funkce
  sirka_b5 = def_a53-def_a51;
  zmena_b51  = (kb5*sirka_b5) * v_b51; %zmensime max o 2x sirka
  b51 = def_a51 - zmena_b51;

  zmena_b53  = (kb5*sirka_b5) * v_b53; %zvetsime o max 2x sirka
  b53 = def_a53 + zmena_b53; 
  b52 = min(b51+((b53-b51)*v_b52),b53);
  
  %----------------------------------------------------------------------
  sugeno_fis.Inputs.MembershipFunctions(1, 1).Parameters  = [b11 b12 b13];
  sugeno_fis.Inputs.MembershipFunctions(1, 2).Parameters  = [b21 b22 b23];
  sugeno_fis.Inputs.MembershipFunctions(1, 3).Parameters  = [b31 b32 b33];
  sugeno_fis.Inputs.MembershipFunctions(1, 4).Parameters  = [b41 b42 b43];
  sugeno_fis.Inputs.MembershipFunctions(1, 5).Parameters  = [b51 b52 b53];
end