#ifndef LITERALBYMATCHABILITY_HPP
#define LITERALBYMATCHABILITY_HPP
#include "Clause.hpp"
#include "Term.hpp"
#include <utility>
namespace Kernel {
class LiteralByMatchability
{
private:
Literal* m_lit;
unsigned m_val;
public:
LiteralByMatchability(Literal* lit)
: m_lit(lit), m_val(computeRating(lit))
{ }
static unsigned computeRating(Literal* lit)
{
return lit->weight() - lit->getDistinctVars();
}
Literal* lit() const { return m_lit; }
bool operator<(LiteralByMatchability const& other) const
{
return m_val < other.m_val || (m_val == other.m_val && m_lit->getId() < other.m_lit->getId());
}
bool operator>(LiteralByMatchability const& other) const { return other.operator<(*this); }
bool operator<=(LiteralByMatchability const& other) const { return !operator>(other); }
bool operator>=(LiteralByMatchability const& other) const { return !operator<(other); }
bool operator==(LiteralByMatchability const& other) const { return m_lit == other.m_lit; }
bool operator!=(LiteralByMatchability const& other) const { return !operator==(other); }
static LiteralByMatchability find_least_matchable_in(Clause* c)
{
ASS_GE(c->length(), 1);
LiteralByMatchability best{(*c)[0]};
for (unsigned i = 1; i < c->length(); ++i) {
LiteralByMatchability curr{(*c)[i]};
if (curr > best) {
best = curr;
}
}
return best;
}
static std::pair<LiteralByMatchability,LiteralByMatchability> find_two_least_matchable_in(Clause* c)
{
ASS_GE(c->length(), 2);
LiteralByMatchability best{(*c)[0]};
LiteralByMatchability secondBest{(*c)[1]};
if (secondBest > best) {
std::swap(best, secondBest);
}
for (unsigned i = 2; i < c->length(); ++i) {
LiteralByMatchability curr{(*c)[i]};
if (curr > best) {
secondBest = best;
best = curr;
} else if (curr > secondBest) {
secondBest = curr;
}
}
ASS(best.lit() != secondBest.lit());
ASS(best > secondBest);
return {best, secondBest};
}
};
}
#endif