Вы находитесь на странице: 1из 12

Министерство науки и высшего образования Российской Федерации

Федеральное государственное бюджетное образовательное учреждение


высшего образования
«Московский государственный технический университет
имени Н.Э. Баумана
(национальный исследовательский университет)»
(МГТУ им. Н.Э. Баумана)

ФАКУЛЬТЕТ «Информатика и системы управления» (ИУ)

КАФЕДРА «Информационная безопасность» (ИУ8)

Отчёт
по лабораторной работе № 4
по дисциплине «Теория систем и системный анализ»

Тема: «Решение задачи многокритериальной оптимизации»

Вариант 12

Выполнил:
Проверил:

г. Москва,
20// г.
Цель работы
Изучить постановку задачи многокритериальной оптимизации (МКО); овладеть
навыками решения задач МКО с помощью различных методов, осуществить
сравнительный анализ результатов, полученных при помощи разных методов.

Постановка задачи
Выбрать лучшую из альтернатив решения предложенной задачи по варианту из
табл.
точки зрения указанных критериев следующими методами:
1) заменой критериев ограничениями;
2) формированием и сужением множества Паррето;
3) методом взвешивания и объединения критериев;
4) методом анализа иерархий.

Условие варианта
№пп Задача, Критерии Описание предпочтений
альтернативы

2 Выбор 1. Размер Стипендия: Oxford не платит


университета стипендии; стипендии студентам, в ТГУ
для 2. Квалификация стипендия небольшая, в МФТИ
поступления: преподавателей; – больше, в МГУ –
А. Oxford; 3. Стоимость существенно больше.
В. МГУ; жизни в Преподаватели: самые
С. МФТИ; городе; квалифицированные – в Oxford,
D. ТГУ 4. Престижность чуть менее
диплома. квалифицированные – в МГУ,
менее – в МФТИ, самая низкая
квалификация – в ТГУ.
Стоимость жизни: самая низкая
– в Томске, существенно выше
– в Долгопрудном, гораздо
выше – в Москве, самая
высокая – в Лондоне.
Диплом: самый престижный –
Oxford, немного менее – МГУ,
еще чуть менее – МФТИ,
самый непрестижный – ТГУ
Выводы
Были изучены необходимые учебные материалы, посвященные решению задачи
многокритериальной оптимизации, разработана программа, реализующая это
решение. Из полученных результатов видно, они могут отличаться в
зависимости от применяемых методов решения, главным образом, в
зависимости от оценки критериев.
Приложение 1. Исходный код программы

Header.hpp
#pragma once
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstddef>

void matrix2(std::vector <double> first, std::vector <double>


second,
std::vector <double> third, std::vector <double> fouth,
std::vector <double> fifth);

void parettoMethod(std::vector <double> first, std::vector


<double> second,
std::vector <double> third, std::vector <double> fouth);

void displayHead() {
std::cout << " || A - Oxford || B - MSU || C - MIPT || D - TSU || " <<
std::endl;
std::cout << " Best variant
bad variant " <<
std::endl << std::endl;
std::cout << " 1) Grant : Oxford -> TSU -> MIPT
-> MSU " << std::endl;
std::cout << " 2) Qualification : Oxford -> MSU -> MIPT
-> TSU " << std::endl;
std::cout << " 3) Cost : TSU -> MIPT -> MSU
-> Oxford" << std::endl;
std::cout << " 4) Degree : Oxford -> MSU -> MIPT
-> TSU " << std::endl <<
std::endl << std::endl;

void displayMatrix2(std::vector <double> first, std::vector


<double> second,
std::vector <double> third, std::vector <double> fouth, double s) {

std::cout << " 1 2 3 4 " << std::endl;


for (size_t i = 0; i <4; ++i) {
if (i == 0) std::cout << " A ";
if (i == 1) std::cout << " B ";
if (i == 2) std::cout << " C ";
if (i == 3) std::cout << " D ";

std::cout << std::fixed << std::setprecision(4) << std::setw(5) <<


" || " << " - " <<
" || " << second[i] / s <<
" || " << third[i] / s <<
" || " << " - " << " || " << std::endl;
}
std::cout << std::endl;
}

void displayMatrix(std::vector <double> first, std::vector


<double> second,
std::vector <double> third, std::vector <double> fouth, double s) {

std::cout << " 1 2 3 4 " << std::endl;


for (size_t i = 0; i <4; ++i) {
if (i == 0) std::cout << " A ";
if (i == 1) std::cout << " B ";
if (i == 2) std::cout << " C ";
if (i == 3) std::cout << " D ";

std::cout << std::fixed << std::setprecision(4) << std::setw(5) <<


" || " << first[i] / s <<
" || " << second[i] / s <<
" || " << third[i] / s <<
" || " << fouth[i] / s << " || " << std::endl;
}
}

void displayMatrixIer(std::vector <double> first, std::vector


<double> second,
std::vector <double> third, std::vector <double> fouth,
std::vector <double> sum, double sumOfSum) {
std::cout << std::fixed << std::setprecision(4);
for (int i = 0; i<4; ++i) {
double sumH = first[i] + second[i] + third[i] + fouth[i];
sum.push_back(sumH);
sumOfSum += sumH;
}
std::cout << " 1 2 3 4 Sum
Norm Sum " << std::endl;
for (size_t i = 0; i <4; ++i) {
std::cout << std::fixed << std::setprecision(4) << std::setw(7) <<
" || " << std::setw(2) << i + 1 <<
" | " << std::setw(7) << first[i] <<
" | " << std::setw(7) << second[i] <<
" | " << std::setw(7) << third[i] <<
" | " << std::setw(7) << fouth[i] <<
" | " << std::setw(7) << sum[i] <<
" | " << std::setw(7) << sum[i] / sumOfSum <<
" || " << std::endl;

void displayMatrixIerP(std::vector <double> first, std::vector


<double> second,
std::vector <double> third, std::vector <double> fouth,
std::vector <double> sum, double sumOfSum) {
std::cout << std::fixed << std::setprecision(4);
for (int i = 0; i<4; ++i) {
double sumH = first[i] + second[i] + third[i] + fouth[i];
sum.push_back(sumH);
sumOfSum += sumH;
}
std::cout << " A B C D Sum
Norm Sum " << std::endl;
for (size_t i = 0; i <4; ++i) {
std::cout << std::fixed << std::setprecision(4) << std::setw(7);
if (i == 0) std::cout << " A ";
if (i == 1) std::cout << " B ";
if (i == 2) std::cout << " C ";
if (i == 3) std::cout << " D ";
std::cout <<
" | " << std::setw(7) << first[i] <<
" | " << std::setw(7) << second[i] <<
" | " << std::setw(7) << third[i] <<
" | " << std::setw(7) << fouth[i] <<
" | " << std::setw(7) << sum[i] <<
" | " << std::setw(7) << sum[i] / sumOfSum <<
" || " << std::endl;
}

void answer(int i) {
if (i == 1) {
std::cout << std::endl << " Best : Oxford " << std::endl;
}
else if (i == 2) {
std::cout << std::endl << " Best : MSU " << std::endl;
}
else if (i == 3) {
std::cout << std::endl << " Best : MIPT " << std::endl;
}
else if (i == 4) {
std::cout << std::endl << " Best : TSU " << std::endl;
}
}

// 1
void limitedCriterialMethod(std::vector <double> first,
std::vector <double> second,
std::vector <double> third, std::vector <double> fouth) {

std::cout << std::endl << " 1) " << std::endl;


displayHead();
std::vector <double> crit{ 2, 6, 4, 8 };
double sum_crit = 20;
std::vector <double> norm_crit;
for (size_t ni = 0; ni < 4; ++ni) {
norm_crit.push_back(crit[ni] / sum_crit);
}
std::cout << '\n' << '\n' << " Vector of weight" << '\n';
std::cout << " || Grant || Qualification || Cost ||
Degree || " << std::endl;
std::cout <<
" || " << std::setw(15) << crit[0] <<
" || " << std::setw(15) << crit[1] <<
" || " << std::setw(16) << crit[2] <<
" || " << std::setw(15) << crit[3] << " || " << '\n' << '\n' << '\n';
std::cout << " Normix matrix \n";
std::cout << " || Grant || Qualification || Cost ||
Degree || " << std::endl;
std::cout <<
" || " << std::setw(15) << norm_crit[0] <<
" || " << std::setw(15) << norm_crit[1] <<
" || " << std::setw(16) << norm_crit[2] <<
" || " << std::setw(15) << norm_crit[3] << " || " << '\n' << '\n' <<
'\n';
std::cout << " Mark of alternatives " << std::endl << std::endl;
displayMatrix(first, second, third, fouth, 1);
std::cout << std::endl << std::endl;
for (int i = 0; i<4; ++i) {
first[i] *= 0.2;
}

for (int i = 0; i<4; ++i) {


second[i] *= 0.7;
}

for (int i = 0; i<4; ++i) {


third[i] *= 0.5;
}

for (int i = 0; i<4; ++i) {


fouth[i] *= 1.;
}

std::cout << " || Grant = 0.2 || Qualification = 0.7 || Cost = 0.5 ||


Degree = 1 || "
<< std::endl << std::endl << std::endl;

displayMatrix(first, second, third, fouth, 1);

std::cout << std::endl << std::endl << " Norm matrix: " << std::endl <<
std::endl;

double minFi = *std::min_element(std::begin(first), std::end(first));


double maxFi = *std::max_element(std::begin(first), std::end(first));

for (int i = 0; i<4; ++i)


first[i] = (first[i] - minFi) / (maxFi - minFi);

double minS = *std::min_element(std::begin(second), std::end(second));


double maxS = *std::max_element(std::begin(second), std::end(second));

for (int i = 0; i<4; ++i)


second[i] = (second[i] - minS) / (maxS - minS);

double minT = *std::min_element(std::begin(third), std::end(third));


double maxT = *std::max_element(std::begin(third), std::end(third));

for (int i = 0; i<4; ++i)


third[i] = (third[i] - minT) / (maxT - minT);

displayMatrix(first, second, third, fouth, 1);


double maxFo = *std::max_element(std::begin(fouth), std::end(fouth));
for (int i = 0; i<4; ++i) {
if (fouth[i] == maxFo && first[i] >= norm_crit[0] && second[i] >=
norm_crit[1] && third[i] >= norm_crit[2])
answer(i + 1);
}
std::cout << std::endl << std::endl << std::endl;

}
// 2
void parettoMethod(std::vector <double> first, std::vector
<double> second,
std::vector <double> third, std::vector <double> fouth) {

std::cout << std::endl << " 2) " << std::endl;

displayHead();

displayMatrix2(first, second, third, fouth, 1);


std::cout << " Lets check 2 main parametrs: 2 - Qualification and 3 - Cost
" << std::endl;
for (int i = 0; i<4; i++) {
std::cout << "(" << second[i] << ";" << third[i] << ")";
}

auto maxX = 0;
auto maxY = 0;
for (int i = 0; i<4; ++i) {
std::vector <double> line;
line.push_back(second[i]);
line.push_back(third[i]);
double maxXi = *std::max_element(std::begin(line), std::end(line));
double maxYi = *std::max_element(std::begin(line), std::end(line));
if (i == 0 || maxXi > maxX) maxX = maxXi;
if (i == 0 || maxYi > maxY) maxY = maxYi;
}
if (maxX>maxY) maxY = maxX;
else maxX = maxY;
auto minL = -1;
auto l = -1;
auto iter = 0;

for (int i = 0; i<4; i++) {


if (second[i] == maxX || third[i] == maxX) iter = i + 1;
}
answer(iter);

// 3
void weightOfCriteris(std::vector <double> first, std::vector
<double> second,
std::vector <double> third, std::vector <double> fouth) {
std::cout << std::endl << " 3) " << std::endl;
displayHead();
displayMatrix(first, second, third, fouth, 1);

auto sum = 0;
for (int i = 0; i < 4; i++) {
sum += first[i];
}
for (int i = 0; i < 4; i++) {
first[i] /= sum;
}
sum = 0;
for (int i = 0; i < 4; i++) {
sum += second[i];
}
for (int i = 0; i < 4; i++) {
second[i] /= sum;
}
sum = 0;
for (int i = 0; i < 4; i++) {
sum += third[i];
}
for (int i = 0; i < 4; i++) {
third[i] /= sum;
}
sum = 0;
for (int i = 0; i < 4; i++) {
sum += fouth[i];
}
for (int i = 0; i < 4; i++) {
fouth[i] /= sum;
}

//-------------------------------------------------------------------------
---------------------------------------------

std::cout << std::endl << " Normalize matrix " << std::endl;
displayMatrix(first, second, third, fouth, 1);

std::vector<double> firstn{ 0, 0.5, 0, 1 };


std::vector<double> secondn{ 1, 0, 1, 1 };
std::vector<double> thirdn{ 0.5, 0.5, 1, 0 };
std::vector<double> fouthn{ 0, 0, 1, 0.5 };

std::vector<double> ownKrit;
sum = 0;
for (int i = 0; i < 4; i++) {
sum += firstn[i];
}

ownKrit.push_back(sum);
sum = 0;
for (int i = 0; i < 4; i++) {
sum += secondn[i];
}

ownKrit.push_back(sum);
sum = 0;
for (int i = 0; i < 4; i++) {
sum += thirdn[i];
}

ownKrit.push_back(sum);
sum = 0;
for (int i = 0; i < 4; i++) {
sum += fouthn[i];
}

ownKrit.push_back(sum);
sum = 0;
for (int i = 0; i < 4; i++) {
sum += ownKrit[i];
}
for (int i = 0; i < 4; i++) {
ownKrit[i] /= sum;
}
matrix2(first, second, third, fouth, ownKrit);
std::cout << std::endl << std::endl << std::endl;

// 4
void functionSogl(std::vector <std::vector <double>> one) {
std::vector<double> oneSum;
for (int i = 0; i < 4; ++i) {
double psum = 1;
for (int j = 0; j < 4; ++j) {
psum *= one[i][j];
}
oneSum.push_back(psum);
}
for (int i = 0; i < 4; ++i) {
oneSum[i] = pow(oneSum[i], 0.25);
}
double sumOfSum = 0;
for (int i = 0; i < 4; ++i) {
sumOfSum += oneSum[i];
}
for (int i = 0; i<4; ++i) {
oneSum[i] /= sumOfSum;
}

double alpha =
oneSum[0] * (one[0][0] + one[1][0] + one[2][0] + one[3][0]) +
oneSum[1] * (one[0][1] + one[1][1] + one[2][1] + one[3][1]) +
oneSum[2] * (one[0][2] + one[1][2] + one[2][2] + one[3][2]) +
oneSum[3] * (one[0][3] + one[1][3] + one[2][3] + one[3][3]);

std::cout << " Onoshenie soglasovannosty: " << (alpha - 4.) / (3.*0.9) <<
std::endl;
}

std::vector <double> functionSum(std::vector <std::vector <double>> one, int o)


{
std::vector<double> oneSum;
for (int i = 0; i<4; ++i) {
double sum = 0;
for (int j = 0; j<4; ++j) {
sum += one[j][i];
}
oneSum.push_back(sum);
}
double sumOfSum = 0;
for (int i = 0; i<4; ++i) {
sumOfSum += oneSum[i];
}
if (o == 0)
displayMatrixIerP(one[0], one[1], one[2], one[3], oneSum, sumOfSum);
else displayMatrixIer(one[0], one[1], one[2], one[3], oneSum, sumOfSum);

for (int i = 0; i<4; ++i) {


oneSum[i] /= sumOfSum;
}
return oneSum;
}

void matrix2(std::vector <double> first, std::vector <double>


second,
std::vector <double> third, std::vector <double> fouth, std::vector
<double> fifth) {
std::vector <double> result;
std::cout << std::endl << std::endl;
for (size_t i = 0; i <4; ++i) {
double sum =
first[i] * fifth[0] +
second[i] * fifth[1] +
third[i] * fifth[2] +
fouth[i] * fifth[3];
result.push_back(sum);
}
for (size_t i = 0; i <4; ++i) {

std::cout << std::fixed << std::setprecision(4) << std::setw(5) <<


" | " << first[i] <<
" " << second[i] <<
" " << third[i] <<
" " << fouth[i] <<
" | ";
if (i == 1) std::cout << " * ";
else std::cout << " ";
std::cout << std::fixed << std::setprecision(4) << std::setw(5) <<
" | " << fifth[i] << " | ";
if (i == 1) std::cout << " = ";
else std::cout << " ";
std::cout << std::fixed << std::setprecision(4) << std::setw(5) <<
" | " << result[i] << " | " << std::endl;
}
double maxFo = *std::max_element(std::begin(result), std::end(result));
for (int i = 0; i < 4; ++i) {
if (result[i] == maxFo)
answer(i + 1);
}
}

void analizIerarhij() {
std::cout << std::endl << " 4) " << std::endl;
displayHead();
std::vector<std::vector<double>> normalize;

std::vector<std::vector<double>> cost{ { 1., 3., 5., 7. },


{ 1. / 3, 1, 5., 7. },
{ 1. / 5, 1. / 5, 1, 3 },
{ 1. / 7, 1. / 7, 1. / 3, 1 } };
std::cout << std::endl << std::endl << " Grant : " << std::endl <<
std::endl;

std::vector<double> costSum = functionSum(cost, 0);

functionSogl(cost);

std::vector<std::vector<double>> maintenance{ { 1., 1. / 7., 1. / 3., 1. },


{ 7., 1, 5., 3. },
{ 3, 1. / 5, 1, 1. / 3 },
{ 1., 1. / 3, 3., 1 } };
std::cout << std::endl << std::endl << " Qualification: " << std::endl <<
std::endl;
std::vector<double> maintenanceSum = functionSum(maintenance, 0);
functionSogl(maintenance);

std::vector<std::vector<double>> fuelConsumption{ { 1., 3., 5., 7. },


{ 1. / 3, 1, 5., 7. },
{ 1. / 5, 1. / 5, 1, 3 },
{ 1. / 7, 1. / 7, 1. / 3, 1 } };
std::cout << std::endl << std::endl << " Cost: " << std::endl << std::endl;
std::vector<double> fuelSum = functionSum(fuelConsumption, 0);
functionSogl(fuelConsumption);

std::vector<std::vector<double>> comfort{ { 1 , 3. , 1. / 3., 1. /


5. },
{ 1. / 3., 1 , 1. / 7, 1. / 7. },
{ 3. , 7. , 1 , 1. / 3. },
{ 5. , 7. , 3., 1 } };
std::cout << std::endl << std::endl << " Degree: " << std::endl <<
std::endl;
std::vector<double> comfortSum = functionSum(comfort, 0);
functionSogl(comfort);

std::vector<std::vector<double>> priorites{ { 1 , 1. / 3 , 3., 5. },


{ 3., 1 , 5., 7. },
{ 1. / 3 , 1. / 5 , 1 , 3. },
{ 1. / 5 , 1. / 7 , 1. / 3., 1 } };

std::cout << std::endl << std::endl << " Priorites: " << std::endl <<
std::endl;
std::vector<double> prioritestSum = functionSum(priorites, 1);
functionSogl(priorites);

matrix2(costSum, maintenanceSum, fuelSum, comfortSum, prioritestSum);


}

main.cpp

#include <iostream>
#include "Header.hpp"
int main() {

std::vector <double> first{ 1, 7, 4, 2 };


std::vector <double> second{ 7, 6, 4, 2 };
std::vector <double> third{ 1, 3, 5, 7 };
std::vector <double> fouth{ 7, 6, 5, 2 };
limitedCriterialMethod(first, second, third, fouth);
parettoMethod(first, second, third, fouth);
weightOfCriteris(first, second, third, fouth);
analizIerarhij();
system("pause");
return 0;
}

Вам также может понравиться