diff --git a/main.cpp b/main.cpp index df1ab18..b4eadcd 100644 --- a/main.cpp +++ b/main.cpp @@ -1,24 +1,21 @@ #include #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; } diff --git a/simplex.cpp b/simplex.cpp index c9a4b93..70e7c2f 100644 --- a/simplex.cpp +++ b/simplex.cpp @@ -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 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]; + } + */ } /* diff --git a/simplex.h b/simplex.h new file mode 100644 index 0000000..d5fcd47 --- /dev/null +++ b/simplex.h @@ -0,0 +1,20 @@ +#ifndef SIMPLEX_H +#define SIMPLEX_H + +#include +#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 \ No newline at end of file