Return and fix zero reducing

This commit is contained in:
emil
2024-10-09 22:55:01 +03:00
parent a2c0cedd00
commit 0920abc31b
+68 -26
View File
@@ -18,58 +18,100 @@ void _printInitialInputs(Vector &C, Matrix &A, Vector &b, double eps, bool maxim
std::cout << "Minimize" << std::endl; std::cout << "Minimize" << std::endl;
} }
std::cout << "z = "; std::cout << "z = ";
bool previousIsZero = true;
bool lastNonZero = false;
for (int i = 0; i < C.size(); i++) for (int i = 0; i < C.size(); i++)
{ {
bool isNegative = false; bool isNegative = false;
if (i != 0)
for (int k = i; k < C.size(); k++)
{ {
std::cout << " + "; if (C[k] == 0)
}
if (C[i] != 1)
{
if (C[i] < 0)
{ {
isNegative = true; lastNonZero = true;
std::cout << "("; } else{
lastNonZero = false;
break;
} }
std::cout << C[i] << " * ";
} }
std::cout << "x" << i + 1; if (!previousIsZero && !lastNonZero){
if (isNegative) std::cout << " + ";
{
std::cout << ")";
} }
if (C[i] != 0){
if (C[i] != 1) {
if (C[i] < 0){
isNegative = true;
std::cout << "(";
}
std::cout << C[i] << " * ";
}
std::cout << "x" << i + 1;
if (isNegative){
std::cout << ")";
}
previousIsZero = false;
}else {
previousIsZero = true;
}
} }
std::cout << std::endl std::cout << std::endl
<< "subject to the constrains:" << std::endl; << "subject to the constrains:" << std::endl;
std::cout << std::endl; std::cout << std::endl;
for (int i = 0; i < b.size(); i++) for (int i = 0; i < b.size(); i++)
{ {
bool previousIsZero = true;
bool lastNonZero = false;
for (int j = 0; j < A.getColumns(); j++) for (int j = 0; j < A.getColumns(); j++)
{ {
bool isNegative = false; bool isNegative = false;
if (j != 0) for (int k = j; k < A[i].size(); k++)
{ {
if (A[i][k] == 0)
{
lastNonZero = true;
} else{
lastNonZero = false;
break;
}
}
if (!previousIsZero && !lastNonZero){
std::cout << " + "; std::cout << " + ";
} }
if (A[i][j] != 1)
{
if (A[i][j] < 0)
{
isNegative = true; if (A[i][j] != 0) {
std::cout << "("; if (A[i][j] != 1) {
if (A[i][j] < 0) {
isNegative = true;
std::cout << "(";
}
std::cout << A[i][j] << " * ";
} }
std::cout << A[i][j] << " * "; std::cout << "x" << j + 1;
} if (isNegative) {
std::cout << "x" << j + 1; std::cout << ")";
if (isNegative) }
{ previousIsZero = false;
std::cout << ")";
}else {
previousIsZero = true;
} }
} }
std::cout << " <= " << b[i] << std::endl; std::cout << " <= " << b[i] << std::endl;
} }
} }