Skip to content

Commit

Permalink
Add z3disjunction_flaw class and enhance z3solver with new disjunctio…
Browse files Browse the repository at this point in the history
…n handling
  • Loading branch information
riccardodebenedictis committed Jan 4, 2025
1 parent cdc371a commit 07f84f4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/graph.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "core.hpp"
#include <deque>

#ifdef ENABLE_API
#define NEW_FLAW(f) flaw_created(f)
Expand Down Expand Up @@ -90,6 +91,7 @@ namespace ratio
auto f = new Tp(std::forward<Args>(args)...);
NEW_FLAW(*f);
flaws.emplace_back(std::unique_ptr<flaw>(f));
flaw_q.push_back(*f);
return *f;
}

Expand Down Expand Up @@ -206,5 +208,6 @@ namespace ratio
std::vector<std::unique_ptr<resolver>> resolvers; // The set of resolvers
std::optional<std::reference_wrapper<flaw>> c_flaw; // the current flaw..
std::optional<std::reference_wrapper<resolver>> c_res; // the current resolver..
std::deque<std::reference_wrapper<flaw>> flaw_q; // the flaw queue (for the graph building procedure)..
};
} // namespace ratio
14 changes: 14 additions & 0 deletions include/z3/z3flaws.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,18 @@ namespace ratio
private:
riddle::atom_expr atom;
};

class z3disjunction_flaw : public z3flaw
{
public:
z3disjunction_flaw(z3solver &slv, std::vector<std::reference_wrapper<resolver>> &&causes, std::vector<std::unique_ptr<riddle::conjunction>> &&disjuncts) noexcept;

[[nodiscard]] const std::vector<std::unique_ptr<riddle::conjunction>> &get_disjuncts() const noexcept { return disjuncts; }

private:
void compute_resolvers() override;

private:
std::vector<std::unique_ptr<riddle::conjunction>> disjuncts;
};
} // namespace ratio
7 changes: 7 additions & 0 deletions src/z3/z3flaws.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "z3flaws.hpp"
#include "conjunction.hpp"

namespace ratio
{
Expand All @@ -19,4 +20,10 @@ namespace ratio
void z3atom_flaw::compute_resolvers()
{
}

z3disjunction_flaw::z3disjunction_flaw(z3solver &slv, std::vector<std::reference_wrapper<resolver>> &&causes, std::vector<std::unique_ptr<riddle::conjunction>> &&disjuncts) noexcept : z3flaw(slv, std::move(causes)), disjuncts(std::move(disjuncts)) {}

void z3disjunction_flaw::compute_resolvers()
{
}
} // namespace ratio
6 changes: 5 additions & 1 deletion src/z3/z3solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ namespace ratio

void z3solver::new_disjunction(std::vector<std::unique_ptr<riddle::conjunction>> &&disjuncts)
{
std::vector<std::reference_wrapper<resolver>> causes;
if (get_current_resolver().has_value())
causes.push_back(get_current_resolver().value());
new_flaw<z3disjunction_flaw>(*this, std::move(causes), std::move(disjuncts));
}
void z3solver::assert_fact(riddle::bool_expr fact)
{
Expand All @@ -314,7 +318,7 @@ namespace ratio
std::vector<std::reference_wrapper<resolver>> causes;
if (get_current_resolver().has_value())
causes.push_back(get_current_resolver().value());
auto &f = new_flaw<z3atom_flaw>(*this, std::move(causes), atm);
new_flaw<z3atom_flaw>(*this, std::move(causes), atm);
return atm;
}

Expand Down

0 comments on commit 07f84f4

Please sign in to comment.