27 Commits
Author SHA1 Message Date
emil 9b67db3629 Merge branch 'main' of https://github.com/emil28092005/SimplexTASK 2024-10-07 18:55:35 +03:00
emil 8b7f86d5b0 Fixed commit 2024-10-07 18:54:58 +03:00
DavidVista 50fda70802 Delete .vscode directory 2024-10-07 20:03:35 +05:00
emil fa123e0fb0 Deleted manual input function 2024-10-07 15:45:11 +03:00
emil c7bc142081 some error checks made by Vladimir 2024-10-07 13:24:54 +03:00
emil 535c63938d added *.vscode to .gitignore 2024-10-07 13:08:55 +03:00
emil 5ee857a067 Merge branch 'main' of https://github.com/emil28092005/SimplexTASK 2024-10-07 13:06:35 +03:00
emil 6e9ce3c894 merge (inapropriately) detached2 to main 2024-10-07 12:53:55 +03:00
emil 2bfea15fde БЛЯТЬ. Я вощем что-то сделал наугад, но у меня ни с gcc, ни с Cmake, ни с Makefile НЕ РАБОТАЕТ НИХУЯ СУКА. Я ТУТ СИЖУ УЖЕ В ДИПРЕССИИ. 5 ЧАСОВ БЛЯТЬ НИХУЯ НЕ МОГУ СДЕЛАТЬ БЛЯЯЯЯЯЯЯТЬ. СУКА Я ХОЧУ ВЫЕБАТЬ МОНИТОР. С ейчас попробую все-таки разобраться с ЕБАНЫМ КОМПИЛОМ, ато я не могу быть уверен ни в чем, пока не смогу это запустить. Попытаюсь сделать что обещал за эту ночь, ЕСЛИ БЛЯТЬ Я СМОГУ ЭТО ЗАПУСТИТЬ ДО УТРА СУКА БЛЯТЬ. 2024-10-03 00:42:28 +03:00
DavidVista 253cf335ce Delete .vscode directory 2024-09-22 23:18:53 +05:00
Ilya Grigorev 98d5fc9da9 Move general matrix to simplex and fix bugs 2024-09-22 23:17:49 +05:00
emil28092005 9cf37ec9e4 it kinda works 2024-09-22 19:33:24 +03:00
Ilya Grigorev 36b4250ad3 default constructor fix 2024-09-22 21:10:59 +05:00
emil28092005 6e5dab96b0 fractured matrix connection 2024-09-22 19:10:18 +03:00
Ilya Grigorev 08eecfd88a fix conflicts 2024-09-22 21:00:27 +05:00
Ilya Grigorev 2aee5013d6 add build system 2024-09-22 20:56:00 +05:00
Spectre ed2163ee9d bug fixes 2024-09-22 22:18:36 +07:00
Spectre113 38982b501a Division by 0 check added 2024-09-22 22:10:53 +07:00
emil28092005 67a6ca1eae Merge pull request #5 from emil28092005/first_half
Merge simplex and elimination.
2024-09-22 18:06:46 +03:00
emil28092005 c6be5c4e20 Merge branch 'main' into first_half 2024-09-22 18:06:23 +03:00
Spectre cd6de49b34 Elimination func created 2024-09-22 21:53:29 +07:00
emil28092005 df12b44d35 enhanced math.cpp and made while loop for iterative evaluation 2024-09-22 17:51:55 +03:00
emil28092005 3cba9318ef make abstract steps of simplex evaluation before elimination process 2024-09-21 20:22:36 +03:00
Spectre c301992d25 elimination added 2024-09-22 00:16:38 +07:00
Spectre c7edcf8232 math.cpp added 2024-09-21 22:41:49 +07:00
emil28092005 c73cdc184b more structure (add new tools) 2024-09-21 17:56:03 +03:00
emil28092005 62334882dc Merge pull request #1 from emil28092005/detached
make x column
2024-09-20 23:18:14 +03:00
6 changed files with 1 additions and 446 deletions
-33
View File
@@ -1,33 +0,0 @@
# Prerequisites
*.d
CMakeLists.txt
.idea
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
Submodule
+1
Submodule SimplexTASK added at c7bc142081
-18
View File
@@ -1,18 +0,0 @@
#include <iostream>
#include "tools/matrix.h"
int main() {
int n, m;
ColumnVector C(n);
Matrix A(n, m);
ColumnVector b(n);
double eps;
double eps_default;
std::cin >> C;
std::cin >> A;
std::cin >> b;
std::cin >> eps;
return 0;
}
-85
View File
@@ -1,85 +0,0 @@
#include <algorithm>
#include <iostream>
#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) {
Result result;
std::vector<int> basicVars(A.getColumns() - A.getRows());
basicVars[0] = -1;
for (int i = 1; i < basicVars.size(); i++) {
basicVars[i] = static_cast<int>(basicVars.size()) + i;
}
int kc = 0;
double temp = A[0][0];
for (int j = 0; j< A.getColumns(); j++) {
if (A[0][j] < temp) {
temp = A[0][j];
kc = j;
}
}
if (A[0][kc] >= 0) {
result.state = unbounded;
result.solution = new ColumnVector(C.getRows());
for (int i = 0; i < C.getRows(); i++) {
result.solution->operator[](i) = 0;
}
for (int i = 1; i < basicVars.size(); i++) {
if (basicVars[i] <= C.getRows()) {
(*result.solution)[basicVars[i]] = b.getRows() - 1;
}
}
result.objective_fucntion_value = b[0];
}
}
/*
Function_name(C, A, b, eps = eps_default)
Input:
- C: A vector of coefficients of the objective function
- A: A matrix of coefficients of the constraint functions
- b: A vector of right-hand side values
- eps: Approximation accuracy (optional, default = eps_default)
Steps:
1. Print the optimization problem:
- max (or min) z = C[0] * x1 + C[1] * x2 + ... + C[n] * xn
- subject to the constraints:
- A[0] * x <= b[0]
- A[1] * x <= b[1]
- ...
- A[m] * x <= b[m]
2. Initialize:
- Form the initial tableau by introducing slack variables to convert inequalities into equalities.
3. Iteratively apply the Simplex method:
- Step 1: Identify the entering variable (most negative coefficient in the objective row).
- Step 2: Identify the leaving variable (smallest positive ratio of RHS to pivot column).
- Step 3: Perform pivot operations to update the tableau.
4. Check for optimality or unboundedness:
- If all coefficients in the objective function row are non-negative, the solution is optimal.
- If no leaving variable exists, the problem is unbounded.
5. Return:
- solver_state: {solved, unbounded}
- x*: Optimal vector of decision variables (if solved)
- z: Maximum (or minimum) value of the objective function (if solved)
End Function
*/
-213
View File
@@ -1,213 +0,0 @@
#include "matrix.h"
ColumnVector::ColumnVector(int n) {
rows = n;
columns = 1;
columnVector.resize(n);
}
ColumnVector::ColumnVector(const ColumnVector& other) {
rows = other.rows;
columns = other.columns;
columnVector = other.columnVector;
}
int ColumnVector::getRows() const {
return rows;
}
int ColumnVector::getColumns() const {
return columns;
}
double& ColumnVector::operator[](int row) {
return columnVector[row];
}
ColumnVector& ColumnVector::operator=(const ColumnVector& other) {
rows = other.rows;
columns = other.columns;
columnVector = other.columnVector;
return *this;
}
ColumnVector ColumnVector::operator+(ColumnVector& other) {
if (rows != other.rows) {
throw std::runtime_error("Error: the dimensional problem occurred");
}
ColumnVector result(rows);
for (int i = 0; i < rows; ++i) {
result[i] = columnVector[i] + other[i];
}
return result;
}
ColumnVector ColumnVector::operator-(ColumnVector& other) {
if (rows != other.rows) {
throw std::runtime_error("Error: the dimensional problem occurred");
}
ColumnVector result(rows);
for (int i = 0; i < rows; ++i) {
result[i] = columnVector[i] - other[i];
}
return result;
}
std::istream& operator>>(std::istream& cin, ColumnVector& vectorObj) {
for (int i = 0; i < vectorObj.rows; ++i) {
cin >> vectorObj[i];
}
return cin;
}
std::ostream& operator<<(std::ostream& cout, ColumnVector& vectorObj) {
for (int i = 0; i < vectorObj.rows; ++i) {
if (i == vectorObj.rows - 1) {
cout << vectorObj[i] << std::endl;
}
else {
cout << vectorObj[i] << ' ';
}
}
return cout;
}
Matrix::Matrix(int n, int m) {
rows = n;
columns = m;
matrix.resize(n);
for (auto& row : matrix) {
row = ColumnVector(m);
}
}
Matrix::Matrix(const Matrix& other) {
rows = other.rows;
columns = other.columns;
matrix = other.matrix;
}
int Matrix::getRows() const {
return rows;
}
int Matrix::getColumns() const {
return columns;
}
ColumnVector& Matrix::operator[](int row) {
return matrix[row];
}
Matrix& Matrix::operator=(const Matrix& other) {
rows = other.rows;
columns = other.columns;
matrix = other.matrix;
return *this;
}
Matrix Matrix::operator+(Matrix& other) const {
if (rows != other.rows || columns != other.columns) {
throw std::runtime_error("Error: the dimensional problem occurred");
}
Matrix result(rows, columns);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
auto x = matrix[i];
auto y = other[i];
result[i][j] = x[j] + y[j];
}
}
return result;
}
Matrix Matrix::operator-(Matrix& other) const {
if (rows != other.rows || columns != other.columns) {
throw std::runtime_error("Error: the dimensional problem occurred");
}
Matrix result(rows, columns);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
auto x = matrix[i];
auto y = other[i];
result[i][j] = x[j] - y[j];
}
}
return result;
}
Matrix Matrix::operator*(Matrix& other) const {
if (columns != other.rows) {
throw std::runtime_error("Error: the dimensional problem occurred");
}
Matrix result(rows, other.columns);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < other.columns; ++j) {
result[i][j] = 0;
for (int k = 0; k < columns; ++k) {
auto x = matrix[i];
auto y = other[k];
result[i][j] += x[k] * y[j];
}
}
}
return result;
}
ColumnVector Matrix::operator*(ColumnVector other) const {
if (columns != other.getRows()) {
throw std::runtime_error("Error: the dimensional problem occurred");
}
ColumnVector result(rows);
for (int i = 0; i < rows; ++i) {
result[i] = 0;
for (int k = 0; k < columns; ++k) {
auto x = matrix[i];
result[i] += x[k] * other[k];
}
}
return result;
}
Matrix Matrix::transpose() const {
Matrix result(columns, rows);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
auto x = matrix[i];
result[j][i] = x[j];
}
}
return result;
}
std::istream& operator>>(std::istream& cin, Matrix& matrixObj) {
for (int i = 0; i < matrixObj.rows; ++i) {
for (int j = 0; j < matrixObj.columns; ++j) {
cin >> matrixObj[i][j];
}
}
return cin;
}
std::ostream& operator<<(std::ostream& cout, Matrix& matrixObj) {
for (int i = 0; i < matrixObj.rows; ++i) {
for (int j = 0; j < matrixObj.columns; ++j) {
if (j == matrixObj.columns - 1) {
cout << matrixObj[i][j] << std::endl;
}
else {
cout << matrixObj[i][j] << ' ';
}
}
}
return cout;
}
-97
View File
@@ -1,97 +0,0 @@
#ifndef TOOLS_MATRIX_H
#define TOOLS_MATRIX_H
// some functions for matrix interaction
#include <iostream>
#include <vector>
/**
* ColumnVector is a class to represent
* a column vector with n rows.
*/
class ColumnVector {
protected:
// Number of rows in vector
int rows;
// Number of columns in vector
int columns;
// Matrix representation as vector of vectors of integers
std::vector<double> columnVector;
public:
ColumnVector(int n);
ColumnVector(const ColumnVector& other);
/* Getter for the number of rows */
int getRows() const;
/* Getter for the number of columns */
int getColumns() const;
double& operator[](int row);
ColumnVector& operator=(const ColumnVector& other);
ColumnVector operator+(ColumnVector& other);
ColumnVector operator-(ColumnVector& other);
/* Input operator reads element of vector */
friend std::istream& operator>>(std::istream& cin, ColumnVector& vectorObj);
/* Output operator prints elements of the vector
* in a row separated with a space (no space at the end of the line)
*/
friend std::ostream& operator<<(std::ostream& cout, ColumnVector& vectorObj);
};
/**
* Class Matrix represents
* a matrix of size n x m
* of type integer.
*/
class Matrix {
protected:
// Number of rows in matrix
int rows;
// Number of columns in matrix
int columns;
// Matrix representation as vector of vectors of integers
std::vector<ColumnVector> matrix;
public:
Matrix(int n, int m);
Matrix(const Matrix& other);
/* Getter for the number of rows */
int getRows() const;
/* Getter for the number of columns */
int getColumns() const;
ColumnVector& operator[](int row);
Matrix& operator=(const Matrix& other);
Matrix operator+(Matrix& other) const;
Matrix operator-(Matrix& other) const;
Matrix operator*(Matrix& other) const;
/* Matrix-Vector multiplication */
ColumnVector operator*(ColumnVector other) const;
/* Produces transposed version of the matrix */
Matrix transpose() const;
/* Input operator reads element of matrix row by row */
friend std::istream& operator>>(std::istream& cin, Matrix& matrixObj);
/* Output operator prints elements of the matrix
* row by row separated with a space (no space at the end of each line)
*/
friend std::ostream& operator<<(std::ostream& cout, Matrix& matrixObj);
};
#endif // TOOLS_MATRIX_H