Skip to content

Commit

Permalink
Several changes
Browse files Browse the repository at this point in the history
1. Fixing clang build errors

2. Removing more warnings
  • Loading branch information
whart222 committed May 8, 2024
1 parent 08d591c commit b76efc7
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lib/coek/coek/api/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParameterTerm>(); }

Parameter::Parameter(const std::string& name)
{
repn = CREATE_POINTER(ParameterTerm);
repn = std::make_shared<ParameterTerm>();
repn->name = name;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/coek/coek/ast/ast_operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion lib/coek/coek/ast/expr_terms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
2 changes: 1 addition & 1 deletion lib/coek/coek/ast/visitor_eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IfThenElseTerm>(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);
Expand Down
2 changes: 1 addition & 1 deletion lib/coek/coek/ast/visitor_simplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void visit_IfThenElseTerm(const expr_pointer_t& expr, VisitorData& data)
auto tmp = safe_pointer_cast<IfThenElseTerm>(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);
Expand Down
2 changes: 1 addition & 1 deletion lib/coek/coek/ast/visitor_to_QuadraticExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void visit(std::shared_ptr<IfThenElseTerm>& 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);
Expand Down
14 changes: 7 additions & 7 deletions lib/coek/coek/autograd/asl_repn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(n_var)];
LUv = new real[2 * static_cast<size_t>(n_var)];
// Uvx = new real[static_cast<size_t>(n_var)];
LUrhs = new real[static_cast<size_t>(n_con)];
Urhsx = new real[static_cast<size_t>(n_con)];
havex0 = new char[static_cast<size_t>(n_var)];
//
// Load model expressions
//
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/coek/coek/autograd/asl_repn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
1 change: 1 addition & 0 deletions lib/coek/coek/autograd/cppad_repn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/coek/coek/solvers/gurobi/gurobi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <unordered_map>

#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"
Expand Down
2 changes: 1 addition & 1 deletion lib/coek/coek/solvers/highs/highs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <unordered_map>

#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"
Expand Down
4 changes: 2 additions & 2 deletions lib/coek/test/smoke/test_autograd_asl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 1 addition & 2 deletions lib/coek/test/smoke/test_autograd_cppad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
16 changes: 8 additions & 8 deletions lib/coek/test/smoke/test_con.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(i);
}
m.add(c);

Expand All @@ -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<double>(i);
}
m.add(c);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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<double>(i);
c(i, i) = tmp;
}
REQUIRE(c.size() == 10);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/coek/test/smoke/test_param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down
4 changes: 2 additions & 2 deletions lib/coek/test/smoke/test_subexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(i);
}

static std::list<std::string> baseline
Expand Down Expand Up @@ -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<double>(i);
}
REQUIRE(e.size() == 10);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/coek/test/smoke/test_var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b76efc7

Please sign in to comment.