use of org.logicng.formulas.Formula in project LogicNG by logic-ng.
the class HypergraphGenerator method fromCNF.
/**
* Generates a hypergraph from a CNF given as a list of clauses. Each variable is represented by a node in the
* hypergraph, each clause is represented by a hyperedge between all variables of the clause.
* @param cnf the list of clauses of the CNF for the hypergraph
* @return the hypergraph for the CNF formula
*/
public static Hypergraph<Variable> fromCNF(final List<Formula> cnf) {
final Hypergraph<Variable> hypergraph = new Hypergraph<>();
final Map<Variable, HypergraphNode<Variable>> nodes = new HashMap<>();
for (final Formula clause : cnf) {
switch(clause.type()) {
case PBC:
case EQUIV:
case IMPL:
case NOT:
case AND:
throw new IllegalStateException("Unexpected element in clause: " + clause);
case LITERAL:
case OR:
addClause(clause, hypergraph, nodes);
break;
}
}
return hypergraph;
}
use of org.logicng.formulas.Formula in project LogicNG by logic-ng.
the class AIGTransformation method transformOr.
private Formula transformOr(final Or or) {
Formula aig = or.transformationCacheEntry(AIG);
if (aig == null) {
final LinkedHashSet<Formula> nops = new LinkedHashSet<>(or.numberOfOperands());
for (final Formula op : or) {
nops.add(f.not(apply(op, cache)));
}
aig = f.not(f.and(nops));
if (cache) {
or.setTransformationCacheEntry(AIG, aig);
aig.setPredicateCacheEntry(PredicateCacheEntry.IS_AIG, true);
}
}
return aig;
}
use of org.logicng.formulas.Formula in project LogicNG by logic-ng.
the class AIGTransformation method transformAnd.
private Formula transformAnd(final And and) {
Formula aig = and.transformationCacheEntry(AIG);
if (aig == null) {
final LinkedHashSet<Formula> nops = new LinkedHashSet<>(and.numberOfOperands());
for (final Formula op : and) {
nops.add(apply(op, cache));
}
aig = f.and(nops);
if (cache) {
and.setTransformationCacheEntry(AIG, aig);
aig.setPredicateCacheEntry(PredicateCacheEntry.IS_AIG, true);
}
}
return aig;
}
use of org.logicng.formulas.Formula in project LogicNG by logic-ng.
the class AIGTransformation method transformImplication.
private Formula transformImplication(final Implication impl) {
Formula aig = impl.transformationCacheEntry(AIG);
if (aig == null) {
aig = f.not(f.and(apply(impl.left(), cache), f.not(apply(impl.right(), cache))));
if (cache) {
impl.setTransformationCacheEntry(AIG, aig);
aig.setPredicateCacheEntry(PredicateCacheEntry.IS_AIG, true);
}
}
return aig;
}
use of org.logicng.formulas.Formula in project LogicNG by logic-ng.
the class AIGTransformation method transformNot.
private Formula transformNot(final Not not) {
Formula aig = not.transformationCacheEntry(AIG);
if (aig == null) {
aig = f.not(apply(not.operand(), cache));
if (cache) {
not.setTransformationCacheEntry(AIG, aig);
aig.setPredicateCacheEntry(PredicateCacheEntry.IS_AIG, true);
}
}
return aig;
}
Aggregations