diff --git a/bindings/AMPL/AMPLModel.cpp b/bindings/AMPL/AMPLModel.cpp index fc9af6f5..a0725e7f 100644 --- a/bindings/AMPL/AMPLModel.cpp +++ b/bindings/AMPL/AMPLModel.cpp @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project directory for details. #include +#include #include "AMPLModel.hpp" #include "linear_algebra/RectangularMatrix.hpp" #include "linear_algebra/SymmetricMatrix.hpp" @@ -19,8 +20,8 @@ namespace uno { int n_discrete = asl->i.nbv_ + asl->i.niv_ + asl->i.nlvbi_ + asl->i.nlvci_ + asl->i.nlvoi_; if (0 < n_discrete) { - WARNING << "Ignoring integrality of " << n_discrete << " variables.\n"; - asl->i.need_nl_ = 0; + throw std::runtime_error("Error: " + std::to_string(n_discrete) + " variables are discrete, which Uno cannot handle."); + // asl->i.need_nl_ = 0; } // preallocate initial primal and dual solutions @@ -33,8 +34,7 @@ namespace uno { } // generate the ASL object and call the private constructor - AMPLModel::AMPLModel(const std::string& file_name) : AMPLModel(file_name, generate_asl(file_name)) { - } + AMPLModel::AMPLModel(const std::string& file_name) : AMPLModel(file_name, generate_asl(file_name)) { } AMPLModel::AMPLModel(const std::string& file_name, ASL* asl) : Model(file_name, static_cast(asl->i.n_var_), static_cast(asl->i.n_con_), (asl->i.objtype_[0] == 1) ? -1. : 1.), diff --git a/bindings/AMPL/uno_ampl.cpp b/bindings/AMPL/uno_ampl.cpp index d2ca25b6..7b0e6332 100644 --- a/bindings/AMPL/uno_ampl.cpp +++ b/bindings/AMPL/uno_ampl.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2018-2024 Charlie Vanaret // Licensed under the MIT license. See LICENSE file in the project directory for details. +# #include "ingredients/globalization_mechanisms/GlobalizationMechanism.hpp" #include "ingredients/globalization_mechanisms/GlobalizationMechanismFactory.hpp" #include "ingredients/constraint_relaxation_strategies/ConstraintRelaxationStrategy.hpp" @@ -23,28 +24,33 @@ void* operator new(size_t size) { namespace uno { void run_uno_ampl(const std::string& model_name, const Options& options) { - // AMPL model - std::unique_ptr ampl_model = std::make_unique(model_name); + try { + // AMPL model + std::unique_ptr ampl_model = std::make_unique(model_name); - // initialize initial primal and dual points - Iterate initial_iterate(ampl_model->number_variables, ampl_model->number_constraints); - ampl_model->initial_primal_point(initial_iterate.primals); - ampl_model->project_onto_variable_bounds(initial_iterate.primals); - ampl_model->initial_dual_point(initial_iterate.multipliers.constraints); - initial_iterate.feasibility_multipliers.reset(); + // initialize initial primal and dual points + Iterate initial_iterate(ampl_model->number_variables, ampl_model->number_constraints); + ampl_model->initial_primal_point(initial_iterate.primals); + ampl_model->project_onto_variable_bounds(initial_iterate.primals); + ampl_model->initial_dual_point(initial_iterate.multipliers.constraints); + initial_iterate.feasibility_multipliers.reset(); - // reformulate (scale, add slacks, relax the bounds, ...) if necessary - std::unique_ptr model = ModelFactory::reformulate(std::move(ampl_model), initial_iterate, options); + // reformulate (scale, add slacks, relax the bounds, ...) if necessary + std::unique_ptr model = ModelFactory::reformulate(std::move(ampl_model), initial_iterate, options); - // create the constraint relaxation strategy, the globalization mechanism and the Uno solver - auto constraint_relaxation_strategy = ConstraintRelaxationStrategyFactory::create(*model, options); - auto globalization_mechanism = GlobalizationMechanismFactory::create(*constraint_relaxation_strategy, options); - Uno uno = Uno(*globalization_mechanism, options); + // create the constraint relaxation strategy, the globalization mechanism and the Uno solver + auto constraint_relaxation_strategy = ConstraintRelaxationStrategyFactory::create(*model, options); + auto globalization_mechanism = GlobalizationMechanismFactory::create(*constraint_relaxation_strategy, options); + Uno uno = Uno(*globalization_mechanism, options); - // solve the instance - Result result = uno.solve(*model, initial_iterate, options); - Uno::print_optimization_summary(options, result); - // std::cout << "memory_allocation_amount = " << memory_allocation_amount << '\n'; + // solve the instance + Result result = uno.solve(*model, initial_iterate, options); + Uno::print_optimization_summary(options, result); + // std::cout << "memory_allocation_amount = " << memory_allocation_amount << '\n'; + } + catch (std::exception& exception) { + ERROR << exception.what() << '\n'; + } } } // namespace