use of jkind.lustre.values.Value in project AGREE by loonwerks.
the class SymbolicValue method applyUnaryOp.
public SymbolicValue applyUnaryOp(final UnaryOp op) {
if (op == UnaryOp.NEGATIVE) {
final Value newSlope = coefficient == null ? null : coefficient.applyUnaryOp(op);
final Value newYIntercept = constant == null ? null : constant.applyUnaryOp(op);
return new SymbolicValue(newSlope, variable, newYIntercept);
} else if (op == UnaryOp.NOT) {
if (coefficient != null) {
return null;
}
return new SymbolicValue(null, null, constant.applyUnaryOp(op));
}
return null;
}
use of jkind.lustre.values.Value in project AGREE by loonwerks.
the class AgreeCounterexampleContentProvider method getElements.
@Override
public Object[] getElements(Object inputElement) {
Counterexample cex = (Counterexample) inputElement;
List<Object> result = new ArrayList<>();
boolean first = true;
for (String category : layout.getCategories()) {
List<Signal<Value>> signals = cex.getCategorySignals(layout, category);
if (!signals.isEmpty()) {
if (first) {
first = false;
} else {
result.add(new Spacer());
}
result.add(new CategoryHeader(category));
List<Signal<Value>> inputSignals = signals.stream().filter(it -> {
EObject ref = refMap.get(it.getName());
return (ref instanceof org.osate.aadl2.Port) && ((org.osate.aadl2.Port) ref).isIn();
}).collect(Collectors.toList());
List<Signal<Value>> outputSignals = signals.stream().filter(it -> {
EObject ref = refMap.get(it.getName());
return (ref instanceof org.osate.aadl2.Port) && ((org.osate.aadl2.Port) ref).isOut();
}).collect(Collectors.toList());
List<Signal<Value>> otherSignals = signals.stream().filter(it -> !(inputSignals.contains(it) || outputSignals.contains(it))).collect(Collectors.toList());
result.addAll(SignalGrouper.group(null, Stream.of(inputSignals, otherSignals, outputSignals).flatMap(Collection::stream).collect(Collectors.toList())));
}
}
return result.toArray();
}
use of jkind.lustre.values.Value in project AGREE by loonwerks.
the class AgreeMenuListener method viewCexConsole.
private void viewCexConsole(final Counterexample cex, final Layout layout, Map<String, EObject> refMap, final AgreeRenaming renaming) {
final MessageConsole console = findConsole("Counterexample");
showConsole(console);
console.clearConsole();
console.addPatternMatchListener(new AgreePatternListener(refMap));
/*
* From the Eclipse API: "Clients should avoid writing large amounts of
* output to this stream in the UI thread. The console needs to process
* the output in the UI thread and if the client hogs the UI thread
* writing output to the console, the console will not be able to
* process the output."
*/
new Thread(() -> {
try (MessageConsoleStream out = console.newMessageStream()) {
for (String category : layout.getCategories()) {
if (isEmpty(category, cex, layout)) {
continue;
}
printHLine(out, cex.getLength());
if (category == "") {
out.println("Variables for the selected component implementation");
} else {
out.println("Variables for " + category);
}
printHLine(out, cex.getLength());
out.print(String.format("%-60s", "Variable Name"));
for (int k1 = 0; k1 < cex.getLength(); k1++) {
out.print(String.format("%-15s", k1));
}
out.println();
printHLine(out, cex.getLength());
List<Signal<Value>> inputSignals = new ArrayList<>();
List<Signal<Value>> outputSignals = new ArrayList<>();
List<Signal<Value>> stateSignals = new ArrayList<>();
for (Signal<Value> signal : cex.getCategorySignals(layout, category)) {
// dont' print out values for properties
if (signal.getName().contains(":")) {
continue;
}
String signalName = signal.getName();
EObject ref = renaming.findBestReference(signalName);
boolean isInput = (ref instanceof org.osate.aadl2.Port) ? ((org.osate.aadl2.Port) ref).isIn() : false;
boolean isOutput = (ref instanceof org.osate.aadl2.Port) ? ((org.osate.aadl2.Port) ref).isOut() : false;
if (isInput) {
inputSignals.add(signal);
} else if (isOutput) {
outputSignals.add(signal);
} else {
stateSignals.add(signal);
}
}
out.println("Inputs:");
inputSignals.forEach(it -> printSignal(out, it, cex.getLength()));
out.println("State:");
stateSignals.forEach(it -> printSignal(out, it, cex.getLength()));
out.println("Outputs:");
outputSignals.forEach(it -> printSignal(out, it, cex.getLength()));
out.println();
}
printHLine(out, cex.getLength());
// print uninterpreted functions using Jkind CounterexampleFormatter
AgreeUninterpretedFunctionFormatter uFcnFormatter = new AgreeUninterpretedFunctionFormatter(cex);
out.println(uFcnFormatter.functions());
} catch (IOException e) {
e.printStackTrace();
}
}).start();
}
use of jkind.lustre.values.Value in project AGREE by loonwerks.
the class FrameAssertionHelper method valueToExpr.
private static Expr valueToExpr(final Value value) {
assert value != null;
if (value instanceof ArrayValue) {
final ArrayValue arrayValue = (ArrayValue) value;
final ArrayList<Expr> exprList = new ArrayList<Expr>(arrayValue.elements.size());
for (final Value childValue : arrayValue.elements) {
exprList.add(valueToExpr(childValue));
}
return new ArrayExpr(exprList);
} else if (value instanceof BooleanValue) {
return new BoolExpr(((BooleanValue) value).value);
} else if (value instanceof EnumValue) {
return new IdExpr(((EnumValue) value).value);
} else if (value instanceof IntegerValue) {
return new IntExpr(((IntegerValue) value).value);
} else if (value instanceof RealValue) {
final BigFraction fraction = ((RealValue) value).value;
return new BinaryExpr(new RealExpr(new BigDecimal(fraction.getNumerator())), BinaryOp.DIVIDE, new RealExpr(new BigDecimal(fraction.getDenominator())));
}
if (value instanceof TupleValue) {
final TupleValue tupleValue = (TupleValue) value;
final ArrayList<Expr> exprList = new ArrayList<Expr>(tupleValue.elements.size());
for (final Value childValue : tupleValue.elements) {
exprList.add(valueToExpr(childValue));
}
return new TupleExpr(exprList);
} else {
throw new RuntimeException("Unhandled case. Value is of type: " + value.getClass());
}
}
use of jkind.lustre.values.Value in project AGREE by loonwerks.
the class SimulationFrameResults method eval.
private Value eval(final Expr lustreExpr) {
if (lustreExpr instanceof BoolExpr) {
return BooleanValue.fromBoolean(((BoolExpr) lustreExpr).value);
} else if (lustreExpr instanceof IntExpr) {
return new IntegerValue(((IntExpr) lustreExpr).value);
} else if (lustreExpr instanceof RealExpr) {
final RealExpr realExpr = (RealExpr) lustreExpr;
return new RealValue(BigFraction.valueOf(realExpr.value));
} else if (lustreExpr instanceof BinaryExpr) {
final BinaryExpr binaryExpr = (BinaryExpr) lustreExpr;
final Value leftValue = eval(binaryExpr.left);
final Value rightValue = eval(binaryExpr.right);
if (leftValue == null || rightValue == null) {
return null;
}
return leftValue.applyBinaryOp(binaryExpr.op, rightValue);
} else if (lustreExpr instanceof UnaryExpr) {
final UnaryExpr unaryExpr = (UnaryExpr) lustreExpr;
final Value operandValue = eval(unaryExpr.expr);
if (operandValue == null) {
return null;
}
return operandValue.applyUnaryOp(unaryExpr.op);
}
return null;
}
Aggregations