use of jkind.lustre.values.BooleanValue in project AGREE by loonwerks.
the class TcgXmlWriter method writeSignal.
private void writeSignal(int k, Signal<Value> signal) throws Exception {
String name = escapeXml(signal.getName());
// TODO: fix this with the type map!
Type type;
if (signal.getValues().isEmpty()) {
throw new TcgException("Unable to assertain signal type in XmlWriter");
} else {
Map.Entry<Integer, Value> entry = signal.getValues().entrySet().iterator().next();
Value v = entry.getValue();
if (v instanceof IntegerValue) {
type = NamedType.INT;
} else if (v instanceof RealValue) {
type = NamedType.REAL;
} else if (v instanceof BooleanValue) {
type = NamedType.BOOL;
} else {
throw new TcgException("Unexpected signal type in XmlWriter");
}
}
out.println(" <Signal name=\"" + name + "\" type=\"" + type + "\">");
for (int i = 0; i < k; i++) {
out.println(" <Value time=\"" + i + "\">" + formatValue(signal.getValue(i)) + "</Value>");
}
out.println(" </Signal>");
}
use of jkind.lustre.values.BooleanValue in project AGREE by loonwerks.
the class CounterexampleLoaderHelper method lustreValueToInputConstraint.
private InputConstraint lustreValueToInputConstraint(final Value value) {
if (value instanceof BooleanValue) {
final BooleanLiteral ic = InputConstraintFactory.eINSTANCE.createBooleanLiteral();
ic.setValue(((BooleanValue) value).value);
return ic;
} else if (value instanceof IntegerValue) {
final IntegerLiteral ic = InputConstraintFactory.eINSTANCE.createIntegerLiteral();
ic.setValue(((IntegerValue) value).value);
return ic;
} else if (value instanceof RealValue) {
final BigFraction fraction = ((RealValue) value).value;
final BinaryExpression ic = ExpressionFactory.createFraction(fraction.getNumerator(), fraction.getDenominator());
return ic;
} else {
throw new RuntimeException("Unsupported value type: " + value.getClass());
}
}
use of jkind.lustre.values.BooleanValue in project AGREE by loonwerks.
the class SymbolicValue method applyBinaryOp.
public SymbolicValue applyBinaryOp(final BinaryOp op, SymbolicValue value) {
final Value newCoefficient;
final Variable newVariable;
final Value newConstant;
if (op == BinaryOp.EQUAL) {
// Equality comparison is only supported when the variables are the same
if (variable == value.variable) {
boolean equal = Objects.equals(coefficient, value.coefficient) && Objects.equals(variable, value.variable) && Objects.equals(constant, value.constant);
return new SymbolicValue(null, null, equal ? BooleanValue.TRUE : BooleanValue.FALSE);
} else {
return null;
}
} else if (op == BinaryOp.LESS || op == BinaryOp.LESSEQUAL || op == BinaryOp.GREATER || op == BinaryOp.GREATEREQUAL) {
// Comparison operators are only supported when the symbolic value are constant values
if (variable == null && value.variable == null && constant != null && value.constant != null) {
final Value result = constant.applyBinaryOp(op, value.constant);
if (result instanceof BooleanValue) {
return new SymbolicValue(null, null, (BooleanValue) result);
}
}
return null;
} else if (op == BinaryOp.PLUS || op == BinaryOp.MINUS) {
if (variable == null && value.variable == null) {
newCoefficient = null;
newVariable = null;
} else if (variable != null && value.variable != null) {
if (variable == value.variable) {
newCoefficient = coefficient.applyBinaryOp(op, value.coefficient);
newVariable = variable;
} else {
// Unsupported
return null;
}
} else {
if (variable == null) {
// value.variable != null
if (op == BinaryOp.PLUS) {
newCoefficient = value.coefficient;
} else {
newCoefficient = value.coefficient.applyUnaryOp(UnaryOp.NEGATIVE);
}
newVariable = value.variable;
} else {
newCoefficient = coefficient;
newVariable = variable;
}
}
if (constant == null && value.constant == null) {
newConstant = null;
} else if (constant != null && value.constant != null) {
newConstant = constant.applyBinaryOp(op, value.constant);
} else {
if (constant == null) {
// value.constant != null
if (op == BinaryOp.PLUS) {
newConstant = value.constant;
} else {
newConstant = value.constant.applyUnaryOp(UnaryOp.NEGATIVE);
}
} else {
newConstant = constant;
}
}
} else if (op == BinaryOp.MULTIPLY || op == BinaryOp.DIVIDE) {
if (variable == null && value.variable == null) {
newCoefficient = null;
newVariable = null;
} else if (variable != null && value.variable != null) {
// At most one may have a variable id
return null;
} else {
if (variable == null) {
// value.variable != null
newCoefficient = value.coefficient.applyBinaryOp(op, constant);
newVariable = value.variable;
} else {
newCoefficient = coefficient.applyBinaryOp(op, value.constant);
newVariable = variable;
}
}
// Since multiplying values which both contain coefficients are not allowed, at least one value must have a constant
if (constant != null && value.constant != null) {
newConstant = constant.applyBinaryOp(op, value.constant);
} else {
newConstant = null;
}
} else if (op == BinaryOp.AND) {
if (variable == null && value.variable == null) {
newCoefficient = null;
newVariable = null;
newConstant = constant.applyBinaryOp(op, value.constant);
} else if (variable != null && value.variable != null) {
if (variable == value.variable && coefficient.equals(value.coefficient)) {
newCoefficient = coefficient;
newVariable = variable;
newConstant = null;
} else {
// Unsupported
return null;
}
} else {
if (variable == null) {
// value.variable != null
if (constant == BooleanValue.TRUE) {
newCoefficient = value.coefficient;
newVariable = value.variable;
newConstant = null;
} else {
newCoefficient = null;
newVariable = null;
newConstant = BooleanValue.FALSE;
}
} else {
if (value.constant == BooleanValue.TRUE) {
newCoefficient = coefficient;
newVariable = variable;
newConstant = null;
} else {
newCoefficient = null;
newVariable = null;
newConstant = BooleanValue.FALSE;
}
}
}
} else if (op == BinaryOp.OR) {
if (variable == null && value.variable == null) {
newCoefficient = null;
newVariable = null;
newConstant = constant.applyBinaryOp(op, value.constant);
} else if (variable != null && value.variable != null) {
if (variable == value.variable && coefficient.equals(value.coefficient)) {
newCoefficient = coefficient;
newVariable = variable;
newConstant = null;
} else {
// Unsupported
return null;
}
} else {
if (variable == null) {
// value.variable != null
if (constant == BooleanValue.TRUE) {
newCoefficient = null;
newVariable = null;
newConstant = BooleanValue.TRUE;
} else {
newCoefficient = value.coefficient;
newVariable = value.variable;
newConstant = null;
}
} else {
if (value.constant == BooleanValue.TRUE) {
newCoefficient = null;
newVariable = null;
newConstant = BooleanValue.TRUE;
} else {
newCoefficient = coefficient;
newVariable = variable;
newConstant = null;
}
}
}
} else {
return null;
}
// This will occur if unsupported operations are performed on the coefficient.
if ((newCoefficient == null) != (newVariable == null)) {
return null;
}
return new SymbolicValue(newCoefficient, newVariable, newConstant);
}
use of jkind.lustre.values.BooleanValue 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.BooleanValue in project AGREE by loonwerks.
the class AGREESimulationState method getPropertyStatus.
@Override
public AGREEPropertyStatus getPropertyStatus(final Object property) {
if (frameInfos.size() == 0) {
return AGREEPropertyStatus.INITIAL_STEP;
}
// Handle care where counterexample is not returned. Simulation is halted.
final SimulationFrameResults frameResults = frameInfos.get(frameInfos.size() - 1).getFrameResults();
if (frameResults.getDisabledProperties().contains(property)) {
return AGREEPropertyStatus.DISABLED;
}
if (frameResults.hasCounterexample()) {
for (final String propLustreId : asProperty(property).getLustreIds()) {
final Value value = frameResults.getValue(propLustreId);
if (!(value instanceof BooleanValue)) {
throw new RuntimeException("Value is not a boolean value");
}
final boolean propertyValue = ((BooleanValue) value).value;
if (!propertyValue) {
return AGREEPropertyStatus.UNSATISFIED_WARNING;
}
}
return AGREEPropertyStatus.SATISFIED;
} else {
if (frameResults.hasInductiveValidityCore()) {
for (final String propLustreId : asProperty(property).getLustreIds()) {
if (frameResults.isInInductiveValidityCore(propLustreId)) {
return AGREEPropertyStatus.UNSATISFIED_ERROR;
}
}
return AGREEPropertyStatus.HALTED_NOT_IN_SET_OF_SUPPORT;
} else {
return AGREEPropertyStatus.HALTED_SET_OF_SUPPORT_UNAVAILABLE;
}
}
}
Aggregations