Search in sources :

Example 11 with Value

use of jkind.lustre.values.Value 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;
        }
    }
}
Also used : SimulationFrameResults(edu.uah.rsesc.aadlsimulator.agree.sim.SimulationFrameResults) BooleanValue(jkind.lustre.values.BooleanValue) TupleValue(jkind.lustre.values.TupleValue) IntegerValue(jkind.lustre.values.IntegerValue) BooleanValue(jkind.lustre.values.BooleanValue) RealValue(jkind.lustre.values.RealValue) RecordValue(jkind.lustre.values.RecordValue) Value(jkind.lustre.values.Value) EnumValue(jkind.lustre.values.EnumValue) ArrayValue(jkind.lustre.values.ArrayValue)

Example 12 with Value

use of jkind.lustre.values.Value 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());
    }
}
Also used : RealValue(jkind.lustre.values.RealValue) BigFraction(jkind.util.BigFraction) Rational(edu.uah.rsesc.aadlsimulator.Rational) EnumValue(jkind.lustre.values.EnumValue) IntegerValue(jkind.lustre.values.IntegerValue) ArrayList(java.util.ArrayList) RecordValue(jkind.lustre.values.RecordValue) TupleValue(jkind.lustre.values.TupleValue) Entry(java.util.Map.Entry) BooleanValue(jkind.lustre.values.BooleanValue) TupleValue(jkind.lustre.values.TupleValue) IntegerValue(jkind.lustre.values.IntegerValue) BooleanValue(jkind.lustre.values.BooleanValue) RealValue(jkind.lustre.values.RealValue) RecordValue(jkind.lustre.values.RecordValue) Value(jkind.lustre.values.Value) EnumValue(jkind.lustre.values.EnumValue) ArrayValue(jkind.lustre.values.ArrayValue) EObject(org.eclipse.emf.ecore.EObject) InstanceObject(org.osate.aadl2.instance.InstanceObject) ArrayValue(jkind.lustre.values.ArrayValue) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with Value

use of jkind.lustre.values.Value 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);
}
Also used : RealValue(jkind.lustre.values.RealValue) BoolExpr(jkind.lustre.BoolExpr) IntegerValue(jkind.lustre.values.IntegerValue) BinaryExpr(jkind.lustre.BinaryExpr) RealValue(jkind.lustre.values.RealValue) IntegerValue(jkind.lustre.values.IntegerValue) Value(jkind.lustre.values.Value) BooleanValue(jkind.lustre.values.BooleanValue) IntExpr(jkind.lustre.IntExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr)

Example 14 with Value

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

the class Main method testValue.

private static void testValue(final String id, final Evaluator evaluator, final Value expectedValue) {
    final Value value = evaluator.evalOrNull(id);
    final boolean valueMatches = Objects.equals(value, expectedValue);
    System.out.println((valueMatches ? "SUCCESS" : "FAILURE") + " : " + id + " : " + value);
}
Also used : RealValue(jkind.lustre.values.RealValue) IntegerValue(jkind.lustre.values.IntegerValue) Value(jkind.lustre.values.Value) BooleanValue(jkind.lustre.values.BooleanValue)

Example 15 with Value

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

the class ExportAction method addElementToCounterexample.

private static void addElementToCounterexample(final Counterexample cex, final Object element, final AGREESimulationState engineState) {
    assert engineState.getElementLustreId(element) != null;
    // Create the signal
    final Signal<Value> newSignal = new Signal<>(engineState.getElementLustreId(element));
    // Populate the signal's values
    final int numberOfFrames = engineState.getNumberOfFrames();
    for (int frameIndex = 0; frameIndex < numberOfFrames; frameIndex++) {
        final Value value = engineState.getElementLustreValue(frameIndex, element);
        if (value != null) {
            newSignal.putValue(frameIndex, value);
        }
    }
    // Add signal to the counterexample
    cex.addSignal(newSignal);
}
Also used : Signal(jkind.results.Signal) Value(jkind.lustre.values.Value)

Aggregations

Value (jkind.lustre.values.Value)17 BooleanValue (jkind.lustre.values.BooleanValue)11 IntegerValue (jkind.lustre.values.IntegerValue)9 RealValue (jkind.lustre.values.RealValue)9 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Signal (jkind.results.Signal)6 EObject (org.eclipse.emf.ecore.EObject)6 List (java.util.List)4 BinaryExpr (jkind.lustre.BinaryExpr)4 BoolExpr (jkind.lustre.BoolExpr)4 IntExpr (jkind.lustre.IntExpr)4 RealExpr (jkind.lustre.RealExpr)4 ArrayValue (jkind.lustre.values.ArrayValue)4 EnumValue (jkind.lustre.values.EnumValue)4 TupleValue (jkind.lustre.values.TupleValue)4 Counterexample (jkind.results.Counterexample)4 Layout (jkind.results.layout.Layout)4 AgreeSubclause (com.rockwellcollins.atc.agree.agree.AgreeSubclause)3 AgreeUtils (com.rockwellcollins.atc.agree.analysis.AgreeUtils)3