本文整理汇总了Java中org.prop4j.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于org.prop4j包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: valid
import org.prop4j.Node; //导入依赖的package包/类
/**
* Checks that all manual and automatic selections are valid.
*
* @return
*/
public boolean valid() {
LinkedList<Node> children = new LinkedList<Node>();
for (SelectableFeature feature : features)
if (feature.getFeature() != null && feature.getFeature().isConcrete()) {
Literal literal = new Literal(feature.getName());
literal.positive = feature.getSelection() == Selection.SELECTED;
children.add(literal);
}
try {
return new SatSolver(rootNode, TIMEOUT).isSatisfiable(children);
} catch (TimeoutException e) {
FMCorePlugin.getDefault().logError(e);
}
return false;
}
示例2: nextExample
import org.prop4j.Node; //导入依赖的package包/类
public Configuration nextExample() throws TimeoutException {
if (exampleSolver == null) {
if (bSatisfiable.isEmpty() && !findSatisfiable(true))
return null;
Node child = bChildren[bSatisfiable.removeFirst()];
exampleSolver = new SatSolver(new And(a, new Not(child.clone())), 1000);
}
String solution = exampleSolver.getSolution();
if (solution.equals(lastSolution)) {
exampleSolver = null;
return nextExample();
}
Configuration configuration = new Configuration(fm, false);
ConfigurationReader reader = new ConfigurationReader(configuration);
reader.readFromString(solution);
lastSolution = solution;
return configuration;
}
示例3: findSatisfiable
import org.prop4j.Node; //导入依赖的package包/类
public boolean findSatisfiable(boolean stopEarly) throws TimeoutException {
boolean sat = false;
while (hasNextChild()) {
Node child = nextChild();
if (!(child instanceof Or))
child = new Or(child);
Node[] list = Node.clone(child.getChildren());
for (Node node : list)
((Literal) node).positive ^= true;
if (solver.isSatisfiable(list)) {
childIsSatisfiable();
if (stopEarly)
return true;
sat = true;
}
}
return sat;
}
示例4: createNodes
import org.prop4j.Node; //导入依赖的package包/类
public static Node createNodes(FeatureModel featureModel,
HashMap<Object, Node> replacingMap) {
Feature root = featureModel.getRoot();
LinkedList<Node> nodes = new LinkedList<Node>();
if (root != null) {
nodes.add(new Literal(getVariable(root, featureModel)));
// convert grammar rules into propositional formulas
createNodes(nodes, root, featureModel, true, replacingMap);
// add extra constraints
for (Node node : featureModel.getPropositionalNodes())
nodes.add(node.clone());
}
And and = new And(nodes);
and = (And) replaceAbstractVariables(and, replacingMap, false);
and = eliminateAbstractVariables(and, replacingMap, featureModel);
return and;
}
示例5: replaceAbstractVariables
import org.prop4j.Node; //导入依赖的package包/类
public static Node replaceAbstractVariables(Node node,
HashMap<Object, Node> map, boolean replaceNull) {
if (node == null)
return null;
if (node instanceof Literal) {
Literal literal = (Literal) node;
if (map.containsKey(literal.var)) {
Node replacing = map.get(literal.var);
if (replacing == null)
return replaceNull ? null : node;
replacing = replacing.clone();
node = literal.positive ? replacing : new Not(replacing);
}
} else {
Node[] children = node.getChildren();
for (int i = 0; i < children.length; i++) {
children[i] = replaceAbstractVariables(children[i], map,
replaceNull);
if (replaceNull && children[i] == null)
return null;
}
}
return node;
}
示例6: implies
import org.prop4j.Node; //导入依赖的package包/类
private boolean implies(Node a, Node b, ExampleCalculator example)
throws TimeoutException {
if (b == null)
return true;
if (!strategy.contains(Strategy.SingleTesting)) {
Node node = new And(a.clone(), new Not(b.clone()));
SatSolver solver = new SatSolver(node, timeout);
boolean valid = !solver.isSatisfiable();
return valid;
}
example.setLeft(a);
example.setRight(b);
return !example.findSatisfiable(strategy
.contains(Strategy.SingleTestingAborted));
}
示例7: clone
import org.prop4j.Node; //导入依赖的package包/类
@Override
public FeatureModel clone() {
FeatureModel fm = new FeatureModel();
fm.root = root.clone();
List<Feature> list = new LinkedList<Feature>();
list.add(fm.root);
while (!list.isEmpty()) {
Feature feature = list.remove(0);
fm.featureTable.put(feature.getName(), feature);
for (Feature child : feature.getChildren())
list.add(child);
}
fm.propNodes = new LinkedList<Node>();
for (Node node : propNodes) {
fm.propNodes.add(node);
fm.constraints.add(new Constraint(fm, node));
}
for (int i = 0; i < annotations.size(); i++)
fm.annotations.add(annotations.get(i));
for (int i = 0; i < comments.size(); i++)
fm.comments.add(comments.get(i));
return fm;
}
示例8: checkImplies
import org.prop4j.Node; //导入依赖的package包/类
/**
* checks whether A implies B for the current feature model.
*
* in detail the following condition should be checked whether
*
* FM => ((A1 and A2 and ... and An) => (B1 and B2 and ... and Bn))
*
* is true for all values
*
* @param A
* set of features that form a conjunction
* @param B
* set of features that form a conjunction
* @return
* @throws TimeoutException
*/
public boolean checkImplies(Set<Feature> a, Set<Feature> b)
throws TimeoutException {
if (b.isEmpty())
return true;
Node featureModel = NodeCreator.createNodes(this);
// B1 and B2 and ... Bn
Node condition = conjunct(b);
// (A1 and ... An) => (B1 and ... Bn)
if (!a.isEmpty())
condition = new Implies(conjunct(a), condition);
// FM => (A => B)
Implies finalFormula = new Implies(featureModel, condition);
return !new SatSolver(new Not(finalFormula), 1000).isSatisfiable();
}
示例9: mayBeMissing
import org.prop4j.Node; //导入依赖的package包/类
/**
* Checks whether there exists a set of features that is valid within the
* feature model and the given context, so that none of the given feature
* sets are present, i.e. evaluate to true.
*
* In detail it is checked whether there exists a set F of features so that
* eval(FM, F) AND eval(context, F) AND NOT(eval(featureSet_1, F)) AND ...
* AND NOT(eval(featureSet_n, F)) is true.
*
* If you want to check XOR(featureSet_1, ..., featureSet_n) you can call
* areMutualExclusive() && !mayBeMissing().
*
* @param context
* context in which everything is checked
* @param featureSets
* list of feature sets
*
* @return true, if there exists such a set of features, i.e. if the
* code-fragment may be missing || false, otherwise
* @throws TimeoutException
*/
public boolean mayBeMissing(Set<Feature> context,
List<Set<Feature>> featureSets) throws TimeoutException {
if ((featureSets == null) || featureSets.isEmpty())
return false;
Node featureModel = NodeCreator.createNodes(this);
LinkedList<Object> forAnd = new LinkedList<Object>();
for (Set<Feature> features : featureSets) {
if ((features != null) && !features.isEmpty())
forAnd.add(new Not(conjunct(features)));
else
return false;
}
Node condition = new And(forAnd);
if ((context != null) && !context.isEmpty())
condition = new And(conjunct(context), condition);
Node finalFormula = new And(featureModel, condition);
return new SatSolver(finalFormula, 1000).isSatisfiable();
}
示例10: readConsStmt
import org.prop4j.Node; //导入依赖的package包/类
private void readConsStmt(ConsStmt consStmt) throws UnsupportedModelException {
ESList eSList = consStmt.getESList();
AstListNode astListNode = (AstListNode) eSList.arg[0];
do {
line = 0;
Node node = exprToNode(((EStmt) astListNode.arg[0]).getExpr());
try {
if (!new SatSolver(new Not(node.clone()), 250).isSatisfiable())
warnings.add(new ModelWarning("Constraint is a tautology.", line));
if (!new SatSolver(node.clone(), 250).isSatisfiable())
warnings.add(new ModelWarning("Constraint is not satisfiable.", line));
} catch (Exception e) {
}
featureModel.addPropositionalNode(node);
astListNode = (AstListNode) astListNode.right;
} while (astListNode != null);
}
示例11: getFalseOptional
import org.prop4j.Node; //导入依赖的package包/类
private List<Feature> getFalseOptional(String input, FeatureModel model) {
List<Feature> list = new ArrayList<Feature>();
FeatureModel clonedModel = model.clone();
NodeReader nodeReader = new NodeReader();
Node propNode = nodeReader.stringToNode(input, clonedModel.getFeatureNames());
for (Feature feature : model.getFeatures()) {
if (input.contains(feature.getName())) {
//if (feature.getFeatureStatus() != FeatureStatus.FALSE_OPTIONAL) {
clonedModel.addPropositionalNode(propNode);
clonedModel.getAnalyser().analyzeFeatureModel(null);
if (clonedModel.getFeature(feature.getName()).getFeatureStatus() == FeatureStatus.FALSE_OPTIONAL && !list.contains(feature))
list.add(feature);
//}
}
}
return list;
}
示例12: voidsModel
import org.prop4j.Node; //导入依赖的package包/类
/**
* returns true if the constraint causes the feature model to be void
* otherwise false
*
* @param input
* constraint to be evaluated
* @param model
* the feature model
*
* * @throws TimeoutException
*/
private boolean voidsModel(final Constraint constraint, String input, FeatureModel model) throws TimeoutException {
if (!model.getAnalyser().isValid()) {
return false;
}
if (input.length() == 0) {
return false;
}
FeatureModel clonedModel = model.clone();
NodeReader nodeReader = new NodeReader();
Node propNode = nodeReader.stringToNode(input, clonedModel.getFeatureNames());
if (propNode != null) {
if (constraint != null) {
clonedModel.removeConstraint(constraint);
}
clonedModel.addPropositionalNode(propNode);
clonedModel.handleModelDataChanged();
}
return (!clonedModel.getAnalyser().isValid());
}
示例13: number
import org.prop4j.Node; //导入依赖的package包/类
public long number(long timeout) {
LinkedList<Node> children = new LinkedList<Node>();
for (SelectableFeature feature : features)
if (!feature.hasChildren()) {
if (feature.getSelection() == Selection.SELECTED)
children.add(new Literal(feature.getName(), true));
if (feature.getSelection() == Selection.UNSELECTED)
children.add(new Literal(feature.getName(), false));
}
Node node = new And(rootNode.clone(), new And(children));
return new SatSolver(node, timeout).countSolutions();
}
示例14: setRight
import org.prop4j.Node; //导入依赖的package包/类
public void setRight(Node b) {
b = b.clone().toCNF();
if (b instanceof Or)
b = new And(b);
bChildren = b.getChildren();
bSatisfiable = new LinkedList<Integer>();
bIndex = -1;
}
示例15: calculateNodesToReplace
import org.prop4j.Node; //导入依赖的package包/类
private static void calculateNodesToReplace(Node[] children,
String abstractFeature, List<Node> nochange, List<Node> change) {
for (Node node : children)
if (nodeContains(node, abstractFeature))
change.add(node);
else
nochange.add(node);
}