| 178 | } |
| 179 | |
| 180 | double OptimizationProblem::complementarity_error(const Vector<double>& primals, const Vector<double>& constraints, |
| 181 | const Multipliers& multipliers, double shift_value, Norm residual_norm) const { |
| 182 | // bound constraints |
| 183 | const Range variables_range = Range(this->number_variables); |
| 184 | const auto& variables_lower_bounds = this->get_variables_lower_bounds(); |
| 185 | const auto& variables_upper_bounds = this->get_variables_upper_bounds(); |
| 186 | const VectorExpression variable_complementarity{variables_range, [&](size_t variable_index) { |
| 187 | if (variable_index >= primals.size() || variable_index >= multipliers.lower_bounds.size() || |
| 188 | variable_index >= multipliers.upper_bounds.size()) { |
| 189 | throw std::runtime_error("Dimension mismatch"); |
| 190 | } |
| 191 | |
| 192 | if (0. < multipliers.lower_bounds[variable_index]) { |
| 193 | return multipliers.lower_bounds[variable_index] * (primals[variable_index] - variables_lower_bounds[variable_index]) - shift_value; |
| 194 | } |
| 195 | if (multipliers.upper_bounds[variable_index] < 0.) { |
| 196 | return multipliers.upper_bounds[variable_index] * (primals[variable_index] - variables_upper_bounds[variable_index]) - shift_value; |
| 197 | } |
| 198 | return 0.; |
| 199 | }}; |
| 200 | |
| 201 | // inequality constraints |
| 202 | const auto& constraints_lower_bounds = this->model.get_constraints_lower_bounds(); |
| 203 | const auto& constraints_upper_bounds = this->model.get_constraints_upper_bounds(); |
| 204 | const VectorExpression constraint_complementarity{this->get_inequality_constraints(), [&](size_t constraint_index) { |
| 205 | if (constraint_index >= constraints.size() || constraint_index >= multipliers.constraints.size()) { |
| 206 | throw std::runtime_error("Dimension mismatch"); |
| 207 | } |
| 208 | |
| 209 | if (0. < multipliers.constraints[constraint_index]) { // lower bound |
| 210 | return multipliers.constraints[constraint_index] * (constraints[constraint_index] - constraints_lower_bounds[constraint_index]) - |
| 211 | shift_value; |
| 212 | } |
| 213 | if (multipliers.constraints[constraint_index] < 0.) { // upper bound |
| 214 | return multipliers.constraints[constraint_index] * (constraints[constraint_index] - constraints_upper_bounds[constraint_index]) - |
| 215 | shift_value; |
| 216 | } |
| 217 | return 0.; |
| 218 | }}; |
| 219 | return norm(residual_norm, variable_complementarity, constraint_complementarity); |
| 220 | } |
| 221 | |
| 222 | double OptimizationProblem::compute_centrality_error(const Vector<double>& primals, const Multipliers& multipliers, |
| 223 | double shift) const { |
no test coverage detected