This commit is contained in:
chriseth 2022-02-03 11:08:24 +01:00
parent f25cd708ea
commit 8600760f3d

View File

@ -262,9 +262,9 @@ pair<LPResult, Tableau> simplexPhaseI(Tableau _tableau)
_tableau.data[i].resize(columns + rows); _tableau.data[i].resize(columns + rows);
_tableau.data[i][columns + i] = 1; _tableau.data[i][columns + i] = 1;
} }
_tableau.objective.factors = _tableau.objective = {};
vector<rational>(columns, rational{}) + _tableau.objective.resize(columns);
vector<rational>(rows, rational{-1}); _tableau.objective.resize(columns + rows, rational{-1});
// This sets the objective factors of the slack variables // This sets the objective factors of the slack variables
// to zero (and thus selects a basic feasible solution). // to zero (and thus selects a basic feasible solution).
@ -276,11 +276,13 @@ pair<LPResult, Tableau> simplexPhaseI(Tableau _tableau)
vector<rational> optimum = solutionVector(_tableau); vector<rational> optimum = solutionVector(_tableau);
// If the solution needs a nonzero factor for a slack variable,
// the original system is infeasible.
for (size_t i = columns - 1; i < optimum.size(); ++i) for (size_t i = columns - 1; i < optimum.size(); ++i)
if (optimum[i] != 0) if (optimum[i] != 0)
return make_pair(LPResult::Infeasible, Tableau{}); return make_pair(LPResult::Infeasible, Tableau{});
_tableau.objective = originalObjective; _tableau.objective = move(originalObjective);
for (auto& row: _tableau.data) for (auto& row: _tableau.data)
row.resize(columns); row.resize(columns);