nl.uu.cs.ape.models.sltlxStruc.SLTLxConjunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of APE Show documentation
Show all versions of APE Show documentation
APE is a command line tool and an API for the automated exploration of possible computational pipelines (workflows) from large collections of computational tools.
The newest version!
package nl.uu.cs.ape.models.sltlxStruc;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import nl.uu.cs.ape.solver.minisat.SATSynthesisEngine;
/**
* Structure used to model conjunction of terms in SLTLx.
*
* @author Vedran Kasalica
*
*/
public class SLTLxConjunction extends SLTLxFormula {
private Set conjunctedFacts;
public SLTLxConjunction(SLTLxFormula arg1, SLTLxFormula arg2) {
super();
this.conjunctedFacts = new HashSet<>();
if (arg1 != null)
this.conjunctedFacts.add(arg1);
if (arg2 != null)
this.conjunctedFacts.add(arg2);
}
public SLTLxConjunction(SLTLxFormula arg1, SLTLxFormula arg2, SLTLxFormula arg3) {
super();
this.conjunctedFacts = new HashSet<>();
if (arg1 != null)
this.conjunctedFacts.add(arg1);
if (arg2 != null)
this.conjunctedFacts.add(arg2);
if (arg3 != null)
this.conjunctedFacts.add(arg3);
}
public SLTLxConjunction(Collection extends SLTLxFormula> conjunctedFacts) {
super();
this.conjunctedFacts = new HashSet<>();
conjunctedFacts.forEach(fact -> {
if (fact != null)
this.conjunctedFacts.add(fact);
});
}
@Override
public Set getCNFEncoding(int stateNo, SLTLxVariableSubstitutionCollection variableMapping,
SATSynthesisEngine synthesisEngine) {
/* Implement conjunction over an empty set rule. */
if (conjunctedFacts.isEmpty()) {
return SLTLxAtom.getTrue().getCNFEncoding(stateNo, variableMapping, synthesisEngine);
}
Set> allClauses = new HashSet<>();
/*
* Conjunct the collection of clauses that encode each of the conjuncted
* elements.
*/
for (SLTLxFormula formula : conjunctedFacts) {
allClauses.add(formula.getCNFEncoding(stateNo, variableMapping, synthesisEngine));
}
return CNFClause.conjunctClausesCollection(allClauses);
}
@Override
public Set getNegatedCNFEncoding(int stateNo, SLTLxVariableSubstitutionCollection variableMapping,
SATSynthesisEngine synthesisEngine) {
/* Implement conjunction over an empty set rule. */
if (conjunctedFacts.isEmpty()) {
return SLTLxAtom.getFalse().getCNFEncoding(stateNo, variableMapping, synthesisEngine);
}
Set> allClauses = new HashSet<>();
/*
* Disjoint the collection of clauses that encode negatioNs of each of the
* disjoint elements.
*/
for (SLTLxFormula formula : conjunctedFacts) {
allClauses.add(formula.getNegatedCNFEncoding(stateNo, variableMapping, synthesisEngine));
}
return CNFClause.disjoinClausesCollection(allClauses);
}
}