make abstract steps of simplex evaluation before elimination process
This commit is contained in:
@@ -1,24 +1,21 @@
|
||||
#include <iostream>
|
||||
#include "tools/matrix.h"
|
||||
#include "tools/math.h"
|
||||
#include "simplex.h"
|
||||
|
||||
int main() {
|
||||
int n, m;
|
||||
std::cin >> n;
|
||||
std::cin >> m;
|
||||
ColumnVector C(6);
|
||||
Matrix A(6, 4);
|
||||
int Carr[C.getColumns()] = {-5, -4, 0, 0, 0, 0};
|
||||
for (int i = 0; i < C.getRows(); ++i) {
|
||||
C[i] = Carr[i];
|
||||
}
|
||||
A = {{6, 4, 1, 0, 0, 0}, {1, 2, 0, 1, 0, 0}, {-1, 1, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 1}};
|
||||
ColumnVector b(A.getRows());
|
||||
b = {24, 6, 1, 2};
|
||||
std::cout << A << std::endl;
|
||||
std::cout << C << std::endl;
|
||||
|
||||
ColumnVector C(n);
|
||||
Matrix A(n, m);
|
||||
ColumnVector b(n);
|
||||
double eps;
|
||||
double eps_default;
|
||||
std::cin >> A;
|
||||
|
||||
std::cout << "Вектор C: " << C << std::endl;
|
||||
|
||||
std::cout << "Матрица A: " << A << std::endl;
|
||||
|
||||
Matrix B(2, 2);
|
||||
std::cout << B << std::endl;
|
||||
Simplex(C, A, b, 0.01, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+25
-1
@@ -13,7 +13,29 @@ struct Result {
|
||||
double objective_fucntion_value;
|
||||
};
|
||||
|
||||
Result Simplex(ColumnVector C, Matrix A, ColumnVector b, double eps = 0.01, bool maximize) {
|
||||
Result Simplex(ColumnVector C, Matrix A, ColumnVector b, double eps = 0.01, bool maximize=true) {
|
||||
|
||||
std::cout << "C: " << C << std::endl;
|
||||
std::cout << "A: " << A << std::endl;
|
||||
std::cout << "b: " << b << std::endl;
|
||||
|
||||
int n = C.getRows();
|
||||
int m = A.getColumns();
|
||||
|
||||
ColumnVector ratio_vector(m);
|
||||
|
||||
int pivot_column_index = 0;
|
||||
|
||||
pivot_column_index = max(C);
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
ratio_vector[i] = b[i] / A[i][pivot_column_index];
|
||||
}
|
||||
|
||||
int pivot_row_index = min(ratio_vector);
|
||||
|
||||
eleminate(A, C, b, pivot_column_index, pivot_row_index);
|
||||
/*
|
||||
Result result;
|
||||
std::vector<int> basicVars(A.getColumns() - A.getRows());
|
||||
basicVars[0] = -1;
|
||||
@@ -43,7 +65,9 @@ Result Simplex(ColumnVector C, Matrix A, ColumnVector b, double eps = 0.01, bool
|
||||
}
|
||||
}
|
||||
result.objective_fucntion_value = b[0];
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef SIMPLEX_H
|
||||
#define SIMPLEX_H
|
||||
|
||||
#include <vector>
|
||||
#include "tools/matrix.h"
|
||||
|
||||
enum solver_state {
|
||||
unbounded,
|
||||
bounded
|
||||
};
|
||||
|
||||
struct Result {
|
||||
solver_state state;
|
||||
ColumnVector *solution;
|
||||
double objective_fucntion_value;
|
||||
};
|
||||
|
||||
Result Simplex(ColumnVector C, Matrix A, ColumnVector b, double eps = 0.01, bool maximize = true);
|
||||
|
||||
#endif // SIMPLEX_H
|
||||
Reference in New Issue
Block a user