Skip to content

Commit e64b554

Browse files
committed
Add nonbasic residual check to EKK
1 parent 034ff66 commit e64b554

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

highs/lp_data/HighsSolution.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void getLpKktFailures(const HighsOptions& options, const HighsLp& lp,
5555
HighsInfo& highs_info) {
5656
HighsPrimalDualErrors primal_dual_errors;
5757
getLpKktFailures(options, lp, solution, basis, highs_info,
58-
primal_dual_errors);
58+
primal_dual_errors, false);
5959
}
6060

6161
void getLpKktFailures(const HighsOptions& options, const HighsLp& lp,
@@ -64,7 +64,7 @@ void getLpKktFailures(const HighsOptions& options, const HighsLp& lp,
6464
HighsPrimalDualErrors& primal_dual_errors,
6565
const bool get_residuals) {
6666
getKktFailures(options, false, lp, lp.col_cost_, solution, highs_info,
67-
get_residuals);
67+
get_residuals, basis.valid);
6868
getPrimalDualBasisErrors(options, lp, solution, basis, primal_dual_errors);
6969
getPrimalDualGlpsolErrors(options, lp, lp.col_cost_, solution,
7070
primal_dual_errors);
@@ -73,7 +73,8 @@ void getLpKktFailures(const HighsOptions& options, const HighsLp& lp,
7373
void getKktFailures(const HighsOptions& options, const bool is_qp,
7474
const HighsLp& lp, const std::vector<double>& gradient,
7575
const HighsSolution& solution, HighsInfo& highs_info,
76-
const bool get_residuals) {
76+
const bool get_residuals,
77+
const bool basic_solution) {
7778
double primal_feasibility_tolerance = options.primal_feasibility_tolerance;
7879
double dual_feasibility_tolerance = options.dual_feasibility_tolerance;
7980
double primal_residual_tolerance = options.primal_residual_tolerance;
@@ -444,7 +445,7 @@ void getKktFailures(const HighsOptions& options, const bool is_qp,
444445
// Determine the sum of complementarity violations
445446
const bool have_values = getComplementarityViolations(
446447
lp, solution, optimality_tolerance, num_complementarity_violation,
447-
max_complementarity_violation);
448+
max_complementarity_violation, basic_solution);
448449
assert(have_values);
449450
}
450451

@@ -955,7 +956,8 @@ bool getComplementarityViolations(const HighsLp& lp,
955956
const HighsSolution& solution,
956957
const double optimality_tolerance,
957958
HighsInt& num_complementarity_violation,
958-
double& max_complementarity_violation) {
959+
double& max_complementarity_violation,
960+
const bool basic_solution) {
959961
num_complementarity_violation = kHighsIllegalComplementarityCount;
960962
max_complementarity_violation = kHighsIllegalComplementarityViolation;
961963
if (!solution.dual_valid) return false;
@@ -983,11 +985,13 @@ bool getComplementarityViolations(const HighsLp& lp,
983985
const double dual_residual = std::fabs(dual);
984986
const double complementarity_violation = primal_residual * dual_residual;
985987
if (complementarity_violation > optimality_tolerance) {
986-
printf("getComplementarityViolations: %s %d has (primal / dual) residual (%g / %g) violation = %g\n",
987-
is_col ? "column" : "row",
988-
is_col ? int(iVar) : int(iRow),
989-
primal_residual, dual_residual,
990-
complementarity_violation);
988+
if (basic_solution) {
989+
printf("getComplementarityViolations: %s %d has (primal / dual) residual (%g / %g) violation = %g\n",
990+
is_col ? "column" : "row",
991+
is_col ? int(iVar) : int(iRow),
992+
primal_residual, dual_residual,
993+
complementarity_violation);
994+
}
991995
num_complementarity_violation++;
992996
}
993997
max_complementarity_violation =

highs/lp_data/HighsSolution.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ void getLpKktFailures(const HighsOptions& options, const HighsLp& lp,
7676
const HighsSolution& solution, const HighsBasis& basis,
7777
HighsInfo& highs_info,
7878
HighsPrimalDualErrors& primal_dual_errors,
79-
const bool get_residuals = false);
79+
const bool get_residuals);
8080

81+
// Inner getKktFailures
8182
void getKktFailures(const HighsOptions& options, const bool is_qp,
8283
const HighsLp& lp, const std::vector<double>& gradient,
8384
const HighsSolution& solution, HighsInfo& highs_info,
84-
const bool get_residuals = false);
85+
const bool get_residuals,// = false,
86+
const bool basic_solution = false);
8587

8688
void getVariableKktFailures(const double primal_feasibility_tolerance,
8789
const double dual_feasibility_tolerance,
@@ -106,7 +108,8 @@ bool getComplementarityViolations(const HighsLp& lp,
106108
const HighsSolution& solution,
107109
const double optimality_tolerance,
108110
HighsInt& num_complementarity_violations,
109-
double& max_complementarity_violation);
111+
double& max_complementarity_violation,
112+
const bool basic_solution = false);
110113

111114
bool computeDualObjectiveValue(const HighsModel& model,
112115
const HighsSolution& solution,

highs/mip/HighsLpRelaxation.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,19 @@ HighsLpRelaxation::Status HighsLpRelaxation::run(bool resolve_on_error) {
11521152
}
11531153
}
11541154
if (use_simplex) {
1155+
const HighsLp& lp = lpsolver.getLp();
1156+
const bool check_lp = lp.num_col_ == 9 && lp.num_row_ == 23 && lp.a_matrix_.numNz() == 200;
1157+
if (check_lp) {
1158+
printf("HighsLpRelaxation::run Checking solution of LP\n");
1159+
lpsolver.setOptionValue("output_flag", true);
1160+
lpsolver.setOptionValue("log_dev_level", 3);
1161+
lpsolver.setOptionValue("highs_analysis_level", 4);
1162+
}
11551163
callstatus = lpsolver.run();
1164+
if (check_lp) {
1165+
lpsolver.setOptionValue("output_flag", false);
1166+
lpsolver.setOptionValue("log_dev_level", 0);
1167+
}
11561168
}
11571169
// Revert the value of lpsolver.options_.solver
11581170
lpsolver.setOptionValue("solver", solver);

0 commit comments

Comments
 (0)