Advertisement
Guest User

Untitled

a guest
May 18th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 8.66 KB | None | 0 0
  1. funcprot(0);
  2. clear();
  3. clc();
  4.  
  5. //-------------------------БЛОК ФУНКЦИЙ--------------------------------
  6. //СРАВНЕНИЕ КОНФИГУРАЦИЙ
  7. function [alternative_config] = compare_alternatives(criteria_amount, alternatives_count, criteria_values)
  8.     alternative_config = zeros(criteria_amount, (alternatives_count*alternatives_count-alternatives_count));
  9.     k = 0;
  10.     for j = 1 : alternatives_count
  11.         for i = 1 : alternatives_count
  12.             if j <> i then
  13.                 k = k + 1;
  14.                 for m = 1 : criteria_amount
  15.                     if  criteria_values(m,j) > criteria_values(m,i) then
  16.                         alternative_config(m,k) = 1;
  17.                     elseif criteria_values(m,j) == criteria_values(m,i) then
  18.                         alternative_config(m,k) = 0;
  19.                     elseif criteria_values(m,j) < criteria_values(m,i) then
  20.                         alternative_config(m,k) = -1;
  21.                     end
  22.                 end
  23.             end
  24.         end
  25.     end
  26.     disp(alternative_config, 'Сравнения конфигураций');
  27. endfunction
  28.  
  29. //РАСЧЁТ МАТРИЦЫ НЕСОГЛАСИЯ
  30. function [disagree_matrix] = find_disagree_value(criteria_amount, alternatives_count, criteria_values, alternative_config, weight_maximum)
  31.     disagree_matrix = zeros(alternatives_count, alternatives_count);
  32.     equals_flag = 0;
  33.     step = 1;
  34.     for j = 1 : alternatives_count
  35.         for i = 1 : alternatives_count
  36.             if j <> i then
  37.                 for m = 1 : criteria_amount
  38.                     if alternative_config(m, step) == -1 then
  39.                     x = j;
  40.                     y = i;
  41.                     equals_flag = 1;
  42.                 end
  43.                     if equals_flag == 1  then
  44.                         d = abs( ( ( criteria_values(m, y) - criteria_values(m, x) ) / weight_maximum ) );
  45.                         disagree_index(m, 1) = d;
  46.                         disagree_index(m, 2) = x;
  47.                         disagree_index(m,3) = y;
  48.                         disagree_matrix( disagree_index(m,2), disagree_index(m,3) ) = max( disagree_index(:,1) );
  49.                         equals_flag = 0;
  50.                     end
  51.                 end
  52.                 step = step + 1;
  53.            end
  54.            disagree_index = zeros(criteria_amount, 3);
  55.         end
  56.     end
  57.     disp(disagree_matrix, 'Матрица несогласия');
  58. endfunction
  59.  
  60. //РАСЧЁТ МАТРИЦЫ СОГЛАСИЯ
  61. function [agree_matrix] = find_agree_value(alternatives_count, criteria_amount, alternative_config, weight_parameters)
  62.     agree_matrix = zeros(alternatives_count, alternatives_count);
  63.    
  64.     // ВЫЧИСЛЕНИЕ СУММЫ ВЕСОВ КРИТЕРИЕВ ПОДМНОЖЕСТВА I+
  65.     sum_plus = zeros(alternatives_count, alternatives_count);
  66.     equals_flag = 1;
  67.     step = 1;
  68.    
  69.     for j = 1 : alternatives_count
  70.         for i = 1 : alternatives_count
  71.            if j<>i then
  72.                for m = 1 : criteria_amount
  73.                    agree_index = zeros(criteria_amount, 3);
  74.                    if ( alternative_config(m, step) == 1 ) then
  75.                       x = j;
  76.                       y = i;
  77.                       equals_flag = 0;
  78.                    end
  79.                    if equals_flag == 0 then
  80.                       d = weight_parameters(m);
  81.                       agree_index_temporary(m, 1) = d;
  82.                       agree_index_temporary(m, 2) = x;
  83.                       agree_index_temporary(m, 3) = y;
  84.                       equals_flag = 1;
  85.                       element_plus = sum(agree_index_temporary(:, 1));
  86.                       sum_plus(x, y) = element_plus;
  87.                       equals_flag = 1;
  88.                    end
  89.                end
  90.                step = step + 1;
  91.            end
  92.            agree_index_temporary = zeros(criteria_amount, 3);
  93.         end
  94.     end
  95.     disp(sum_plus, 'Cуммы весов критериев подмножества I+');
  96.    
  97.     // ВЫЧИСЛЕНИЕ СУММЫ ВЕСОВ КРИТЕРИЕВ ПОДМНОЖЕСТВА I-
  98.     sum_minus = ones(alternatives_count, alternatives_count);
  99.     equals_flag = 1;
  100.     step = 1;
  101.    
  102.     for j = 1 : alternatives_count
  103.         for i = 1 : alternatives_count
  104.            if j<>i then
  105.                for m = 1 : criteria_amount
  106.                    agree_index = zeros(criteria_amount, 3);
  107.                    if ( alternative_config(m, step) == -1 ) then
  108.                       x = j;
  109.                       y = i;
  110.                       equals_flag = 0;
  111.                    end
  112.                    if equals_flag == 0 then
  113.                       d = weight_parameters(m);
  114.                       disagree_indexTemp(m, 1) = d;
  115.                       disagree_indexTemp(m, 2) = x;
  116.                       disagree_indexTemp(m, 3) = y;
  117.                       equals_flag = 1;
  118.                       elementsum_minus = sum(disagree_indexTemp(:, 1));
  119.                       sum_minus(x, y) = elementsum_minus;
  120.                       equals_flag = 1;
  121.                    end
  122.                end
  123.                step = step + 1;
  124.            end
  125.            disagree_indexTemp = zeros(criteria_amount, 3);
  126.         end
  127.     end
  128.     disp(sum_minus, 'Cуммы весов критериев подмножеств I- ');
  129.    
  130.     agree_matrix =  sum_plus ./ sum_minus;
  131.     disp(agree_matrix, 'Матрица согласия');
  132. endfunction
  133.  
  134. //ВЫБОР ЛУЧШЕЙ АЛЬТЕРНАТИВЫ
  135. function [best_alternative] = find_optimal_alternative(c, d, alternatives_count, agree_matrix, disagree_matrix, alternatives_names)
  136.     // Матрица превосходства
  137.     best_alternative = zeros( alternatives_count, alternatives_count);
  138.     for i = 1 : alternatives_count
  139.         for j = 1 : alternatives_count
  140.             if agree_matrix(i, j) >= c & disagree_matrix( i,j ) <= d then
  141.                 best_alternative(i, j) = 1;
  142.             end
  143.         end
  144.     end
  145.     disp(best_alternative, 'Матрица превосходства вариантов');
  146.    
  147.     optimal_alternative = zeros(1, alternatives_count);
  148.     optimal_alternative = sum(best_alternative, 'c');
  149.     optimal_alternative_max = max(optimal_alternative);
  150.     disp('------------------------------');
  151.     disp('Результат:');
  152.     for i = 1 : alternatives_count
  153.         disp(optimal_alternative(i), alternatives_names(i));
  154.     end
  155.     disp('------------------------------');
  156.     disp('Лучшая альтернатива:');
  157.     for i = 1 : alternatives_count
  158.         if optimal_alternative(i) == optimal_alternative_max then
  159.             disp(optimal_alternative_max, alternatives_names(i));  
  160.         end
  161.     end
  162. endfunction
  163.  
  164. //БЛОК ВЫПОЛНЕНИЯ ПРОГРАММЫ
  165. alternatives_count = evstr(x_dialog('Введите количество альтернатив:', '5'));
  166. alternatives_names = ['InSky', 'Join UP!', 'Van Der Tour', 'Хороший Отдых', 'Поехали с нами'];
  167. alternatives_names = x_dialog('Перечислите альтернативы:', alternatives_names);
  168. criteria_amount = evstr(x_dialog('Введите количество критериев:', '6'));
  169. criteria_names = ['Стаж работы', 'Ценовая политика', 'Ассортимент туров','Месторасположение турагенства' , 'Прозрачность условий и документооборота', 'Качество обслуживания клиентов']
  170. criteria_names = x_dialog('Укажите критерии:', criteria_names);
  171. weight_maximum = evstr(x_dialog('Укажите максимальное значение шкалы:', '20'));
  172. weight_parameters = [17 20 18 12 16 17];
  173. weight_parameters = x_matrix('Введите весовые параметры критериев:', weight_parameters);
  174. criteria_values = [15 18 20 17 13;
  175.                   16 15 11 18 13;
  176.                   16 19 15 10 9;
  177.                   19 16 16 15 14;
  178.                   14 15 17 13 20;
  179.                   17 20 12 16 20];
  180. criteria_values = x_matrix('Матрица критериев:', criteria_values);
  181. alternative_config = zeros(criteria_amount, (alternatives_count*alternatives_count-alternatives_count))
  182. c = 0.5;
  183. d = 0.5;
  184.    
  185. alternative_config = compare_alternatives(criteria_amount, alternatives_count, criteria_values);
  186. disagree_matrix = find_disagree_value(criteria_amount, alternatives_count, criteria_values, alternative_config, weight_maximum);
  187. agree_matrix = find_agree_value(alternatives_count, criteria_amount, alternative_config, weight_parameters);
  188. find_optimal_alternative(c, d, alternatives_count, agree_matrix, disagree_matrix, alternatives_names);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement