Skip to content

Commit

Permalink
Merge pull request #122 from cvanaret/ingredients
Browse files Browse the repository at this point in the history
(WIP) Ingredient refactoring
  • Loading branch information
cvanaret authored Dec 12, 2024
2 parents a403f30 + aba1d3d commit a0fe28a
Show file tree
Hide file tree
Showing 67 changed files with 195 additions and 229 deletions.
19 changes: 9 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ file(GLOB UNO_SOURCE_FILES
uno/ingredients/globalization_strategies/switching_methods/filter_methods/filters/*.cpp
uno/ingredients/globalization_strategies/switching_methods/funnel_methods/*.cpp
uno/ingredients/hessian_models/*.cpp
uno/ingredients/subproblems/*.cpp
uno/ingredients/subproblems/inequality_constrained_methods/*.cpp
uno/ingredients/subproblems/interior_point_methods/*.cpp
uno/ingredients/inequality_handling_methods/*.cpp
uno/ingredients/inequality_handling_methods/inequality_constrained_methods/*.cpp
uno/ingredients/inequality_handling_methods/interior_point_methods/*.cpp
uno/ingredients/subproblem_solvers/*.cpp
uno/model/*.cpp
uno/optimization/*.cpp
uno/options/*.cpp
uno/preprocessing/*.cpp
uno/reformulation/*.cpp
uno/solvers/*.cpp
uno/tools/*.cpp
)

Expand Down Expand Up @@ -115,14 +114,14 @@ else()
endif()
endif()
if(HSL OR MA57)
list(APPEND UNO_SOURCE_FILES uno/solvers/MA57/MA57Solver.cpp)
list(APPEND UNO_SOURCE_FILES uno/ingredients/subproblem_solvers/MA57/MA57Solver.cpp)
list(APPEND TESTS_UNO_SOURCE_FILES unotest/functional_tests/MA57SolverTests.cpp)

find_package(BLAS REQUIRED)
list(APPEND LIBRARIES ${BLAS_LIBRARIES})
endif()
if(HSL OR MA27)
list(APPEND UNO_SOURCE_FILES uno/solvers/MA27/MA27Solver.cpp)
list(APPEND UNO_SOURCE_FILES uno/ingredients/subproblem_solvers/MA27/MA27Solver.cpp)
list(APPEND TESTS_UNO_SOURCE_FILES unotest/functional_tests/MA27SolverTests.cpp)

find_package(BLAS REQUIRED)
Expand All @@ -142,7 +141,7 @@ find_library(BQPD bqpd)
if(NOT BQPD)
message(WARNING "Optional library BQPD was not found.")
else()
list(APPEND UNO_SOURCE_FILES uno/solvers/BQPD/BQPDSolver.cpp)
list(APPEND UNO_SOURCE_FILES uno/ingredients/subproblem_solvers/BQPD/BQPDSolver.cpp)
list(APPEND TESTS_UNO_SOURCE_FILES unotest/functional_tests/BQPDSolverTests.cpp)
link_to_uno(bqpd ${BQPD})
endif()
Expand All @@ -152,7 +151,7 @@ find_package(HIGHS)
if(NOT HIGHS)
message(WARNING "Optional library HiGHS was not found.")
else()
list(APPEND UNO_SOURCE_FILES uno/solvers/HiGHS/HiGHSSolver.cpp)
list(APPEND UNO_SOURCE_FILES uno/ingredients/subproblem_solvers/HiGHS/HiGHSSolver.cpp)
list(APPEND TESTS_UNO_SOURCE_FILES unotest/functional_tests/HiGHSSolverTests.cpp)
link_to_uno(highs ${HIGHS})
list(APPEND LIBRARIES highs::highs)
Expand All @@ -163,7 +162,7 @@ find_package(MUMPS)
if(NOT MUMPS_LIBRARY)
message(WARNING "Optional library MUMPS was not found.")
else()
list(APPEND UNO_SOURCE_FILES uno/solvers/MUMPS/MUMPSSolver.cpp)
list(APPEND UNO_SOURCE_FILES uno/ingredients/subproblem_solvers/MUMPS/MUMPSSolver.cpp)
list(APPEND TESTS_UNO_SOURCE_FILES unotest/functional_tests/MUMPSSolverTests.cpp)
list(APPEND LIBRARIES ${MUMPS_LIBRARY} ${MUMPS_COMMON_LIBRARY} ${MUMPS_PORD_LIBRARY})

Expand Down
10 changes: 5 additions & 5 deletions uno/Uno.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include "ingredients/globalization_mechanisms/GlobalizationMechanism.hpp"
#include "ingredients/globalization_mechanisms/GlobalizationMechanismFactory.hpp"
#include "ingredients/globalization_strategies/GlobalizationStrategyFactory.hpp"
#include "ingredients/subproblems/SubproblemFactory.hpp"
#include "ingredients/inequality_handling_methods/InequalityHandlingMethodFactory.hpp"
#include "ingredients/subproblem_solvers/QPSolverFactory.hpp"
#include "ingredients/subproblem_solvers/LPSolverFactory.hpp"
#include "ingredients/subproblem_solvers/SymmetricIndefiniteLinearSolverFactory.hpp"
#include "linear_algebra/Vector.hpp"
#include "model/Model.hpp"
#include "optimization/Iterate.hpp"
#include "optimization/WarmstartInformation.hpp"
#include "solvers/QPSolverFactory.hpp"
#include "solvers/LPSolverFactory.hpp"
#include "solvers/SymmetricIndefiniteLinearSolverFactory.hpp"
#include "tools/Logger.hpp"
#include "optimization/OptimizationStatus.hpp"
#include "options/Options.hpp"
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace uno {
std::cout << "- Constraint relaxation strategies: " << join(ConstraintRelaxationStrategyFactory::available_strategies(), ", ") << '\n';
std::cout << "- Globalization mechanisms: " << join(GlobalizationMechanismFactory::available_strategies(), ", ") << '\n';
std::cout << "- Globalization strategies: " << join(GlobalizationStrategyFactory::available_strategies(), ", ") << '\n';
std::cout << "- Subproblems: " << join(SubproblemFactory::available_strategies(), ", ") << '\n';
std::cout << "- Subproblems: " << join(InequalityHandlingMethodFactory::available_strategies(), ", ") << '\n';
std::cout << "- QP solvers: " << join(QPSolverFactory::available_solvers(), ", ") << '\n';
std::cout << "- LP solvers: " << join(LPSolverFactory::available_solvers(), ", ") << '\n';
std::cout << "- Linear solvers: " << join(SymmetricIndefiniteLinearSolverFactory::available_solvers(), ", ") << '\n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// Licensed under the MIT license. See LICENSE file in the project directory for details.

#include "ConstraintRelaxationStrategy.hpp"
#include "OptimizationProblem.hpp"
#include "ingredients/globalization_strategies/GlobalizationStrategy.hpp"
#include "ingredients/globalization_strategies/GlobalizationStrategyFactory.hpp"
#include "optimization/Direction.hpp"
#include "ingredients/subproblems/Subproblem.hpp"
#include "ingredients/subproblems/SubproblemFactory.hpp"
#include "ingredients/inequality_handling_methods/InequalityHandlingMethod.hpp"
#include "ingredients/inequality_handling_methods/InequalityHandlingMethodFactory.hpp"
#include "linear_algebra/SymmetricMatrix.hpp"
#include "model/Model.hpp"
#include "optimization/Iterate.hpp"
#include "optimization/Multipliers.hpp"
#include "reformulation/OptimizationProblem.hpp"
#include "symbolic/VectorView.hpp"
#include "symbolic/Expression.hpp"
#include "options/Options.hpp"
Expand All @@ -22,7 +22,7 @@ namespace uno {
size_t number_objective_gradient_nonzeros, size_t number_jacobian_nonzeros, size_t number_hessian_nonzeros, const Options& options):
model(model),
globalization_strategy(GlobalizationStrategyFactory::create(options.get_string("globalization_strategy"), options)),
subproblem(SubproblemFactory::create(number_variables, number_constraints, number_objective_gradient_nonzeros, number_jacobian_nonzeros,
inequality_handling_method(InequalityHandlingMethodFactory::create(number_variables, number_constraints, number_objective_gradient_nonzeros, number_jacobian_nonzeros,
number_hessian_nonzeros, options)),
progress_norm(norm_from_string(options.get_string("progress_norm"))),
residual_norm(norm_from_string(options.get_string("residual_norm"))),
Expand All @@ -37,13 +37,13 @@ namespace uno {
ConstraintRelaxationStrategy::~ConstraintRelaxationStrategy() { }

void ConstraintRelaxationStrategy::set_trust_region_radius(double trust_region_radius) {
this->subproblem->set_trust_region_radius(trust_region_radius);
this->inequality_handling_method->set_trust_region_radius(trust_region_radius);
}

// with initial point
void ConstraintRelaxationStrategy::compute_feasible_direction(Statistics& statistics, Iterate& current_iterate, Direction& direction,
const Vector<double>& initial_point, WarmstartInformation& warmstart_information) {
this->subproblem->set_initial_point(initial_point);
this->inequality_handling_method->set_initial_point(initial_point);
this->compute_feasible_direction(statistics, current_iterate, direction, warmstart_information);
}

Expand Down Expand Up @@ -91,11 +91,11 @@ namespace uno {
}

void ConstraintRelaxationStrategy::compute_progress_measures(Iterate& current_iterate, Iterate& trial_iterate) {
if (this->subproblem->subproblem_definition_changed) {
if (this->inequality_handling_method->subproblem_definition_changed) {
DEBUG << "The subproblem definition changed, the globalization strategy is reset and the auxiliary measure is recomputed\n";
this->globalization_strategy->reset();
this->subproblem->set_auxiliary_measure(this->model, current_iterate);
this->subproblem->subproblem_definition_changed = false;
this->inequality_handling_method->set_auxiliary_measure(this->model, current_iterate);
this->inequality_handling_method->subproblem_definition_changed = false;
}
this->evaluate_progress_measures(trial_iterate);
}
Expand Down Expand Up @@ -241,10 +241,10 @@ namespace uno {
}

size_t ConstraintRelaxationStrategy::get_hessian_evaluation_count() const {
return this->subproblem->get_hessian_evaluation_count();
return this->inequality_handling_method->get_hessian_evaluation_count();
}

size_t ConstraintRelaxationStrategy::get_number_subproblems_solved() const {
return this->subproblem->number_subproblems_solved;
return this->inequality_handling_method->number_subproblems_solved;
}
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace uno {
class OptimizationProblem;
class Options;
class Statistics;
class Subproblem;
class InequalityHandlingMethod;
template <typename IndexType, typename ElementType>
class SymmetricMatrix;
class UserCallbacks;
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace uno {
protected:
const Model& model;
const std::unique_ptr<GlobalizationStrategy> globalization_strategy;
const std::unique_ptr<Subproblem> subproblem;
const std::unique_ptr<InequalityHandlingMethod> inequality_handling_method;
const Norm progress_norm;
const Norm residual_norm;
const double residual_scaling_threshold;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ namespace uno {
};
} // namespace

#endif // UNO_ELASTICVARIABLES_H
#endif // UNO_ELASTICVARIABLES_H
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <functional>
#include "FeasibilityRestoration.hpp"
#include "ingredients/globalization_strategies/GlobalizationStrategy.hpp"
#include "optimization/Direction.hpp"
#include "ingredients/subproblems/Subproblem.hpp"
#include "ingredients/inequality_handling_methods/InequalityHandlingMethod.hpp"
#include "linear_algebra/SymmetricIndefiniteLinearSystem.hpp"
#include "model/Model.hpp"
#include "optimization/Direction.hpp"
#include "optimization/Iterate.hpp"
#include "optimization/WarmstartInformation.hpp"
#include "options/Options.hpp"
Expand Down Expand Up @@ -45,15 +45,15 @@ namespace uno {

void FeasibilityRestoration::initialize(Statistics& statistics, Iterate& initial_iterate, const Options& options) {
// statistics
this->subproblem->initialize_statistics(statistics, options);
this->inequality_handling_method->initialize_statistics(statistics, options);
statistics.add_column("phase", Statistics::int_width, options.get_int("statistics_restoration_phase_column_order"));
statistics.set("phase", "OPT");

// initial iterate
initial_iterate.feasibility_residuals.lagrangian_gradient.resize(this->feasibility_problem.number_variables);
initial_iterate.feasibility_multipliers.lower_bounds.resize(this->feasibility_problem.number_variables);
initial_iterate.feasibility_multipliers.upper_bounds.resize(this->feasibility_problem.number_variables);
this->subproblem->generate_initial_iterate(this->optimality_problem, initial_iterate);
this->inequality_handling_method->generate_initial_iterate(this->optimality_problem, initial_iterate);
this->evaluate_progress_measures(initial_iterate);
this->compute_primal_dual_residuals(initial_iterate);
this->set_statistics(statistics, initial_iterate);
Expand All @@ -74,7 +74,7 @@ namespace uno {
statistics.set("status", std::string("infeasible " + this->subproblem_strategy));
DEBUG << "/!\\ The subproblem is infeasible\n";
this->switch_to_feasibility_problem(statistics, current_iterate, warmstart_information);
this->subproblem->set_initial_point(direction.primals);
this->inequality_handling_method->set_initial_point(direction.primals);
}
else {
warmstart_information.no_changes();
Expand Down Expand Up @@ -105,14 +105,14 @@ namespace uno {
DEBUG << "Switching from optimality to restoration phase\n";
this->current_phase = Phase::FEASIBILITY_RESTORATION;
this->globalization_strategy->notify_switch_to_feasibility(current_iterate.progress);
this->subproblem->initialize_feasibility_problem(this->feasibility_problem, current_iterate);
this->inequality_handling_method->initialize_feasibility_problem(this->feasibility_problem, current_iterate);
// save the current point (progress and primals) upon switching
this->reference_optimality_progress = current_iterate.progress;
this->reference_optimality_primals = current_iterate.primals;
this->feasibility_problem.set_proximal_multiplier(this->subproblem->proximal_coefficient(current_iterate));
this->feasibility_problem.set_proximal_multiplier(this->inequality_handling_method->proximal_coefficient(current_iterate));

current_iterate.set_number_variables(this->feasibility_problem.number_variables);
this->subproblem->set_elastic_variable_values(this->feasibility_problem, current_iterate);
this->inequality_handling_method->set_elastic_variable_values(this->feasibility_problem, current_iterate);
DEBUG2 << "Current iterate:\n" << current_iterate << '\n';

if (Logger::level == INFO) statistics.print_current_line();
Expand All @@ -122,7 +122,7 @@ namespace uno {
void FeasibilityRestoration::solve_subproblem(Statistics& statistics, const OptimizationProblem& problem, Iterate& current_iterate,
const Multipliers& current_multipliers, Direction& direction, WarmstartInformation& warmstart_information) {
direction.set_dimensions(problem.number_variables, problem.number_constraints);
this->subproblem->solve(statistics, problem, current_iterate, current_multipliers, direction, warmstart_information);
this->inequality_handling_method->solve(statistics, problem, current_iterate, current_multipliers, direction, warmstart_information);
direction.norm = norm_inf(view(direction.primals, 0, this->model.number_variables));
DEBUG3 << direction << '\n';
}
Expand All @@ -143,15 +143,15 @@ namespace uno {
trial_iterate.set_number_variables(this->optimality_problem.number_variables);
current_iterate.objective_multiplier = trial_iterate.objective_multiplier = 1.;

this->subproblem->exit_feasibility_problem(this->optimality_problem, trial_iterate);
this->inequality_handling_method->exit_feasibility_problem(this->optimality_problem, trial_iterate);
// set a cold start in the subproblem solver
warmstart_information.whole_problem_changed();
}

bool FeasibilityRestoration::is_iterate_acceptable(Statistics& statistics, Iterate& current_iterate, Iterate& trial_iterate, const Direction& direction,
double step_length, WarmstartInformation& warmstart_information, UserCallbacks& user_callbacks) {
// TODO pick right multipliers
this->subproblem->postprocess_iterate(this->current_problem(), trial_iterate);
this->inequality_handling_method->postprocess_iterate(this->current_problem(), trial_iterate);
this->compute_progress_measures(current_iterate, trial_iterate);
trial_iterate.objective_multiplier = this->current_problem().get_objective_multiplier();

Expand Down Expand Up @@ -201,15 +201,15 @@ namespace uno {
void FeasibilityRestoration::evaluate_progress_measures(Iterate& iterate) const {
this->set_infeasibility_measure(iterate);
this->set_objective_measure(iterate);
this->subproblem->set_auxiliary_measure(this->model, iterate);
this->inequality_handling_method->set_auxiliary_measure(this->model, iterate);
}

ProgressMeasures FeasibilityRestoration::compute_predicted_reduction_models(Iterate& current_iterate, const Direction& direction, double step_length) {
return {
this->compute_predicted_infeasibility_reduction_model(current_iterate, direction.primals, step_length),
this->first_order_predicted_reduction ? this->compute_predicted_objective_reduction_model(current_iterate, direction.primals, step_length) :
this->compute_predicted_objective_reduction_model(current_iterate, direction.primals, step_length, this->subproblem->get_lagrangian_hessian()),
this->subproblem->compute_predicted_auxiliary_reduction_model(this->model, current_iterate, direction.primals, step_length)
this->compute_predicted_objective_reduction_model(current_iterate, direction.primals, step_length, this->inequality_handling_method->get_lagrangian_hessian()),
this->inequality_handling_method->compute_predicted_auxiliary_reduction_model(this->model, current_iterate, direction.primals, step_length)
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <memory>
#include "ConstraintRelaxationStrategy.hpp"
#include "ingredients/globalization_strategies/ProgressMeasures.hpp"
#include "reformulation/OptimalityProblem.hpp"
#include "reformulation/l1RelaxedProblem.hpp"
#include "OptimalityProblem.hpp"
#include "l1RelaxedProblem.hpp"

namespace uno {
enum class Phase {FEASIBILITY_RESTORATION = 1, OPTIMALITY = 2};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ namespace uno {
};
} // namespace

#endif // UNO_OPTIMALITYPROBLEM_H
#endif // UNO_OPTIMALITYPROBLEM_H
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a0fe28a

Please sign in to comment.