Search in sources :

Example 6 with Value

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

the class SymbolicValue method applyUnaryOp.

public SymbolicValue applyUnaryOp(final UnaryOp op) {
    if (op == UnaryOp.NEGATIVE) {
        final Value newSlope = coefficient == null ? null : coefficient.applyUnaryOp(op);
        final Value newYIntercept = constant == null ? null : constant.applyUnaryOp(op);
        return new SymbolicValue(newSlope, variable, newYIntercept);
    } else if (op == UnaryOp.NOT) {
        if (coefficient != null) {
            return null;
        }
        return new SymbolicValue(null, null, constant.applyUnaryOp(op));
    }
    return null;
}
Also used : Value(jkind.lustre.values.Value) BooleanValue(jkind.lustre.values.BooleanValue)

Example 7 with Value

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

the class AgreeCounterexampleContentProvider method getElements.

@Override
public Object[] getElements(Object inputElement) {
    Counterexample cex = (Counterexample) inputElement;
    List<Object> result = new ArrayList<>();
    boolean first = true;
    for (String category : layout.getCategories()) {
        List<Signal<Value>> signals = cex.getCategorySignals(layout, category);
        if (!signals.isEmpty()) {
            if (first) {
                first = false;
            } else {
                result.add(new Spacer());
            }
            result.add(new CategoryHeader(category));
            List<Signal<Value>> inputSignals = signals.stream().filter(it -> {
                EObject ref = refMap.get(it.getName());
                return (ref instanceof org.osate.aadl2.Port) && ((org.osate.aadl2.Port) ref).isIn();
            }).collect(Collectors.toList());
            List<Signal<Value>> outputSignals = signals.stream().filter(it -> {
                EObject ref = refMap.get(it.getName());
                return (ref instanceof org.osate.aadl2.Port) && ((org.osate.aadl2.Port) ref).isOut();
            }).collect(Collectors.toList());
            List<Signal<Value>> otherSignals = signals.stream().filter(it -> !(inputSignals.contains(it) || outputSignals.contains(it))).collect(Collectors.toList());
            result.addAll(SignalGrouper.group(null, Stream.of(inputSignals, otherSignals, outputSignals).flatMap(Collection::stream).collect(Collectors.toList())));
        }
    }
    return result.toArray();
}
Also used : SignalGrouper(jkind.api.ui.counterexample.SignalGrouper) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) CounterexampleContentProvider(jkind.api.ui.counterexample.CounterexampleContentProvider) Signal(jkind.results.Signal) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Value(jkind.lustre.values.Value) Layout(jkind.results.layout.Layout) List(java.util.List) Stream(java.util.stream.Stream) CategoryHeader(jkind.api.ui.counterexample.CategoryHeader) Map(java.util.Map) Counterexample(jkind.results.Counterexample) Spacer(jkind.api.ui.counterexample.Spacer) ArrayList(java.util.ArrayList) Counterexample(jkind.results.Counterexample) Signal(jkind.results.Signal) Spacer(jkind.api.ui.counterexample.Spacer) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) CategoryHeader(jkind.api.ui.counterexample.CategoryHeader)

Example 8 with Value

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

the class AgreeMenuListener method viewCexConsole.

private void viewCexConsole(final Counterexample cex, final Layout layout, Map<String, EObject> refMap, final AgreeRenaming renaming) {
    final MessageConsole console = findConsole("Counterexample");
    showConsole(console);
    console.clearConsole();
    console.addPatternMatchListener(new AgreePatternListener(refMap));
    /*
		 * From the Eclipse API: "Clients should avoid writing large amounts of
		 * output to this stream in the UI thread. The console needs to process
		 * the output in the UI thread and if the client hogs the UI thread
		 * writing output to the console, the console will not be able to
		 * process the output."
		 */
    new Thread(() -> {
        try (MessageConsoleStream out = console.newMessageStream()) {
            for (String category : layout.getCategories()) {
                if (isEmpty(category, cex, layout)) {
                    continue;
                }
                printHLine(out, cex.getLength());
                if (category == "") {
                    out.println("Variables for the selected component implementation");
                } else {
                    out.println("Variables for " + category);
                }
                printHLine(out, cex.getLength());
                out.print(String.format("%-60s", "Variable Name"));
                for (int k1 = 0; k1 < cex.getLength(); k1++) {
                    out.print(String.format("%-15s", k1));
                }
                out.println();
                printHLine(out, cex.getLength());
                List<Signal<Value>> inputSignals = new ArrayList<>();
                List<Signal<Value>> outputSignals = new ArrayList<>();
                List<Signal<Value>> stateSignals = new ArrayList<>();
                for (Signal<Value> signal : cex.getCategorySignals(layout, category)) {
                    // dont' print out values for properties
                    if (signal.getName().contains(":")) {
                        continue;
                    }
                    String signalName = signal.getName();
                    EObject ref = renaming.findBestReference(signalName);
                    boolean isInput = (ref instanceof org.osate.aadl2.Port) ? ((org.osate.aadl2.Port) ref).isIn() : false;
                    boolean isOutput = (ref instanceof org.osate.aadl2.Port) ? ((org.osate.aadl2.Port) ref).isOut() : false;
                    if (isInput) {
                        inputSignals.add(signal);
                    } else if (isOutput) {
                        outputSignals.add(signal);
                    } else {
                        stateSignals.add(signal);
                    }
                }
                out.println("Inputs:");
                inputSignals.forEach(it -> printSignal(out, it, cex.getLength()));
                out.println("State:");
                stateSignals.forEach(it -> printSignal(out, it, cex.getLength()));
                out.println("Outputs:");
                outputSignals.forEach(it -> printSignal(out, it, cex.getLength()));
                out.println();
            }
            printHLine(out, cex.getLength());
            // print uninterpreted functions using Jkind CounterexampleFormatter
            AgreeUninterpretedFunctionFormatter uFcnFormatter = new AgreeUninterpretedFunctionFormatter(cex);
            out.println(uFcnFormatter.functions());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }).start();
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Program(jkind.lustre.Program) AnalysisResult(jkind.api.results.AnalysisResult) IAction(org.eclipse.jface.action.IAction) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) GlobalURIEditorOpener(org.eclipse.xtext.ui.editor.GlobalURIEditorOpener) Matcher(java.util.regex.Matcher) AgreeAutomaterRegistry(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomaterRegistry) PartInitException(org.eclipse.ui.PartInitException) IConsoleView(org.eclipse.ui.console.IConsoleView) Map(java.util.Map) BigInteger(java.math.BigInteger) ValidProperty(jkind.results.ValidProperty) AgreePattern(com.rockwellcollins.atc.agree.analysis.realtime.AgreePattern) PlatformUI(org.eclipse.ui.PlatformUI) MenuManager(org.eclipse.jface.action.MenuManager) Property(jkind.results.Property) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) MessageConsole(org.eclipse.ui.console.MessageConsole) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CexExtractorRegistry(com.rockwellcollins.atc.agree.analysis.extentions.CexExtractorRegistry) Layout(jkind.results.layout.Layout) List(java.util.List) AgreeUtils(com.rockwellcollins.atc.agree.analysis.AgreeUtils) GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) InvalidProperty(jkind.results.InvalidProperty) IConsoleManager(org.eclipse.ui.console.IConsoleManager) Pattern(java.util.regex.Pattern) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AgreeAutomater(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomater) ExtensionRegistry(com.rockwellcollins.atc.agree.analysis.extentions.ExtensionRegistry) Dialog(org.osate.ui.dialogs.Dialog) Counterexample(jkind.results.Counterexample) IMenuListener(org.eclipse.jface.action.IMenuListener) ConsistencyResult(com.rockwellcollins.atc.agree.analysis.ConsistencyResult) AgreeSubclause(com.rockwellcollins.atc.agree.agree.AgreeSubclause) Activator(com.rockwellcollins.atc.agree.analysis.Activator) ComponentImplementation(org.osate.aadl2.ComponentImplementation) ArrayList(java.util.ArrayList) IConsole(org.eclipse.ui.console.IConsole) HashSet(java.util.HashSet) JKindResult(jkind.api.results.JKindResult) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) ConsolePlugin(org.eclipse.ui.console.ConsolePlugin) AnalysisResultTree(jkind.api.ui.results.AnalysisResultTree) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) IConsoleConstants(org.eclipse.ui.console.IConsoleConstants) JRealizabilityResult(jkind.api.results.JRealizabilityResult) MalformedURLException(java.net.MalformedURLException) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) IOException(java.io.IOException) Action(org.eclipse.jface.action.Action) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) UnknownProperty(jkind.results.UnknownProperty) Signal(jkind.results.Signal) CexExtractor(com.rockwellcollins.atc.agree.analysis.extentions.CexExtractor) File(java.io.File) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) Value(jkind.lustre.values.Value) PreferenceConstants(com.rockwellcollins.atc.agree.analysis.preferences.PreferenceConstants) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) IMenuManager(org.eclipse.jface.action.IMenuManager) PropertyResult(jkind.api.results.PropertyResult) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) Renaming(jkind.api.results.Renaming) Collections(java.util.Collections) MessageConsole(org.eclipse.ui.console.MessageConsole) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) IOException(java.io.IOException) Signal(jkind.results.Signal) EObject(org.eclipse.emf.ecore.EObject) Value(jkind.lustre.values.Value) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with Value

use of jkind.lustre.values.Value 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 10 with Value

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

the class SimulationFrameResults method eval.

private Value eval(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 = eval(binaryExpr.left);
        final Value rightValue = eval(binaryExpr.right);
        if (leftValue == null || rightValue == null) {
            return null;
        }
        return leftValue.applyBinaryOp(binaryExpr.op, rightValue);
    } else if (lustreExpr instanceof UnaryExpr) {
        final UnaryExpr unaryExpr = (UnaryExpr) lustreExpr;
        final Value operandValue = eval(unaryExpr.expr);
        if (operandValue == null) {
            return null;
        }
        return operandValue.applyUnaryOp(unaryExpr.op);
    }
    return null;
}
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)

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