Search in sources :

Example 1 with BooleanValue

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>");
}
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 BooleanValue

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());
    }
}
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 3 with BooleanValue

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);
}
Also used : BooleanValue(jkind.lustre.values.BooleanValue) Value(jkind.lustre.values.Value) BooleanValue(jkind.lustre.values.BooleanValue)

Example 4 with BooleanValue

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());
    }
}
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)

Example 5 with BooleanValue

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;
        }
    }
}
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)

Aggregations

BooleanValue (jkind.lustre.values.BooleanValue)6 IntegerValue (jkind.lustre.values.IntegerValue)5 RealValue (jkind.lustre.values.RealValue)5 Value (jkind.lustre.values.Value)5 ArrayValue (jkind.lustre.values.ArrayValue)3 EnumValue (jkind.lustre.values.EnumValue)3 TupleValue (jkind.lustre.values.TupleValue)3 BigFraction (jkind.util.BigFraction)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 RecordValue (jkind.lustre.values.RecordValue)2 TcgException (com.rockwellcollins.atc.tcg.TcgException)1 Rational (edu.uah.rsesc.aadlsimulator.Rational)1 SimulationFrameResults (edu.uah.rsesc.aadlsimulator.agree.sim.SimulationFrameResults)1 BinaryExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BinaryExpression)1 BooleanLiteral (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral)1 IntegerLiteral (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntegerLiteral)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1