diff --git a/lib/coek/coek/api/expression.cpp b/lib/coek/coek/api/expression.cpp index 1fcfa77e..305ba2ae 100644 --- a/lib/coek/coek/api/expression.cpp +++ b/lib/coek/coek/api/expression.cpp @@ -16,11 +16,11 @@ expr_pointer_t convert_expr_template(const expr_pointer_t& expr); // Parameter // -Parameter::Parameter() { repn = CREATE_POINTER(ParameterTerm); } +Parameter::Parameter() { repn = std::make_shared(); } Parameter::Parameter(const std::string& name) { - repn = CREATE_POINTER(ParameterTerm); + repn = std::make_shared(); repn->name = name; } diff --git a/lib/coek/coek/ast/ast_operators.hpp b/lib/coek/coek/ast/ast_operators.hpp index ecba44aa..fe6bbe0e 100644 --- a/lib/coek/coek/ast/ast_operators.hpp +++ b/lib/coek/coek/ast/ast_operators.hpp @@ -512,7 +512,7 @@ inline expr_pointer_t if_then_else(const expr_pointer_t& cond_expr, const expr_p const expr_pointer_t& else_expr) { if (cond_expr->is_constant()) { - if (cond_expr->eval()) + if (cond_expr->eval() > (1.0 - 1e-7)) return then_expr; else return else_expr; diff --git a/lib/coek/coek/ast/expr_terms.hpp b/lib/coek/coek/ast/expr_terms.hpp index d15499c9..cb964117 100644 --- a/lib/coek/coek/ast/expr_terms.hpp +++ b/lib/coek/coek/ast/expr_terms.hpp @@ -247,7 +247,10 @@ class IfThenElseTerm : public ExpressionTerm { IfThenElseTerm(const expr_pointer_t& _cond, const expr_pointer_t& _then, const expr_pointer_t& _else); - double _eval() const { return cond_expr->_eval() ? then_expr->_eval() : else_expr->_eval(); } + double _eval() const + { + return cond_expr->_eval() > (1.0 - 1e-7) ? then_expr->_eval() : else_expr->_eval(); + } term_id id() { return IfThenElseTerm_id; } diff --git a/lib/coek/coek/ast/visitor_eval.cpp b/lib/coek/coek/ast/visitor_eval.cpp index 3771da2e..5335a338 100644 --- a/lib/coek/coek/ast/visitor_eval.cpp +++ b/lib/coek/coek/ast/visitor_eval.cpp @@ -148,7 +148,7 @@ double visit_DivideTerm(const expr_pointer_t& expr, VariableData& data) double visit_IfThenElseTerm(const expr_pointer_t& expr, VariableData& data) { auto tmp = safe_pointer_cast(expr); - if (visit_expression(tmp->cond_expr, data)) + if (visit_expression(tmp->cond_expr, data) > (1.0 - 1e-7)) return visit_expression(tmp->then_expr, data); else return visit_expression(tmp->else_expr, data); diff --git a/lib/coek/coek/ast/visitor_simplify.cpp b/lib/coek/coek/ast/visitor_simplify.cpp index 7062f34c..26134cb0 100644 --- a/lib/coek/coek/ast/visitor_simplify.cpp +++ b/lib/coek/coek/ast/visitor_simplify.cpp @@ -295,7 +295,7 @@ void visit_IfThenElseTerm(const expr_pointer_t& expr, VisitorData& data) auto tmp = safe_pointer_cast(expr); visit_expression(tmp->cond_expr, data); if (data.is_value) { - if (data.last_value) + if (data.last_value > (1.0 - 1e-7)) visit_expression(tmp->then_expr, data); else visit_expression(tmp->else_expr, data); diff --git a/lib/coek/coek/ast/visitor_to_QuadraticExpr.cpp b/lib/coek/coek/ast/visitor_to_QuadraticExpr.cpp index e0f76803..544dee67 100644 --- a/lib/coek/coek/ast/visitor_to_QuadraticExpr.cpp +++ b/lib/coek/coek/ast/visitor_to_QuadraticExpr.cpp @@ -232,7 +232,7 @@ void visit(std::shared_ptr& expr, QuadraticExpr& repn, double mu "Non-constant expressions in the condition of an if-then-else expression are " "non-quadratic."); - if (cond_repn.constval) + if (cond_repn.constval > (1.0 - 1e-7)) visit_expression(expr->then_expr, repn, multiplier); else visit_expression(expr->else_expr, repn, multiplier); diff --git a/lib/coek/coek/autograd/asl_repn.cpp b/lib/coek/coek/autograd/asl_repn.cpp index abb5b0c1..529b2cc8 100644 --- a/lib/coek/coek/autograd/asl_repn.cpp +++ b/lib/coek/coek/autograd/asl_repn.cpp @@ -359,12 +359,12 @@ void ASL_Repn::alloc_asl() // // allocate space for data read in by pfgh_read() // - X0 = new real[n_var]; - LUv = new real[2 * n_var]; - // Uvx = new real[n_var]; - LUrhs = new real[n_con]; - Urhsx = new real[n_con]; - havex0 = new char[n_var]; + X0 = new real[static_cast(n_var)]; + LUv = new real[2 * static_cast(n_var)]; + // Uvx = new real[static_cast(n_var)]; + LUrhs = new real[static_cast(n_con)]; + Urhsx = new real[static_cast(n_con)]; + havex0 = new char[static_cast(n_var)]; // // Load model expressions // @@ -507,7 +507,7 @@ void ASL_Repn::set_option(const std::string& option, int value) remove_nl_file = (value == 1); } -void ASL_Repn::set_option(const std::string& option, const std::string value) +void ASL_Repn::set_option(const std::string& option, const std::string& value) { if (option == "temp_directory") temp_directory = value; diff --git a/lib/coek/coek/autograd/asl_repn.hpp b/lib/coek/coek/autograd/asl_repn.hpp index e8f2cff6..6b27bc0b 100644 --- a/lib/coek/coek/autograd/asl_repn.hpp +++ b/lib/coek/coek/autograd/asl_repn.hpp @@ -108,7 +108,7 @@ class ASL_Repn : public NLPModelRepn { bool get_option(const std::string& option, std::string& value) const; void set_option(const std::string& option, bool value); void set_option(const std::string& option, int value); - void set_option(const std::string& option, const std::string value); + void set_option(const std::string& option, const std::string& value); protected: void* nerror_; diff --git a/lib/coek/coek/autograd/cppad_repn.cpp b/lib/coek/coek/autograd/cppad_repn.cpp index d7c6a9e4..40a1b398 100644 --- a/lib/coek/coek/autograd/cppad_repn.cpp +++ b/lib/coek/coek/autograd/cppad_repn.cpp @@ -5,6 +5,7 @@ #include "../ast/expr_terms.hpp" #include "../ast/value_terms.hpp" #include "../ast/visitor_fns.hpp" +#include "coek/api/expression.hpp" #include "coek/api/constraint.hpp" #include "coek/api/objective.hpp" #include "coek/model/model.hpp" diff --git a/lib/coek/coek/solvers/gurobi/gurobi.cpp b/lib/coek/coek/solvers/gurobi/gurobi.cpp index dbbd8c92..413708a9 100644 --- a/lib/coek/coek/solvers/gurobi/gurobi.cpp +++ b/lib/coek/coek/solvers/gurobi/gurobi.cpp @@ -4,8 +4,8 @@ #include #include "../../ast/value_terms.hpp" -#include "coek/api/constraint.hpp" #include "coek/api/expression.hpp" +#include "coek/api/constraint.hpp" #include "coek/api/objective.hpp" #include "coek/compact/constraint_sequence.hpp" #include "coek/compact/expression_sequence.hpp" diff --git a/lib/coek/coek/solvers/highs/highs.cpp b/lib/coek/coek/solvers/highs/highs.cpp index 3571f9d3..59267de1 100644 --- a/lib/coek/coek/solvers/highs/highs.cpp +++ b/lib/coek/coek/solvers/highs/highs.cpp @@ -3,8 +3,8 @@ #include #include "../../ast/value_terms.hpp" -#include "coek/api/constraint.hpp" #include "coek/api/expression.hpp" +#include "coek/api/constraint.hpp" #include "coek/api/objective.hpp" #include "coek/compact/constraint_sequence.hpp" #include "coek/compact/expression_sequence.hpp" diff --git a/lib/coek/test/smoke/test_autograd_asl.cpp b/lib/coek/test/smoke/test_autograd_asl.cpp index 47b4872e..cbe73fde 100644 --- a/lib/coek/test/smoke/test_autograd_asl.cpp +++ b/lib/coek/test/smoke/test_autograd_asl.cpp @@ -4,8 +4,8 @@ #include "coek/ast/base_terms.hpp" #include "coek/coek.hpp" -const double PI = 3.141592653589793238463; -const double E = exp(1.0); +// const double PI = 3.141592653589793238463; +// const double E = exp(1.0); #define ADNAME "asl" diff --git a/lib/coek/test/smoke/test_autograd_cppad.cpp b/lib/coek/test/smoke/test_autograd_cppad.cpp index bb5e1d61..b0071cd5 100644 --- a/lib/coek/test/smoke/test_autograd_cppad.cpp +++ b/lib/coek/test/smoke/test_autograd_cppad.cpp @@ -4,8 +4,7 @@ #include "coek/ast/base_terms.hpp" #include "coek/coek.hpp" -const double PI = 3.141592653589793238463; -const double E = exp(1.0); +// const double E = exp(1.0); #define ADNAME "cppad" diff --git a/lib/coek/test/smoke/test_con.cpp b/lib/coek/test/smoke/test_con.cpp index 3e8e70be..e10080de 100644 --- a/lib/coek/test/smoke/test_con.cpp +++ b/lib/coek/test/smoke/test_con.cpp @@ -1755,7 +1755,7 @@ TEMPLATE_TEST_CASE("indexed_constraint", "[smoke]", MODEL_TYPES) v.generate_names(); auto c = coek::constraint(10); for (size_t i = 0; i < 10; ++i) { - c(i) = v(i) == 1.0 * i; + c(i) = v(i) == static_cast(i); } m.add(c); @@ -1770,7 +1770,7 @@ TEMPLATE_TEST_CASE("indexed_constraint", "[smoke]", MODEL_TYPES) auto v = coek::variable(10); auto c = coek::constraint(10); for (int i = 0; i < 10; ++i) { - c(i) = v(i) == 1.0 * i; + c(i) = v(i) == static_cast(i); } m.add(c); } @@ -1783,7 +1783,7 @@ TEMPLATE_TEST_CASE("indexed_constraint", "[smoke]", MODEL_TYPES) auto c = coek::constraint(10); for (int i = 0; i < 10; ++i) { p.value(i); - c(p) = v(p) == 1.0 * i; + c(p) = v(p) == i; } m.add(c); } @@ -1798,7 +1798,7 @@ TEMPLATE_TEST_CASE("indexed_constraint", "[smoke]", MODEL_TYPES) auto c = coek::constraint(10); for (int i=0; i<10; ++i) { p.value(i+1); - c(p-1) = v(p+1) == 1.0*i; + c(p-1) = v(p+1) == i; } m.add(c); } @@ -1858,7 +1858,7 @@ TEMPLATE_TEST_CASE("indexed_constraint", "[smoke]", MODEL_TYPES) auto v = coek::variable({10, 10}); auto c = coek::constraint({10, 10}); for (size_t i = 0; i < 10; ++i) { - auto tmp = v(i, i) == 1.0 * i; + auto tmp = v(i, i) == static_cast(i); c(i, i) = tmp; } REQUIRE(c.size() == 10); @@ -1870,7 +1870,7 @@ TEMPLATE_TEST_CASE("indexed_constraint", "[smoke]", MODEL_TYPES) auto v = coek::variable({10, 10, 10}); auto c = coek::constraint({10, 10, 10}); for (int i = 0; i < 10; ++i) { - auto tmp = v(i, i, i) == 1.0 * i; + auto tmp = v(i, i, i) == i; c(i, i, i) = tmp; } REQUIRE(c.size() == 10); @@ -1925,7 +1925,7 @@ TEMPLATE_TEST_CASE("indexed_constraint", "[smoke]", MODEL_TYPES) auto v = coek::variable(A); auto c = coek::constraint(A); for (size_t i = 0; i < 10; ++i) { - auto tmp = v(i, i) == 1.0 * i; + auto tmp = v(i, i) == i; c(i, i) = tmp; } REQUIRE(c.size() == 10); @@ -1938,7 +1938,7 @@ TEMPLATE_TEST_CASE("indexed_constraint", "[smoke]", MODEL_TYPES) auto v = coek::variable(A); auto c = coek::constraint(A); for (int i = 0; i < 10; ++i) { - auto tmp = v(i, i, i) == 1.0 * i; + auto tmp = v(i, i, i) == i; c(i, i, i) = tmp; } REQUIRE(c.size() == 10); diff --git a/lib/coek/test/smoke/test_param.cpp b/lib/coek/test/smoke/test_param.cpp index 5602e083..a51daaaf 100644 --- a/lib/coek/test/smoke/test_param.cpp +++ b/lib/coek/test/smoke/test_param.cpp @@ -328,7 +328,7 @@ TEST_CASE("1D_param_array", "[smoke]") for (size_t i = 0; i < 4; i++) params(i).value(q + (int)i); // TODO - generalize API to include unsigned ints for (size_t i = 0; i < 4; i++) - REQUIRE(params(i).value() == 2 + i); + REQUIRE(params(i).value() == 2 + (int)i); } WHEN("value all - q") { diff --git a/lib/coek/test/smoke/test_subexpression.cpp b/lib/coek/test/smoke/test_subexpression.cpp index 8e1dad89..69ef1340 100644 --- a/lib/coek/test/smoke/test_subexpression.cpp +++ b/lib/coek/test/smoke/test_subexpression.cpp @@ -73,7 +73,7 @@ TEST_CASE("indexed_subexpression", "[smoke]") v.generate_names(); auto e = coek::subexpression("e", 10); for (size_t i = 0; i < 10; ++i) { - e(i) = v(i) + 1.0 * i; + e(i) = v(i) + static_cast(i); } static std::list baseline @@ -174,7 +174,7 @@ TEST_CASE("indexed_subexpression", "[smoke]") auto v = coek::variable({10, 10}); auto e = coek::subexpression("e", {10, 10}); for (size_t i = 0; i < 10; ++i) { - e(i, i) = v(i, i) + 1.0 * i; + e(i, i) = v(i, i) + static_cast(i); } REQUIRE(e.size() == 10); } diff --git a/lib/coek/test/smoke/test_var.cpp b/lib/coek/test/smoke/test_var.cpp index 4dd1582e..1bbdd58b 100644 --- a/lib/coek/test/smoke/test_var.cpp +++ b/lib/coek/test/smoke/test_var.cpp @@ -376,7 +376,7 @@ TEST_CASE("1D_var_array", "[smoke]") for (size_t i = 0; i < 4; i++) vars(i).value(q + (int)i); // TODO - generalize API to include unsigned ints for (size_t i = 0; i < 4; i++) - REQUIRE(vars(i).value() == 2 + i); + REQUIRE(vars(i).value() == 2 + (int)i); } WHEN("value all - q")