Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <vector>
- #include <iomanip>
- #include <algorithm>
- using namespace std;
- int counter = 0;
- vector<double> ves_criter = { 2, 0.5, 1.5, 2 };
- vector<string> kinds = { "Suzuki","Mitsub","Honda","Toyota" };
- void Print(vector<vector<double>> & matrix) // Печать таблицы
- {
- ++counter;
- cout << endl;
- for (int i = 0; i < 5; i++)
- {
- if (i == 0) cout << ' ';
- else if (i == 1) cout << setw(25) << "Cost";
- else if (i == 2) cout << setw(20) << "Service";
- else if (i == 3) cout << setw(20) << "Fuel";
- else if (i == 4) cout << setw(20) << "Comfort";
- }
- cout << endl;
- for (int i = 0; i < 4; i++)
- {
- if (i == 0) cout << setw(20) << "Suzuki\t ";
- else if (i == 1) cout << setw(20) << "Mitsub\t ";
- else if (i == 2) cout << setw(20) << "Honda\t ";
- else if (i == 3) cout << setw(20) << "Toyota\t ";
- for (int j = 0; j < 4; j++)
- {
- if (counter == 2) cout << matrix[i][j] << setw(20);
- else cout << matrix[j][i] << setw(20);
- }
- cout << endl;
- }
- }
- void Print_2(vector<vector<double>> & matrix)
- {
- ++counter;
- cout << endl;
- for (int i = 0; i < 5; i++)
- {
- if (i == 0) cout << ' ';
- else if (i == 1) cout << setw(25) << "Cost";// цена
- else if (i == 2) cout << setw(20) << "Service";// обслуживание
- else if (i == 3) cout << setw(20) << "Fuel";// бензин
- else if (i == 4) cout << setw(20) << "Comfort";// комфорт
- }
- cout << endl;
- for (int i = 0; i < 4; i++)
- {
- if (i == 0) cout << setw(15) << "Suzuki\t ";// марки машин
- else if (i == 1) cout << setw(15) << "Mitsub\t ";
- else if (i == 2) cout << setw(15) << "Honda\t ";
- else if (i == 3) cout << setw(15) << "Toyota\t ";
- for (int j = 0; j < 4; j++)
- {
- if (counter == 2) cout << matrix[i][j] << setw(20);
- else cout << matrix[j][i] << setw(20);
- }
- cout << endl;
- }
- }
- void VyvodOptSol(int str) // Вывод оптим. выбора
- {
- cout << endl;
- if (str == 0)
- cout << "optimal: SUZUKI";
- else if (str == 1)
- cout << "optimal: MITSUBISHI";
- else if (str == 2)
- cout << "optimal: HONDA";
- else if (str == 3)
- cout << "optimal: TOYOTA";
- cout << endl << endl << endl;
- }
- void NormalVectorCriteriev()
- {
- cout << setw(50) << "========================== Normal vector criteriev ==========================" << endl << endl;
- double sum = 0;
- for (int i = 0; i < 4; ++i)
- {
- sum += ves_criter[i];
- }
- cout << "Ves Kriteriev: { 2, 0.5, 1.5, 2 }" << endl << endl;
- cout << "Summa Vesov:" << sum << endl << endl;
- cout << "Norm Vesa Criter : ";
- for (int i = 0; i < 4; ++i)
- {
- ves_criter[i] /= sum;
- cout << setw(5) << ves_criter[i] << " ";
- }
- cout << endl << endl;
- }
- void NormalizSaati(double matrix[4][5], vector<double> & vector)// нормирование
- {
- double sum = 0;
- for (int i = 0; i < 4; ++i)
- {
- for (int j = 0; j < 4; ++j)
- {
- matrix[i][4] += matrix[i][j];
- }
- cout << setw(10) << matrix[i][4];
- cout << endl;
- }
- for (int i = 0; i < 4; ++i)
- {
- sum += matrix[i][4];
- }
- cout << endl << " Symma Strok: " << sum << endl;
- for (int i = 0; i < 4; ++i)
- {
- vector.push_back(matrix[i][4] / sum);
- cout << "\t" << endl;
- }
- }
- void Saati()
- {
- cout << "========================== Saati ==========================" << endl;
- double matr_criteriy[4][5] = { { 1, 0.2, 4, 3, 0 },{ 5, 1, 7, 6, 0 },{ 0.25, 0.14, 1, 0.5, 0 },{ 0.333, 0.167, 2, 1, 0 } };
- double cost[4][5] = { { 1, 0.25, 0.333, 0.125, 0 },{ 4, 1, 2, 0.333, 0 },{ 3, 0.5, 1, 0.25, 0 },{ 8, 3, 4, 1, 0 } };
- double service[4][5] = { { 1, 6, 0.333, 2, 0 },{ 0.167, 1, 0.125, 0.2, 0 },{ 3, 8, 1, 4, 0 },{ 0.5, 5, 0.25, 1, 0 } };
- double fuel[4][5] = { { 1, 0.2, 0.333, 0.125, 0 },{ 5, 1, 3, 0.25, 0 },{ 3, 0.333, 1, 0.167, 0 },{ 8, 4, 6, 1, 0 } };
- double comfort[4][5] = { { 1, 0.333, 0.2, 0.14, 0 },{ 3, 1, 0.333, 0.2, 0 },{ 5, 3, 1, 0.333, 0 },{ 7, 5, 3, 1, 0 } };
- vector<double> cost_v, service_v, fuel_v, comfort_v, ves_criter_saati;
- NormalizSaati(cost, cost_v);
- NormalizSaati(service, service_v);
- NormalizSaati(fuel, fuel_v);
- NormalizSaati(comfort, comfort_v);
- NormalizSaati(matr_criteriy, ves_criter_saati);
- vector<vector<double>> normaliz_matrix;
- normaliz_matrix.push_back(cost_v); normaliz_matrix.push_back(service_v); normaliz_matrix.push_back(fuel_v); normaliz_matrix.push_back(comfort_v);
- Print(normaliz_matrix);
- double record = 0;
- int str = -1;
- for (unsigned i = 0; i < 4; ++i)
- {
- double sum = 0;
- for (unsigned j = 0; j < 4; ++j)
- {
- sum += (normaliz_matrix[j][i] * ves_criter_saati[j]);
- }
- cout << endl;
- cout << "Sum: " << sum << endl;
- if (sum > record)
- {
- record = sum;
- str = i;
- }
- }
- VyvodOptSol(str);
- }
- double manhattan(pair<double, double>& a, pair<double, double>& b)
- {
- return abs(a.second - b.second) + abs(a.first - b.first);
- }
- using matrix = vector<vector<double>>;
- void MethodPareto(const matrix& matrix, size_t k1, size_t k2)
- {
- vector<pair<double, double>> points;
- for (auto i = 0; i < 4; ++i)
- {
- points.push_back(std::make_pair(matrix[i][k1], matrix[i][k2]));
- }
- cout << "Tocki: ";
- for (auto& it : points)
- {
- cout << '(' << it.first << ", " << it.second << ")";
- }
- cout << endl;
- auto max_x = max_element(points.begin(), points.end(),
- [](pair<double, double> &a, pair<double, double> &b)
- {
- return a.first < b.first;
- });
- auto max_y = max_element(points.begin(), points.end(),
- [](pair<double, double> &a, pair<double, double> &b)
- {
- return a.second < b.second;
- });
- pair<double, double> utopia_point = make_pair(8, 8);
- cout << "Utopia tocki: (" << utopia_point.first << ", " << utopia_point.second << ") ";
- cout << endl;
- vector<double> solution;
- for (auto i = 0; i < points.size(); ++i)
- solution.push_back(manhattan(points[i], utopia_point));
- cout << "Znachanie komb kriteria: ";
- for (auto i = 0; i < solution.size(); ++i)
- cout << setw(7) << solution[i];
- cout << endl;
- auto min = std::min_element(solution.begin(), solution.end());
- cout << "Best reshenie: " << kinds[distance(solution.begin(), min)] << endl;
- }
- void MainCritery()
- {
- vector<vector<double>> normaliz_matrix = { { 0,0.6,0,1 },
- { 0.286,0,0.833,0.333 },
- { 0.714,1, 0.333,0.833 },
- { 1,0.4,1, 0 } };
- cout << setw(50) << "====================== Method zameni criteria ogranicheniami ==========================" << endl;
- Print_2(normaliz_matrix);
- double rec = 0;
- int str = 0;
- for (unsigned i = 0; i < 4; ++i)
- {
- cout << "Dopystimoe Cost= " << normaliz_matrix[i][0] * 0.2<<endl;
- cout << "Dopystimoe Service= " << normaliz_matrix[i][3] * 0.5<<endl;
- cout << "Dopystimoe Fuel= " << normaliz_matrix[i][1] * 0.3<<endl;
- cout << "==============="<<endl;
- if (normaliz_matrix[i][0] >= 0.2 && normaliz_matrix[i][1] >= 0.5 && normaliz_matrix[i][3] >= 0.3 && normaliz_matrix[i][2] > rec)
- {
- rec = normaliz_matrix[i][0];
- str = i;
- }
- }
- VyvodOptSol(str);
- }
- void LinConvolut()
- {
- vector<vector<double>> normaliz_matrix = { { 2, 6, 2, 8 },
- { 4, 3, 7, 4 },
- { 7, 8, 4, 7 },
- { 9, 5, 8, 2 } };
- for (int i = 0; i < 4; ++i)
- {
- double sum = 0;
- for (int j = 0; j < 4; ++j)
- {
- sum += normaliz_matrix[j][i];
- }
- for (int j = 0; j < 4; ++j)
- {
- normaliz_matrix[j][i] /= sum;
- }
- }
- cout << endl << setw(50) << "================================== Method Lineynoy svertki =========================" << endl << endl;
- Print_2(normaliz_matrix);
- cout << endl;
- //Ввод матрицы
- int str = 0;
- double record = 0;
- for (int i = 0; i < 4; ++i)
- {
- double sum = 0;
- for (int j = 0; j < 4; ++j)
- {
- sum += (normaliz_matrix[i][j] * ves_criter[j]);
- }
- cout << setw(25) << "sum: " << sum << endl;
- if (record < sum)
- {
- record = sum;
- str = i;
- }
- }
- VyvodOptSol(str);
- cout << endl << endl;
- }
- int main()
- {
- cout << "======================================================================================" << endl;
- matrix m = { { 2, 6, 2, 8 },
- { 4, 3, 7, 4 },
- { 7, 8, 4, 7 },
- { 9, 5, 8, 2 } };
- Print(m);
- cout << endl;
- MainCritery();
- NormalVectorCriteriev();
- LinConvolut();
- cout << setw(63) << "========================== Pareto ==========================" << endl << endl;
- MethodPareto(m, 1, 2);
- Saati();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement