|
Amaliy ish Topshirdi: Grupa: Toshkent – 2024 Variant -6
|
Sana | 18.05.2024 | Hajmi | 3,3 Mb. | | #242831 |
Bog'liq Variant-6 Toshkent axborot texnologiyalari universiteti Algoritmlash va Loyihalash
Amaliy ish
Topshirdi:
Grupa:
Toshkent – 2024
Variant -6
2. Berilgan parametrga iqtisodiy masala tuzish
#include
#include
#include
#include
using namespace std;
const double EPSILON = 1e-10;
// Simplex algoritmi
vector simplex(vector>& A, vector& b, vector& c) {
int m = b.size(), n = c.size();
vector> tableau(m + 1, vector(n + m + 1));
// Tableauga kiritish
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
tableau[i][j] = A[i][j];
}
tableau[i][n + i] = 1;
tableau[i][n + m] = b[i];
}
// Maqsad funktsiyasini qo'shish
for (int j = 0; j < n; ++j) {
tableau[m][j] = -c[j];
}
// Simplex algoritmini boshlash
while (true) {
// qatlamalardan chiqish
int pivot_col = min_element(tableau[m].begin(), tableau[m].end() - 1) - tableau[m].begin();
if (tableau[m][pivot_col] >= -EPSILON) {
break; // Optimallashtirilgan
}
// pivot ustunni tanlash
int pivot_row = -1;
double min_ratio = numeric_limits::infinity();
for (int i = 0; i < m; ++i) {
if (tableau[i][pivot_col] > EPSILON) {
double ratio = tableau[i][n + m] / tableau[i][pivot_col];
if (ratio < min_ratio) {
min_ratio = ratio;
pivot_row = i;
}
}
}
if (pivot_row == -1) {
throw logic_error("Infinitiyada resurslar mavjud");
}
// pivot elementni qayta ishlang
for (int j = 0; j <= n + m; ++j) {
if (j != pivot_col) {
tableau[pivot_row][j] /= tableau[pivot_row][pivot_col];
}
}
tableau[pivot_row][pivot_col] = 1;
// qatorlarni yangilash
for (int i = 0; i <= m; ++i) {
if (i != pivot_row) {
for (int j = 0; j <= n + m; ++j) {
if (j != pivot_col) {
tableau[i][j] -= tableau[i][pivot_col] * tableau[pivot_row][j];
}
}
tableau[i][pivot_col] = 0;
}
}
}
// Yechimlarni izlash
vector solution(n);
for (int i = 0; i < m; ++i) {
int one_index = find(tableau[i].begin(), tableau[i].end() - 1, 1) - tableau[i].begin();
if (one_index != n + m) {
solution[one_index] = tableau[i][n + m];
}
}
return solution;
}
int main() {
// Ko'rsatkichlar va shartlar
vector> A = {
{17, 15, 10},
{11, 8, 16},
{9, 18, 11}
};
vector b = {219,141,182};
vector c = {1500, 1700, 1400}; // Maqsad funktsiyasi
// Simplex algoritmini chaqirish
vector solution = simplex(A, b, c);
// Ekranga chiqarish
cout << "Optimal yechimlar:" << endl;
for (int i = 0; i < solution.size(); ++i) {
cout << "x(" << i+1 << "): " << solution[i] << endl;
}
// Umumiy daromadni hisoblash
double optimal_daromad = 0;
for (int i = 0; i < solution.size(); ++i) {
optimal_daromad += solution[i] * c[i];
}
cout << "Optimal daromad: " << optimal_daromad << endl;
return 0;
}
3. Geometrik usul
4.Simpleks usulda ishlash
F=22100 x1=7; x2=6 x3=1
|
| |