Search in sources :

Example 1 with RealValue

use of jkind.lustre.values.RealValue 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>");
}
Also used : RealValue(jkind.lustre.values.RealValue) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) IntegerValue(jkind.lustre.values.IntegerValue) BooleanValue(jkind.lustre.values.BooleanValue) RealValue(jkind.lustre.values.RealValue) IntegerValue(jkind.lustre.values.IntegerValue) Value(jkind.lustre.values.Value) BooleanValue(jkind.lustre.values.BooleanValue) Map(java.util.Map) TcgException(com.rockwellcollins.atc.tcg.TcgException)

Example 2 with RealValue

use of jkind.lustre.values.RealValue in project AGREE by loonwerks.

the class Main method testReal.

private static void testReal() throws IOException {
    System.out.println("=============Real Test=============");
    final Evaluator baseEvaluator = createEvaluator(INPUT_DIRECTORY + "symb_test_real.lus");
    final Evaluator evaluator = new Evaluator(baseEvaluator, Arrays.asList(new BinaryExpr(new IdExpr("__SIM_PE___ASSUME0"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE___ASSUME1"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE__TOP__ss__TILDE__0__DOT____GUARANTEE0"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE__TOP__ss__TILDE__0__DOT____GUARANTEE1"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("in1"), BinaryOp.EQUAL, new RealExpr(BigDecimal.valueOf(60))), new BinaryExpr(new IdExpr("in2"), BinaryOp.EQUAL, new RealExpr(BigDecimal.valueOf(10)))));
    testValue("in1", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(60))));
    testValue("in2", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(10))));
    testValue("out1", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(30))));
    testValue("out2", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(20))));
}
Also used : RealValue(jkind.lustre.values.RealValue) BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Evaluator(edu.uah.rsesc.aadlsimulator.agree.eval.Evaluator) RealExpr(jkind.lustre.RealExpr)

Example 3 with RealValue

use of jkind.lustre.values.RealValue 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());
    }
}
Also used : RealValue(jkind.lustre.values.RealValue) BigFraction(jkind.util.BigFraction) BinaryExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BinaryExpression) BooleanLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral) BooleanValue(jkind.lustre.values.BooleanValue) IntegerValue(jkind.lustre.values.IntegerValue) IntegerLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntegerLiteral)

Example 4 with RealValue

use of jkind.lustre.values.RealValue in project AGREE by loonwerks.

the class AGREESimulationState method getConstantLustreValue.

// Returns the raw value stored in the counterexample provided by JKind
public Value getConstantLustreValue(final int frameIndex, final Object constant) {
    if (frameIndex < 0 || frameIndex > frameInfos.size()) {
        throw new IllegalArgumentException("frameIndex is outside the valid range");
    }
    final ConstStatement constStatement = asConstant(constant);
    final com.rockwellcollins.atc.agree.agree.Expr agreeExpr = constStatement.getExpr();
    if (agreeExpr instanceof IntLitExpr) {
        return new IntegerValue(new BigInteger(((IntLitExpr) agreeExpr).getVal(), 10));
    } else if (agreeExpr instanceof RealLitExpr) {
        BigDecimal bd = new BigDecimal(((RealLitExpr) agreeExpr).getVal());
        if (bd.scale() < 0) {
            bd = bd.setScale(0);
        }
        return new RealValue(new BigFraction(bd.unscaledValue(), BigInteger.TEN.pow(bd.scale())));
    } else if (agreeExpr instanceof BoolLitExpr) {
        return BooleanValue.fromBoolean(((BoolLitExpr) agreeExpr).getVal().getValue());
    } else {
        return null;
    }
}
Also used : RealValue(jkind.lustre.values.RealValue) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) BigFraction(jkind.util.BigFraction) IntegerValue(jkind.lustre.values.IntegerValue) BigDecimal(java.math.BigDecimal) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) BigInteger(java.math.BigInteger) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr)

Example 5 with RealValue

use of jkind.lustre.values.RealValue 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());
    }
}
Also used : RealValue(jkind.lustre.values.RealValue) BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BigFraction(jkind.util.BigFraction) EnumValue(jkind.lustre.values.EnumValue) IntegerValue(jkind.lustre.values.IntegerValue) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) TupleValue(jkind.lustre.values.TupleValue) TupleExpr(jkind.lustre.TupleExpr) ArrayExpr(jkind.lustre.ArrayExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) TupleExpr(jkind.lustre.TupleExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) BooleanValue(jkind.lustre.values.BooleanValue) RealValue(jkind.lustre.values.RealValue) TupleValue(jkind.lustre.values.TupleValue) Value(jkind.lustre.values.Value) EnumValue(jkind.lustre.values.EnumValue) ArrayValue(jkind.lustre.values.ArrayValue) BooleanValue(jkind.lustre.values.BooleanValue) IntegerValue(jkind.lustre.values.IntegerValue) IntExpr(jkind.lustre.IntExpr) ArrayValue(jkind.lustre.values.ArrayValue) RealExpr(jkind.lustre.RealExpr)

Aggregations

RealValue (jkind.lustre.values.RealValue)8 IntegerValue (jkind.lustre.values.IntegerValue)7 BooleanValue (jkind.lustre.values.BooleanValue)6 Value (jkind.lustre.values.Value)5 BinaryExpr (jkind.lustre.BinaryExpr)4 BoolExpr (jkind.lustre.BoolExpr)4 RealExpr (jkind.lustre.RealExpr)4 BigFraction (jkind.util.BigFraction)4 IntExpr (jkind.lustre.IntExpr)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 IdExpr (jkind.lustre.IdExpr)2 UnaryExpr (jkind.lustre.UnaryExpr)2 ArrayValue (jkind.lustre.values.ArrayValue)2 EnumValue (jkind.lustre.values.EnumValue)2 TupleValue (jkind.lustre.values.TupleValue)2 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)1 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)1 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)1