Skip to content

Commit

Permalink
added enum variable creation..
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardodebenedictis committed Jul 25, 2022
1 parent 76566c0 commit 5ea6926
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
build
2 changes: 1 addition & 1 deletion extern/core
Submodule core updated 1 files
+2 −1 include/item.h
1 change: 1 addition & 0 deletions include/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace ratio::solver
ORATIO_EXPORT ratio::core::expr new_real() noexcept override;
ORATIO_EXPORT ratio::core::expr new_time_point() noexcept override;
ORATIO_EXPORT ratio::core::expr new_string() noexcept override;
ORATIO_EXPORT ratio::core::expr new_enum(ratio::core::type &tp, const std::vector<ratio::core::expr> &allowed_vals) override;

/**
* @brief Get the sat core.
Expand Down
17 changes: 17 additions & 0 deletions src/solver.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "solver.h"
#include "atom.h"
#include <cassert>

namespace ratio::solver
{
Expand All @@ -10,4 +11,20 @@ namespace ratio::solver
ORATIO_EXPORT ratio::core::expr solver::new_real() noexcept { return std::make_shared<ratio::core::arith_item>(get_real_type(), semitone::lin(lra_th.new_var(), semitone::rational::ONE)); }
ORATIO_EXPORT ratio::core::expr solver::new_time_point() noexcept { return std::make_shared<ratio::core::arith_item>(get_time_type(), semitone::lin(lra_th.new_var(), semitone::rational::ONE)); }
ORATIO_EXPORT ratio::core::expr solver::new_string() noexcept { return std::make_shared<ratio::core::string_item>(get_string_type(), ""); }
ORATIO_EXPORT ratio::core::expr solver::new_enum(ratio::core::type &tp, const std::vector<ratio::core::expr> &allowed_vals)
{
assert(&tp != &get_bool_type());
assert(&tp != &get_int_type());
assert(&tp != &get_real_type());
assert(&tp != &get_time_type());
if (allowed_vals.empty())
throw ratio::core::inconsistency_exception();

std::vector<semitone::var_value *> vals;
vals.reserve(allowed_vals.size());
for (const auto &i : allowed_vals)
vals.push_back(i.get());

return std::make_shared<ratio::core::enum_item>(tp, ov_th.new_var(vals));
}
} // namespace ratio::solver

0 comments on commit 5ea6926

Please sign in to comment.