Search in sources :

Example 1 with Signal

use of jkind.results.Signal in project AGREE by loonwerks.

the class TcgXmlReader method getSignal.

private Signal<Value> getSignal(Element signalElement) {
    String name = signalElement.getAttribute("name");
    String type = signalElement.getAttribute("type");
    if (type.contains("subrange ")) {
        type = "int";
    }
    Signal<Value> signal = new Signal<>(name);
    for (Element valueElement : getElements(signalElement, "Value")) {
        int time = Integer.parseInt(valueElement.getAttribute(getTimeAttribute()));
        signal.putValue(time, getValue(valueElement, type));
    }
    return signal;
}
Also used : Signal(jkind.results.Signal) Element(org.w3c.dom.Element) Value(jkind.lustre.values.Value)

Example 2 with Signal

use of jkind.results.Signal 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 3 with Signal

use of jkind.results.Signal 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 4 with Signal

use of jkind.results.Signal in project AGREE by loonwerks.

the class Simulation method executeFrame.

private SimulationFrameResults executeFrame(final List<Expr> assertions, final Set<SimulationProperty> disabledProperties) throws InterruptedException {
    assert assertions != null;
    // Build the final constrained lustre specification for the frame.
    final ProgramBuilder programBuilder = new ProgramBuilder(program.getLustreProgram());
    programBuilder.clearNodes();
    final NodeBuilder nodeBuilder = new NodeBuilder(program.getLustreProgram().getMainNode());
    // Add assignments for the sim assertions signal
    // Actual assertions are not used because they can result in an inconsistent Lustre program which will prevent
    // the set of support from being generated when using yices.
    Expr prevSimAssertionExpr = new BoolExpr(true);
    for (int assertionIndex = 0; assertionIndex < assertions.size(); assertionIndex++) {
        final String simAssertionSignalId = CreateSimulationGuarantee.SIMULATION_ASSERTIONS_ID + assertionIndex;
        final IdExpr simAssertionExpr = new IdExpr(simAssertionSignalId);
        nodeBuilder.addLocal(new VarDecl(simAssertionSignalId, NamedType.BOOL));
        nodeBuilder.addEquation(new Equation(simAssertionExpr, new BinaryExpr(prevSimAssertionExpr, BinaryOp.AND, assertions.get(assertionIndex))));
        prevSimAssertionExpr = simAssertionExpr;
    }
    nodeBuilder.addEquation(new Equation(new IdExpr(CreateSimulationGuarantee.SIMULATION_ASSERTIONS_ID), prevSimAssertionExpr));
    // Add assignments for property enablement variables
    for (final SimulationProperty simProp : program.getSimulationProperties()) {
        if (simProp.getEnablementVariableId() != null) {
            nodeBuilder.addEquation(new Equation(new IdExpr(simProp.getEnablementVariableId()), new BoolExpr(disabledProperties.contains(simProp) ? false : true)));
        }
    }
    // Build the lustre program for the frame
    programBuilder.addNode(nodeBuilder.build());
    final Program constrainedLustreProgram = programBuilder.build();
    // Prepare to execute JKind
    final KindApi api = PreferencesUtil.getKindApi();
    // Enable IVC Reduction capability if using JKind
    if (api instanceof JKindApi) {
        final JKindApi jkindApi = (JKindApi) api;
        jkindApi.setIvcReduction();
    }
    // Execute JKind
    final JKindResult result = new JKindResult("Simulation");
    // Lucas: This seems to be needed. If we do not add properties to the result explicitly,
    // it looks like the result will grab the main property name with the main node prepended.
    // This is causing an error when retrieving the property result in the
    // if/then/else block structure below.
    constrainedLustreProgram.getMainNode().properties.forEach(p -> result.addProperty(p));
    System.out.println(constrainedLustreProgram.toString());
    try {
        final IProgressMonitor currentMonitor = new NullProgressMonitor();
        api.execute(constrainedLustreProgram, result, currentMonitor);
        // Create a model state from the results.
        String simulationGuaranteeId = CreateSimulationGuarantee.SIMULATION_GUARANTEE_ID;
        final PropertyResult propertyResult = result.getPropertyResult(simulationGuaranteeId);
        final Property property = propertyResult.getProperty();
        if (property == null) {
            throw new AGREESimulatorException("Unexpected case. Unable to read property results", constrainedLustreProgram);
        } else if (property instanceof InvalidProperty) {
            final InvalidProperty invalidProperty = (InvalidProperty) property;
            final Counterexample counterexample = invalidProperty.getCounterexample();
            if (counterexample.getLength() != 1) {
                throw new AGREESimulatorException("Unexpected case. Counterexample has " + counterexample.getLength() + " steps", constrainedLustreProgram);
            }
            SimulationState newState = SimulationState.WAITING_FOR_COMMANDS;
            // and a counterexample will not have been generated. This should only occur when a disabled property, lemma, top-level guarantee, or a non-top-level assumption is false.
            for (final SimulationProperty simulationProp : program.getSimulationProperties()) {
                if (!disabledProperties.contains(simulationProp)) {
                    for (final String propLustreId : simulationProp.getLustreIds()) {
                        final Signal<BooleanValue> signal = counterexample.getBooleanSignal(propLustreId);
                        if (signal == null) {
                            throw new AGREESimulatorException("Unable to get signal for guarantee property: " + propLustreId, constrainedLustreProgram);
                        } else {
                            if (!signal.getValue(0).value) {
                                newState = SimulationState.WARNING_PROPERTY_NOT_SATISFIED;
                                break;
                            }
                        }
                    }
                }
            }
            return new SimulationFrameResults(constrainedLustreProgram, counterexample, disabledProperties, newState);
        } else if (property instanceof UnknownProperty) {
            return new SimulationFrameResults(constrainedLustreProgram, assertions, disabledProperties, SimulationState.HALTED_UNABLE_TO_SATISFY_CONSTRAINTS);
        } else if (property instanceof ValidProperty) {
            return new SimulationFrameResults(constrainedLustreProgram, assertions, disabledProperties, ((ValidProperty) property).getIvc(), SimulationState.HALTED_UNABLE_TO_SATISFY_CONSTRAINTS);
        } else {
            throw new AGREESimulatorException("Unhandled case. Property is of type: " + property.getClass(), constrainedLustreProgram);
        }
    } catch (JKindException ex) {
        if (ex.getCause() instanceof InterruptedException) {
            throw (InterruptedException) ex.getCause();
        }
        throw new AGREESimulatorException(constrainedLustreProgram, ex, result.getText());
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) UnknownProperty(jkind.results.UnknownProperty) ValidProperty(jkind.results.ValidProperty) NodeBuilder(jkind.lustre.builders.NodeBuilder) Counterexample(jkind.results.Counterexample) PropertyResult(jkind.api.results.PropertyResult) JKindApi(jkind.api.JKindApi) Signal(jkind.results.Signal) VarDecl(jkind.lustre.VarDecl) SimulationProperty(edu.uah.rsesc.aadlsimulator.agree.SimulationProperty) KindApi(jkind.api.KindApi) JKindApi(jkind.api.JKindApi) SimulationProperty(edu.uah.rsesc.aadlsimulator.agree.SimulationProperty) ValidProperty(jkind.results.ValidProperty) Property(jkind.results.Property) UnknownProperty(jkind.results.UnknownProperty) InvalidProperty(jkind.results.InvalidProperty) InvalidProperty(jkind.results.InvalidProperty) Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) JKindException(jkind.JKindException) IdExpr(jkind.lustre.IdExpr) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) JKindResult(jkind.api.results.JKindResult) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr)

Example 5 with Signal

use of jkind.results.Signal 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

Signal (jkind.results.Signal)7 Value (jkind.lustre.values.Value)6 Counterexample (jkind.results.Counterexample)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 Program (jkind.lustre.Program)4 Layout (jkind.results.layout.Layout)4 EObject (org.eclipse.emf.ecore.EObject)4 AgreeSubclause (com.rockwellcollins.atc.agree.agree.AgreeSubclause)3 AgreeUtils (com.rockwellcollins.atc.agree.analysis.AgreeUtils)3 File (java.io.File)3 IOException (java.io.IOException)3 AnalysisResult (jkind.api.results.AnalysisResult)3 JKindResult (jkind.api.results.JKindResult)3 PropertyResult (jkind.api.results.PropertyResult)3 Renaming (jkind.api.results.Renaming)3 InvalidProperty (jkind.results.InvalidProperty)3 Property (jkind.results.Property)3 UnknownProperty (jkind.results.UnknownProperty)3