use of jkind.lustre.values.IntegerValue in project AGREE by loonwerks.
the class AGREESimulationState method convertLustreValue.
/**
* Converts a JKind API Lustre value to types that are independent of the JKind API. In cases where there isn't an equivalent type in the standard
* Java API, the original type will be preserved. Throws an
* @param value non-null value object.
* @throws RuntimeException if the value is not of a supported type.
* @return
*/
private Object convertLustreValue(final Value value) {
assert value != null;
if (value instanceof ArrayValue) {
final ArrayValue arrayValue = (ArrayValue) value;
final ArrayList<Object> newList = new ArrayList<Object>(arrayValue.elements.size());
for (final Value childValue : arrayValue.elements) {
newList.add(convertLustreValue(childValue));
}
return newList;
} else if (value instanceof BooleanValue) {
return ((BooleanValue) value).value;
} else if (value instanceof EnumValue) {
return ((EnumValue) value).value;
} else if (value instanceof IntegerValue) {
return ((IntegerValue) value).value;
} else if (value instanceof RealValue) {
final BigFraction fraction = ((RealValue) value).value;
return new Rational(fraction.getNumerator(), fraction.getDenominator());
} else if (value instanceof RecordValue) {
final RecordValue recordValue = (RecordValue) value;
final Map<String, Object> newMap = new HashMap<String, Object>();
for (final Entry<String, Value> entry : recordValue.fields.entrySet()) {
newMap.put(entry.getKey(), convertLustreValue(entry.getValue()));
}
return newMap;
} else if (value instanceof TupleValue) {
final TupleValue tupleValue = (TupleValue) value;
final ArrayList<Object> newList = new ArrayList<Object>(tupleValue.elements.size());
for (final Value childValue : tupleValue.elements) {
newList.add(convertLustreValue(childValue));
}
return newList;
} else {
throw new RuntimeException("Unhandled case. Value is of type: " + value.getClass());
}
}
use of jkind.lustre.values.IntegerValue in project AGREE by loonwerks.
the class InputConstraintToLustreValueExpression method lustreExprToValue.
// Only binary, unary, and literal expressions are supported
private static Value lustreExprToValue(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 = lustreExprToValue(binaryExpr.left);
final Value rightValue = lustreExprToValue(binaryExpr.right);
return leftValue.applyBinaryOp(binaryExpr.op, rightValue);
} else if (lustreExpr instanceof UnaryExpr) {
final UnaryExpr unaryExpr = (UnaryExpr) lustreExpr;
final Value operandValue = lustreExprToValue(unaryExpr.expr);
return operandValue.applyUnaryOp(unaryExpr.op);
}
throw new RuntimeException("Unsupported expression: " + lustreExpr);
}
use of jkind.lustre.values.IntegerValue in project AGREE by loonwerks.
the class Main method testInteger.
private static void testInteger() throws IOException {
System.out.println("=============Integer Test=============");
final Evaluator baseEvaluator = createEvaluator(INPUT_DIRECTORY + "symb_test_int.lus");
final Evaluator evaluator = new Evaluator(baseEvaluator, Arrays.asList(new BinaryExpr(new IdExpr("in1"), BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(-10))), new BinaryExpr(new IdExpr("in2"), BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(10)))));
testValue("in1", evaluator, new IntegerValue(BigInteger.valueOf(-10)));
testValue("in2", evaluator, new IntegerValue(BigInteger.valueOf(10)));
testValue("out1", evaluator, new IntegerValue(BigInteger.valueOf(-5)));
testValue("out2", evaluator, new IntegerValue(BigInteger.valueOf(-15)));
testValue("ss__a1[0]", evaluator, new IntegerValue(BigInteger.valueOf(-5)));
testValue("ss__a1[1]", evaluator, new IntegerValue(BigInteger.valueOf(-5)));
testValue("ss__a1[2]", evaluator, new IntegerValue(BigInteger.valueOf(-20)));
testValue("ss__a2[0]", evaluator, new IntegerValue(BigInteger.valueOf(10)));
testValue("ss__a2[1]", evaluator, new IntegerValue(BigInteger.valueOf(20)));
testValue("ss__a2[2]", evaluator, new IntegerValue(BigInteger.valueOf(30)));
testValue("ss__a3[0]", evaluator, new IntegerValue(BigInteger.valueOf(42)));
testValue("ss__a3[1]", evaluator, new IntegerValue(BigInteger.valueOf(88)));
testValue("ss__a3[2]", evaluator, new IntegerValue(BigInteger.valueOf(-20)));
testValue("ss__r1.x", evaluator, new IntegerValue(BigInteger.valueOf(-5)));
testValue("ss__r1.y", evaluator, new IntegerValue(BigInteger.valueOf(-5)));
testValue("ss__r1.z", evaluator, new IntegerValue(BigInteger.valueOf(42)));
testValue("ss__r2.x", evaluator, new IntegerValue(BigInteger.valueOf(10)));
testValue("ss__r2.y", evaluator, new IntegerValue(BigInteger.valueOf(20)));
testValue("ss__r2.z", evaluator, new IntegerValue(BigInteger.valueOf(30)));
testValue("ss__r3.x", evaluator, new IntegerValue(BigInteger.valueOf(42)));
testValue("ss__r3.y", evaluator, new IntegerValue(BigInteger.valueOf(88)));
testValue("ss__r3.z", evaluator, new IntegerValue(BigInteger.valueOf(42)));
testValue("ss__ra1[0].x", evaluator, new IntegerValue(BigInteger.valueOf(-5)));
testValue("ss__ra1[0].y", evaluator, new IntegerValue(BigInteger.valueOf(-5)));
testValue("ss__ra1[0].z", evaluator, new IntegerValue(BigInteger.valueOf(42)));
testValue("ss__ra1[1].x", evaluator, new IntegerValue(BigInteger.valueOf(10)));
testValue("ss__ra1[1].y", evaluator, new IntegerValue(BigInteger.valueOf(20)));
testValue("ss__ra1[1].z", evaluator, new IntegerValue(BigInteger.valueOf(30)));
}
Aggregations