Advertisement
Guest User

Untitled

a guest
May 17th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 8.52 KB | None | 0 0
  1. // Исходные данные
  2.  
  3. alts_n = evstr(x_dialog('Кол-во альтернатив', '5'));
  4. alts = ['ПриватБанк', 'АльфаБанк', 'УкрСоцБанк', 'УкрСибБанк', 'МоноБанк'];
  5. alts = x_dialog('Альтернативы:', alts);
  6.  
  7. crits_n = evstr(x_dialog('Кол-во критериев', '6'));
  8. crits = ['Надежность', 'Количество банкоматов', 'Репутация', 'Профессионализм персонала', 'Технологичность', 'Тарифная политика'];
  9. crits = x_dialog('Критерии', crits);
  10.  
  11. L = evstr(x_dialog('Максимальное значение шкалы', '20'));
  12. crits_weights = [17 11 14 20 18 12];
  13. crits_weights = x_matrix('Весовой параметр каждого критерия', crits_weights);
  14.  
  15. crits_matrix = [16 18 13 14 10;
  16.                 12 16 17 11 19;
  17.                 15 10 20 11 13;
  18.                 16 16 13 10 19;
  19.                 19 10 14 16 16;
  20.                 11 17 17 12 16];
  21. crits_matrix = x_matrix('Матрица критериев:', crits_matrix);
  22. alts_conf = zeros(crits_n, (alts_n * alts_n - alts_n))
  23.  
  24. C= 0.5;
  25. d = 0.5;
  26.  
  27. f1 = figure(); // Создание графического объекта
  28. set(f1, 'position', [0, 0, 620, 827]); // Размер окна
  29.  
  30. uicontrol('style', 'text', ..
  31.           'position', [10, 797, 600, 20], ..
  32.           'string', 'Матрица критериев');
  33.  
  34. table = ["" alts' "Веса"; [crits string(crits_matrix(:, 1)) string(crits_matrix(:, 2)) string(crits_matrix(:, 3)) string(crits_matrix(:, 4)) string(crits_matrix(:, 5)) string(crits_weights')]];
  35.  
  36. uicontrol('style', 'table', ..
  37.           'string', table, ..
  38.           'position', [10 660 600 127]);
  39.  
  40. // Сравнение конфигураций
  41.  
  42. alts_conf = zeros(crits_n, (alts_n * alts_n - alts_n));
  43. k = 0;
  44. for j = 1 : alts_n
  45.     for i = 1 : alts_n
  46.         if j <> i then
  47.             k = k + 1;
  48.             for m = 1 : crits_n
  49.                 if crits_matrix(m, j) > crits_matrix(m, i) then
  50.                     alts_conf(m, k) = 1;
  51.                 elseif crits_matrix(m, j) == crits_matrix(m, i) then
  52.                     alts_conf(m, k) = 0;       
  53.                 elseif crits_matrix(m, j) < crits_matrix(m, i) then
  54.                     alts_conf(m, k) = -1;
  55.                 end
  56.             end
  57.         end
  58.     end
  59. end
  60.  
  61. uicontrol('style', 'text', ..
  62.           'position', [10, 630, 600, 20], ..
  63.           'string', 'Сравнение конфигураций (-1 <, 0 =, 1 >)');
  64.  
  65. table = ["" string([1 2 3 4 5 6]); [["AB"; "AC"; "AD"; "AE"; "BA"; "BC"; "BD"; "BE"; "CA"; "CB"; "CD"; "CE"; "DA"; "DB"; "DC"; "DE"; "EA"; "EB"; "EC"; "ED"] string(alts_conf'(:, 1)) string(alts_conf'(:, 2)) string(alts_conf'(:, 3)) string(alts_conf'(:, 4)) string(alts_conf'(:, 5)) string(alts_conf'(:, 6))]];
  66.  
  67. uicontrol('style', 'table', ..
  68.           'string', table, ..
  69.           'position', [10 493 600 127]);
  70.  
  71. // Расчёт матрицы несогласия
  72.  
  73. disagree_matrix = zeros(alts_n, alts_n);
  74. is_equal = 0;
  75. step = 1;
  76. for j = 1 : alts_n
  77.     for i = 1 : alts_n
  78.         if j <> i then
  79.             for m = 1 : crits_n
  80.                 if alts_conf(m, step) == -1 then
  81.                     x = j;
  82.                     y = i;
  83.                     is_equal = 1;
  84.                 end
  85.                 if is_equal == 1 then
  86.                     d = abs(((crits_matrix(m, y) - crits_matrix(m, x)) / L));
  87.                     disagree_index(m, 1) = d;
  88.                     disagree_index(m, 2) = x;
  89.                     disagree_index(m, 3) = y;
  90.                     disagree_matrix(disagree_index(m, 2), disagree_index(m, 3)) = max(disagree_index(:, 1));
  91.                     is_equal = 0;
  92.                 end
  93.             end
  94.             step = step + 1;
  95.         end
  96.         disagree_index = zeros(crits_n, 3);
  97.     end
  98. end
  99. // disp(disagree_matrix, 'Матрица несогласия');
  100.  
  101. uicontrol('style', 'text', ..
  102.           'position', [10, 463, 600, 20], ..
  103.           'string', 'Матрица несогласия');
  104.  
  105. alts_aliases = ["A" "B" "C" "D" "E"];
  106.  
  107. table = [["" alts_aliases]; [alts_aliases' string(disagree_matrix(:, 1)) string(disagree_matrix(:, 2)) string(disagree_matrix(:, 3)) string(disagree_matrix(:, 4)) string(disagree_matrix(:, 5))]];
  108.  
  109. uicontrol('style', 'table', ..
  110.           'string', table, ..
  111.           'position', [10 342 600 111]);
  112.  
  113. // Расчёт матрицы согласия и подмножеств I+, I=, I
  114.  
  115. agree_matrix = zeros(alts_n, alts_n);
  116.  
  117. // Вычисление суммы весов критериев подмножеств I+, I=
  118. sum_plus_equals = zeros(alts_n, alts_n);
  119. is_equal = 1;
  120. step = 1;
  121. for j = 1 : alts_n
  122.     for i = 1 : alts_n
  123.         if j <> i then
  124.             for m = 1 : crits_n
  125.                 agree_index = zeros(crits_n, 3);
  126.                 if (alts_conf(m, step) == 1 || alts_conf(m, step) == 0) then
  127.                     x = j;
  128.                     y = i;
  129.                     is_equal = 0;
  130.                 end
  131.                 if is_equal == 0 then
  132.                     d = crits_weights(m);
  133.                     agree_index_temp(m, 1) = d;
  134.                     agree_index_temp(m, 2) = x;
  135.                     agree_index_temp(m, 3) = y;
  136.                     is_equal = 1;
  137.                     elem_sum_equal_plus = sum(agree_index_temp(:, 1));
  138.                     sum_plus_equals(x, y) = elem_sum_equal_plus;
  139.                     is_equal = 1;
  140.                 end
  141.             end
  142.             step = step + 1;
  143.         end
  144.         agree_index_temp = zeros(crits_n, 3);
  145.     end
  146. end
  147. // disp(sum_plus_equals, 'Cуммы весов критериев подмножеств I+ и I= ');
  148.  
  149. // Вычисление общей суммы весов
  150.  
  151. weight_sum = ones(alts_n, alts_n);
  152. for j = 1 : alts_n
  153.     for i = 1 : alts_n
  154.         if j <> i then
  155.             for m = 1 : crits_n
  156.                 x = j;
  157.                 y = i;
  158.                 d = crits_weights(m);
  159.                 agree_index_temp(m, 1) = d;
  160.                 agree_index_temp(m, 2) = x;
  161.                 agree_index_temp(m, 3) = y;
  162.                 elem_sum = sum(agree_index_temp(:, 1));
  163.                 weight_sum(x,y) = elem_sum;
  164.             end
  165.         end
  166.         agree_index_temp = zeros(crits_n, 3);
  167.     end
  168. end
  169. // disp(weight_sum, 'Общая сумма весов');
  170.  
  171. // Вычисление матрицы согласия
  172. agree_matrix = sum_plus_equals ./ weight_sum;
  173. // disp(agree_matrix, 'Матрица согласия');
  174.  
  175. uicontrol('style', 'text', ..
  176.           'position', [10, 312, 600, 20], ..
  177.           'string', 'Матрица согласия');
  178.  
  179. table = [["" alts_aliases]; [alts_aliases' string(agree_matrix(:, 1)) string(agree_matrix(:, 2)) string(agree_matrix(:, 3)) string(agree_matrix(:, 4)) string(agree_matrix(:, 5))]];
  180.  
  181. uicontrol('style', 'table', ..
  182.           'string', table, ..
  183.           'position', [10 191 600 111]);
  184.  
  185. // Вычисление превосходства альтернатив и выбор лучшей альтернативы
  186.  
  187. // Матрица превосходства
  188. superior_alts = zeros(alts_n, alts_n);
  189. for i = 1 : alts_n
  190.     for j = 1 : alts_n
  191.         if agree_matrix(i, j) >= C & disagree_matrix(i, j) <= d then
  192.             superior_alts(i, j) = 1;
  193.         end
  194.     end
  195. end
  196. // disp(superior_alts, 'Матрица превосходства вариантов');
  197.  
  198. uicontrol('style', 'text', ..
  199.           'position', [10, 161, 600, 20], ..
  200.           'string', 'Матрица превосходства вариантов');
  201.  
  202. table = [["" alts_aliases]; [alts_aliases' string(superior_alts(:, 1)) string(superior_alts(:, 2)) string(superior_alts(:, 3)) string(superior_alts(:, 4)) string(superior_alts(:, 5))]];
  203.  
  204. uicontrol('style', 'table', ..
  205.           'string', table, ..
  206.           'position', [10 40 600 111]);
  207.  
  208. // Выбор лучшей альтернативы
  209.  
  210. best_alt = zeros(1, alts_n);
  211. best_alt = sum(superior_alts, 'c');
  212. max_best_alt = max(best_alt);
  213.  
  214. disp('------------------------------');
  215. disp('Результат:');
  216. for i = 1 : alts_n
  217.     disp(best_alt(i), alts(i));
  218. end
  219. disp('------------------------------');
  220. disp('Лучшая альтернатива:');
  221. for i = 1 : alts_n
  222.     if best_alt(i) == max_best_alt then
  223.         disp(max_best_alt, alts(i));
  224.         answer = alts(i);
  225.         break;
  226.     end
  227. end
  228.  
  229. uicontrol('style', 'text', ..
  230.           'position', [10, 10, 600, 20], ..
  231.           'string', 'Лучшая альтернатива - ' + answer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement