use of org.logicng.formulas.Literal in project feature-diagram by MontiCore.
the class FD2Formula method visit.
@Override
public void visit(ASTXorGroup node) {
Set<String> xorGroup = getFeatures(node);
Set<Literal> G = xorGroup.stream().map(this::Var).collect(Collectors.toSet());
Formula min1 = ff.or(G);
Formula max1 = ff.and(Sets.combinations(G, 2).stream().map(ff::and).map(ff::not).collect(Collectors.toList()));
formulas.add(ff.implication(Var(current), ff.and(min1, max1)));
}
use of org.logicng.formulas.Literal in project ITSTools by lip6.
the class GalToLogicNG method toGal.
private BooleanExpression toGal(Formula f) {
if (f instanceof Variable) {
Variable v = (Variable) f;
return EcoreUtil.copy(map.get(v.name()));
} else if (f instanceof org.logicng.formulas.Or) {
org.logicng.formulas.Or or = (org.logicng.formulas.Or) f;
BooleanExpression res = GalFactory.eINSTANCE.createFalse();
for (Formula elt : or) {
res = GF2.or(res, toGal(elt));
}
return res;
} else if (f instanceof org.logicng.formulas.And) {
org.logicng.formulas.And and = (org.logicng.formulas.And) f;
BooleanExpression res = GalFactory.eINSTANCE.createTrue();
for (Formula elt : and) {
res = GF2.and(res, toGal(elt));
}
return res;
} else if (f instanceof Literal) {
Literal l = (Literal) f;
return GF2.not(toGal(l.variable()));
} else if (f instanceof org.logicng.formulas.Not) {
org.logicng.formulas.Not l = (org.logicng.formulas.Not) f;
return GF2.not(toGal(l.operand()));
} else if (f instanceof CFalse) {
return GalFactory.eINSTANCE.createFalse();
} else if (f instanceof CTrue) {
return GalFactory.eINSTANCE.createTrue();
} else {
System.out.println("error");
}
return null;
}
use of org.logicng.formulas.Literal in project ITSTools by lip6.
the class ToLogicNG method toLogic.
private BooleanExpression toLogic(Formula f) {
if (f instanceof Variable) {
Variable v = (Variable) f;
return EcoreUtil.copy(map.get(v.name()));
} else if (f instanceof org.logicng.formulas.Or) {
org.logicng.formulas.Or or = (org.logicng.formulas.Or) f;
Or oc = LogicFactory.eINSTANCE.createOr();
oc.setLeft(LogicFactory.eINSTANCE.createFalse());
for (Formula elt : or) {
oc.setRight(toLogic(elt));
Or oc2 = LogicFactory.eINSTANCE.createOr();
oc2.setLeft(oc);
oc = oc2;
}
return oc.getLeft();
} else if (f instanceof org.logicng.formulas.And) {
org.logicng.formulas.And or = (org.logicng.formulas.And) f;
And oc = LogicFactory.eINSTANCE.createAnd();
oc.setLeft(LogicFactory.eINSTANCE.createTrue());
for (Formula elt : or) {
oc.setRight(toLogic(elt));
And oc2 = LogicFactory.eINSTANCE.createAnd();
oc2.setLeft(oc);
oc = oc2;
}
return oc.getLeft();
} else if (f instanceof Literal) {
Literal l = (Literal) f;
Not n = LogicFactory.eINSTANCE.createNot();
n.setValue(toLogic(l.variable()));
return n;
} else if (f instanceof org.logicng.formulas.Not) {
org.logicng.formulas.Not l = (org.logicng.formulas.Not) f;
Not n = LogicFactory.eINSTANCE.createNot();
n.setValue(toLogic(l.operand()));
return n;
} else if (f instanceof CFalse) {
return LogicFactory.eINSTANCE.createFalse();
} else if (f instanceof CTrue) {
return LogicFactory.eINSTANCE.createTrue();
} else {
System.out.println("error");
}
return null;
}
use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class FormulaStringRepresentation method toInnerString.
/**
* Returns the string representation of the given formula.
* <p>
* This method is used for recursive calls in order to format the sub-formulas.
* @param formula the formula
* @return the string representation of the formula
*/
protected String toInnerString(final Formula formula) {
switch(formula.type()) {
case FALSE:
return this.falsum();
case TRUE:
return this.verum();
case LITERAL:
final Literal lit = (Literal) formula;
return lit.phase() ? lit.name() : this.negation() + lit.name();
case NOT:
final Not not = (Not) formula;
return this.negation() + this.bracket(not.operand());
case IMPL:
case EQUIV:
final BinaryOperator binary = (BinaryOperator) formula;
String op = formula.type() == FType.IMPL ? this.implication() : this.equivalence();
return this.binaryOperator(binary, op);
case AND:
case OR:
final NAryOperator nary = (NAryOperator) formula;
op = formula.type() == FType.AND ? this.and() : this.or();
return this.naryOperator(nary, String.format("%s", op));
case PBC:
final PBConstraint pbc = (PBConstraint) formula;
return String.format("%s%s%d", this.pbLhs(pbc.operands(), pbc.coefficients()), this.pbComparator(pbc.comparator()), pbc.rhs());
default:
throw new IllegalArgumentException("Cannot print the unknown formula type " + formula.type());
}
}
use of org.logicng.formulas.Literal in project LogicNG by logic-ng.
the class SortedStringRepresentation method toInnerString.
/**
* Returns the sorted string representation of the given formula.
* @param formula the formula
* @return the sorted string representation of the formula with regard to the variable ordering
*/
@Override
public String toInnerString(final Formula formula) {
switch(formula.type()) {
case FALSE:
return falsum();
case TRUE:
return verum();
case LITERAL:
final Literal lit = (Literal) formula;
return lit.phase() ? lit.name() : negation() + lit.name();
case NOT:
final Not not = (Not) formula;
return negation() + bracket(not.operand());
case IMPL:
return binaryOperator((BinaryOperator) formula, implication());
case EQUIV:
return sortedEquivalence((Equivalence) formula);
case AND:
case OR:
final NAryOperator nary = (NAryOperator) formula;
final String op = formula.type() == FType.AND ? and() : or();
return naryOperator(nary, String.format("%s", op));
case PBC:
final PBConstraint pbc = (PBConstraint) formula;
return String.format("%s%s%d", pbLhs(pbc.operands(), pbc.coefficients()), pbComparator(pbc.comparator()), pbc.rhs());
default:
throw new IllegalArgumentException("Cannot print the unknown formula type " + formula.type());
}
}
Aggregations