Skip to content
Snippets Groups Projects
DirectedGraphTranslator.java 221 KiB
Newer Older
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
 * ludovic.apvrille AT enst.fr
 * This software is a computer program whose purpose is to allow the
 * edition of TURTLE analysis, design and deployment diagrams, to
 * allow the generation of RT-LOTOS or Java code from this diagram,
 * and at last to allow the analysis of formal validation traces
 * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
 * from INRIA Rhone-Alpes.
 * This software is governed by the CeCILL  license under French law and
 * abiding by the rules of distribution of free software.  You can  use,
 * modify and/ or redistribute the software under the terms of the CeCILL
 * license as circulated by CEA, CNRS and INRIA at the following URL
 * "http://www.cecill.info".
 * As a counterpart to the access to the source code and  rights to copy,
 * modify and redistribute granted by the license, users are provided only
 * with a limited warranty  and the software's author,  the holder of the
 * economic rights,  and the successive licensors  have only  limited
 * liability.
 * In this respect, the user's attention is drawn to the risks associated
 * with loading,  using,  modifying and/or developing or reproducing the
 * software by the user in light of its specific status of free software,
 * that may mean  that it is complicated to manipulate,  and  that  also
 * therefore means  that it is reserved for developers  and  experienced
 * professionals having in-depth computer knowledge. Users are therefore
 * encouraged to load and test the software's suitability as regards their
 * requirements in conditions enabling the security of their systems and/or
 * data to be ensured and,  more generally, to use and operate it in the
 * same conditions as regards security.
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL license and that you accept its terms.
 */

maysam zoor's avatar
maysam zoor committed
package ui.simulationtraceanalysis;
import com.mxgraph.layout.hierarchical.mxHierarchicalLayout;
import com.mxgraph.swing.mxGraphComponent;
import org.jgrapht.Graph;
import org.jgrapht.GraphPath;
import org.jgrapht.Graphs;
import org.jgrapht.alg.shortestpath.AllDirectedPaths;
import org.jgrapht.alg.shortestpath.DijkstraShortestPath;
import org.jgrapht.ext.JGraphXAdapter;
import org.jgrapht.graph.DefaultDirectedGraph;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.io.*;
import tmltranslator.*;
import tmltranslator.tomappingsystemc2.DiploSimulatorCodeGenerator;
import ui.TGComponent;
import ui.TGConnectingPoint;
import ui.TGConnector;
import ui.TMLComponentDesignPanel;
import ui.interactivesimulation.SimulationTransaction;
import ui.tmlad.*;
import ui.tmlcompd.TMLCPrimitivePort;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;

/**
 * Class DirectedGraphTranslator: this class generate the directed graph
 * equivalent for the sysml model
 * 23/09/2019
 *
 * @author Maysam Zoor
 */
public class DirectedGraphTranslator extends JApplet {

    // private TMLArchiPanel tmlap; // USed to retrieve the currently opened
    // architecture panel
    // private TMLMapping<TGComponent> tmap;
maysam zoor's avatar
maysam zoor committed
    // private TMLComponentDesignPanel tmlcdp;
    private TMLTask taskAc, task1, task2;
    private TMLActivity activity;
    private int nodeNbProgressBar = 0;
    private int nodeNb = 0;
    private TMLActivityElement currentElement;
    private TMLActivityElement backwardElement;
    private ArrayList<String> SummaryCommMapping;
    private Graph<vertex, DefaultEdge> g;
    private static final Dimension DEFAULT_SIZE = new Dimension(530, 320);
maysam zoor's avatar
maysam zoor committed
    private List<TMLComponentDesignPanel> cpanels;

    private final List<HwLink> links;
    private final TMLMapping<TGComponent> tmap;
    private final HashMap<String, String> addedEdges = new HashMap<String, String>();
    private final HashMap<String, HashSet<String>> sendEventWaitEventEdges = new HashMap<String, HashSet<String>>();
    private final HashMap<String, HashSet<String>> readWriteChannelEdges = new HashMap<String, HashSet<String>>();
    private final HashMap<String, HashSet<String>> writeReadChannelEdges = new HashMap<String, HashSet<String>>();

    private final HashMap<String, HashSet<String>> forkreadEdges = new HashMap<String, HashSet<String>>();
    private final HashMap<String, HashSet<String>> forkwriteEdges = new HashMap<String, HashSet<String>>();

    private final HashMap<String, HashSet<String>> joinreadEdges = new HashMap<String, HashSet<String>>();
    private final HashMap<String, HashSet<String>> joinwriteEdges = new HashMap<String, HashSet<String>>();

    private final HashMap<String, HashSet<String>> sequenceEdges = new HashMap<String, HashSet<String>>();
    private final HashMap<String, ArrayList<String>> orderedSequenceList = new HashMap<String, ArrayList<String>>();
    private final HashMap<String, HashSet<String>> unOrderedSequenceEdges = new HashMap<String, HashSet<String>>();
    private final HashMap<String, ArrayList<String>> unOrderedSequenceList = new HashMap<String, ArrayList<String>>();
    private final List<String> forEverLoopList = new ArrayList<String>();
    private final HashMap<String, List<TMLTask>> requests = new HashMap<String, List<TMLTask>>();
    private final HashMap<String, HashSet<String>> requestEdges = new HashMap<String, HashSet<String>>();
    private final HashMap<String, List<String>> requestsOriginDestination = new HashMap<String, List<String>>();
    private final HashMap<String, List<String>> requestsPorts = new HashMap<String, List<String>>();
    private final HashMap<String, List<String>> requestsDestination = new HashMap<String, List<String>>();
    private final Vector<String> allLatencyTasks = new Vector<String>();
    private static JScrollPane scrollPane = new JScrollPane();

    // List<String,String> = new ArrayList<String,String>();

    private final HashMap<String, String> nameIDTaskList = new HashMap<String, String>();

    private final HashMap<String, ArrayList<String>> channelPaths = new HashMap<String, ArrayList<String>>();

    private Object[][] dataByTask = null;
    private Object[][] dataByTaskMinMax = null;
    private Object[][] dataByTaskBYRow;
    private Object[][] dataByTaskHWBYRow;

    private HashMap<Integer, Vector<SimulationTransaction>> dataByTaskR = new HashMap<Integer, Vector<SimulationTransaction>>();
    private HashMap<Integer, List<SimulationTransaction>> dataBydelayedTasks = new HashMap<Integer, List<SimulationTransaction>>();
    private HashMap<Integer, HashMap<String, ArrayList<ArrayList<Integer>>>> timeDelayedPerRow = new HashMap<Integer, HashMap<String, ArrayList<ArrayList<Integer>>>>();
    private HashMap<Integer, List<String>> detailsOfMinMaxRow = new HashMap<Integer, List<String>>();
    private HashMap<Integer, List<SimulationTransaction>> dataBydelayedTasksOfMinMAx = new HashMap<Integer, List<SimulationTransaction>>();
    private final JFrame frame = new JFrame("The Sys-ML Model As Directed Graph");
    private List<Integer> times1 = new ArrayList<Integer>();
    private List<Integer> times2 = new ArrayList<Integer>();
    private Vector<SimulationTransaction> transFile;
    private String idTask1;
    private String idTask2;
    private String task2DeviceName = "";
    private String task1DeviceName = "";
    private ArrayList<String> devicesToBeConsidered = new ArrayList<String>();
    private Vector<SimulationTransaction> relatedsimTraces = new Vector<SimulationTransaction>();
    private Vector<SimulationTransaction> delayDueTosimTraces = new Vector<SimulationTransaction>();
    private HashMap<String, ArrayList<SimulationTransaction>> relatedsimTraceswithTaint = new HashMap<String, ArrayList<SimulationTransaction>>();
    private JFrameLatencyDetailedAnalysis frameLatencyDetailedAnalysis;
    private JFrameCompareLatencyDetail frameCompareLatencyDetail;
    private int callingFrame;
    private int nbOfNodes = 0;

    private List<String> usedLabels = new ArrayList<String>();
    private List<String> warnings = new ArrayList<String>();
maysam zoor's avatar
maysam zoor committed

    private static Random random = new Random();

    private static final String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz";
    private static final String CHAR_UPPER = CHAR_LOWER.toUpperCase();
    private static final String data = CHAR_LOWER + CHAR_UPPER;
    // List<vertex> gVertecies = new ArrayList<vertex>();

    private HashMap<String, ArrayList<ArrayList<Integer>>> runnableTimePerDevice = new HashMap<String, ArrayList<ArrayList<Integer>>>();
    private HashMap<String, List<String>> allForLoopNextValues = new HashMap<String, List<String>>();
    private HashMap<vertex, List<vertex>> allChoiceValues = new HashMap<vertex, List<vertex>>();

    private HashMap<vertex, List<vertex>> allSeqValues = new HashMap<vertex, List<vertex>>();
    private HashMap<vertex, List<vertex>> allRandomSeqValues = new HashMap<vertex, List<vertex>>();

    private String taintLabel = "";

    private Vector<String> readChannelTransactions = new Vector<String>();
    private Vector<String> writeChannelTransactions = new Vector<String>();
    private HashMap<vertex, List<vertex>> ruleAddedEdges = new HashMap<vertex, List<vertex>>();

    private HashMap<vertex, List<vertex>> ruleAddedEdgesChannels = new HashMap<vertex, List<vertex>>();
    private HashMap<String, Integer> cpuIDs = new HashMap<String, Integer>();
    private HashMap<String, List<String>> forLoopNextValues = new HashMap<String, List<String>>();

    private int opCount;

    private HashMap<String, List<String>> sendEvt = new HashMap<String, List<String>>();
    private HashMap<String, List<String>> waitEvt = new HashMap<String, List<String>>();

    private HashMap<String, String> sendData = new HashMap<String, String>();
    private HashMap<String, String> receiveData = new HashMap<String, String>();
    private String taskStartName = "";
    @SuppressWarnings("deprecation")
maysam zoor's avatar
maysam zoor committed
    public DirectedGraphTranslator(JFrameLatencyDetailedAnalysis jFrameLatencyDetailedAnalysis, JFrameCompareLatencyDetail jframeCompareLatencyDetail,
            TMLMapping<TGComponent> tmap1, List<TMLComponentDesignPanel> cpanels1, int i) {
maysam zoor's avatar
maysam zoor committed
        setCpanels(cpanels1);

        links = tmap.getTMLArchitecture().getHwLinks();

maysam zoor's avatar
maysam zoor committed
        // tmlcdp = getCpanels().get(0);

        callingFrame = i;

        if (callingFrame == 0)

        {
            frameLatencyDetailedAnalysis = jFrameLatencyDetailedAnalysis;
        } else if (callingFrame == 1) {
            frameCompareLatencyDetail = jframeCompareLatencyDetail;
maysam zoor's avatar
maysam zoor committed
        }
        DrawDirectedGraph();

    }

    // The main function to add the vertices and edges according to the model

    public vertex vertex(String name, int id) {
        // TODO Auto-generated method stub

        vertex v = new vertex(name, id);
    private void DrawDirectedGraph() {
maysam zoor's avatar
maysam zoor committed
        nodeNbProgressBar = 0;

        nodeNbProgressBar = tmap.getArch().getBUSs().size() + tmap.getArch().getHwBridge().size() + tmap.getArch().getHwA().size()
                + tmap.getArch().getMemories().size() + tmap.getArch().getCPUs().size();

        expectedNumberofVertex();
maysam zoor's avatar
maysam zoor committed

        if (callingFrame == 0)

        {
            frameLatencyDetailedAnalysis.getPbar().setMaximum(nodeNbProgressBar);
            frameLatencyDetailedAnalysis.getPbar().setMinimum(0);
maysam zoor's avatar
maysam zoor committed

        }
        if (callingFrame == 1)

        {
            frameCompareLatencyDetail.getPbar().setMaximum(nodeNbProgressBar);
            frameCompareLatencyDetail.getPbar().setMinimum(0);
maysam zoor's avatar
maysam zoor committed
        }

        nbOfNodes = 0;
        // HashMap<String, HashSet<String>> cpuTasks;
        HashMap<String, HashSet<TMLElement>> buschannel = new HashMap<String, HashSet<TMLElement>>();
        HashMap<String, HashSet<TMLElement>> memorychannel = new HashMap<String, HashSet<TMLElement>>();

        HashMap<String, HashSet<TMLElement>> bridgechannel = new HashMap<String, HashSet<TMLElement>>();

        // HashMap<String, HashSet<TMLTask>> cpuTask = new HashMap<String,
        // HashSet<TMLTask>>();
        g = new DefaultDirectedGraph<>(DefaultEdge.class);

        buschannel = addBUSs();
        bridgechannel = addBridge();
        addHwAs();
        memorychannel = addMemories();
        addBuschannel(buschannel);
        addBridgechannel(bridgechannel);
        addMemorychannel(memorychannel);
        addUnmappedchannel();
        addCPUs();
        addLinkEdges();
        addFlowEdges();
        addSendEventWaitEventEdges();
        addReadWriteChannelEdges();
        addForkreadEdges();
        addJoinreadEdges();
        addWriteReadChannelEdges();
        addSeqEdges();
        addunOrderedSeqEdges();
        addRequestEdges();
maysam zoor's avatar
maysam zoor committed

    private void addUnmappedchannel() {
        // TODO Auto-generated method stub
        DiploSimulatorCodeGenerator gen = new DiploSimulatorCodeGenerator(tmap);
        for (TMLChannel ch : tmap.getTMLModeling().getChannels()) {
            List<HwCommunicationNode> pathNodes = gen.determineRoutingPath(tmap.getHwNodeOf(ch.getOriginTask()),
                    tmap.getHwNodeOf(ch.getDestinationTask()), ch);
maysam zoor's avatar
maysam zoor committed

            if (!g.vertexSet().contains(getvertex(ch.getName()))) {
                vertex v2 = vertex(ch.getName(), ch.getID());
                g.addVertex(v2);
                // gVertecies.add(vertex(ch.getName()));
                getvertex(ch.getName()).setType(vertex.TYPE_CHANNEL);
                getvertex(ch.getName()).setTaintFixedNumber(0);
                updatemainBar(ch.getName());
            if (!pathNodes.isEmpty()) {
                for (HwCommunicationNode node : pathNodes) {
                    if (channelPaths.containsKey(ch.getName())) {
                        if (!channelPaths.get(ch.getName()).contains(node.getName())) {
                            channelPaths.get(ch.getName()).add(node.getName());
                        }
                    } else {
                        ArrayList<String> pathNodeNames = new ArrayList<String>();
                        pathNodeNames.add(node.getName());
                        channelPaths.put(ch.getName(), pathNodeNames);
                    }
                    vertex v1 = vertex(node.getName(), node.getID());
maysam zoor's avatar
maysam zoor committed

                    vertex v2 = vertex(ch.getName(), ch.getID());
maysam zoor's avatar
maysam zoor committed

                    if (!g.containsEdge(v1, v2)) {
                        g.addEdge(v1, v2);
                    }
        SummaryCommMapping = tmap.getSummaryCommMapping();
maysam zoor's avatar
maysam zoor committed

    private void addCPUs() {
        // TODO Auto-generated method stub
        HashMap<String, HashSet<TMLTask>> cpuTask = new HashMap<String, HashSet<TMLTask>>();
        HashMap<String, HashSet<String>> cpuTasks;
        for (HwNode node : tmap.getArch().getCPUs()) {
            cpuTask = new HashMap<String, HashSet<TMLTask>>();
            cpuIDs.put(node.getName(), node.getID());
            if (tmap.getLisMappedTasks(node).size() > 0) {
maysam zoor's avatar
maysam zoor committed

                cpuTask.put(node.getName(), tmap.getLisMappedTasks(node));

            }

            cpuTasks = getCPUTaskMap(cpuTask);

        }

    private void addMemorychannel(HashMap<String, HashSet<TMLElement>> memorychannel) {
        // TODO Auto-generated method stub
        for (Entry<String, HashSet<TMLElement>> entry : memorychannel.entrySet()) {
            String busName = entry.getKey();
            HashSet<TMLElement> busChList = entry.getValue();

            for (TMLElement busCh : busChList) {

                String ChannelName = busCh.getName();
                vertex v = vertex(ChannelName, busCh.getID());
maysam zoor's avatar
maysam zoor committed

                if (!g.containsVertex(getvertex(ChannelName))) {
                    g.addVertex(v);
                    getvertex(ChannelName).setType(vertex.TYPE_CHANNEL);
                    // gVertecies.add(vertex(ChannelName));
                    getvertex(ChannelName).setTaintFixedNumber(0);
maysam zoor's avatar
maysam zoor committed
                    updatemainBar("ChannelName");

                }

                g.addEdge(getvertex(busName), getvertex(ChannelName));
    }

    private void addBridgechannel(HashMap<String, HashSet<TMLElement>> bridgechannel) {
        // TODO Auto-generated method stub

        for (Entry<String, HashSet<TMLElement>> entry : bridgechannel.entrySet()) {
            String busName = entry.getKey();
            HashSet<TMLElement> busChList = entry.getValue();

            for (TMLElement busCh : busChList) {

                String ChannelName = busCh.getName();
                vertex v = vertex(ChannelName, busCh.getID());

                if (!g.containsVertex(getvertex(ChannelName))) {
                    g.addVertex(v);
                    getvertex(ChannelName).setType(vertex.TYPE_CHANNEL);
                    // gVertecies.add(vertex(ChannelName));

                    getvertex(ChannelName).setTaintFixedNumber(0);
maysam zoor's avatar
maysam zoor committed

                    updatemainBar("ChannelName");

                }

                g.addEdge(getvertex(busName), getvertex(ChannelName));
    }

    private void addBuschannel(HashMap<String, HashSet<TMLElement>> buschannel) {
        // TODO Auto-generated method stub
        for (Entry<String, HashSet<TMLElement>> entry : buschannel.entrySet()) {
            String busName = entry.getKey();
            HashSet<TMLElement> busChList = entry.getValue();

            for (TMLElement busCh : busChList) {

                String ChannelName = busCh.getName();

                vertex v = vertex(ChannelName, busCh.getID());

                if (!g.containsVertex(v)) {
                    g.addVertex(v);

                    getvertex(ChannelName).setType(vertex.TYPE_CHANNEL);
                    // gVertecies.add(vertex(ChannelName));
                    getvertex(ChannelName).setTaintFixedNumber(0);
maysam zoor's avatar
maysam zoor committed
                    updatemainBar("ChannelName");

                }

                g.addEdge(getvertex(busName), getvertex(ChannelName));
                // TMLChannel tmlch = (TMLChannel) busCh;
                // String writeChannel = tmlch.getDestinationTask().getName() + "__" +
                // "writechannel:" + tmlch.getDestinationPort();
                // String readChannel;
    private HashMap<String, HashSet<TMLElement>> addMemories() {
        HashMap<String, HashSet<TMLElement>> memorychannel = new HashMap<String, HashSet<TMLElement>>();
        for (HwNode node : tmap.getArch().getMemories()) {
            vertex v = vertex(node.getName(), node.getID());
            if (!g.containsVertex(v)) {
                g.addVertex(v);
                updatemainBar("getMemories");
            }

            if (tmap.getLisMappedChannels(node).size() > 0) {
                memorychannel.put(node.getName(), tmap.getLisMappedChannels(node));
        return memorychannel;
    }

    private void addHwAs() {
        // TODO Auto-generated method stub
        HashMap<String, HashSet<TMLTask>> cpuTask = new HashMap<String, HashSet<TMLTask>>();
        HashMap<String, HashSet<String>> cpuTasks;
        for (HwA node : tmap.getArch().getHwA()) {
maysam zoor's avatar
maysam zoor committed
            cpuTask = new HashMap<String, HashSet<TMLTask>>();
            cpuIDs.put(node.getName(), node.getID());

            if (tmap.getLisMappedTasks(node).size() > 0) {
maysam zoor's avatar
maysam zoor committed

                cpuTask.put(node.getName(), tmap.getLisMappedTasks(node));

            }

            cpuTasks = getCPUTaskMap(cpuTask);

        }
    }

    private HashMap<String, HashSet<TMLElement>> addBridge() {
        // TODO Auto-generated method stub

        HashMap<String, HashSet<TMLElement>> bridgechannel = new HashMap<String, HashSet<TMLElement>>();

        for (HwNode node : tmap.getArch().getHwBridge()) {

            vertex v = vertex(node.getName(), node.getID());

            if (!g.containsVertex(v)) {
                g.addVertex(v);

                updatemainBar("getHwBridge");

            }

            if (tmap.getLisMappedChannels(node).size() > 0) {
                bridgechannel.put(node.getName(), tmap.getLisMappedChannels(node));

            }

        }
        return bridgechannel;

    }

    private HashMap<String, HashSet<TMLElement>> addBUSs() {
        // TODO Auto-generated method stub
        HashMap<String, HashSet<TMLElement>> buschannel = new HashMap<String, HashSet<TMLElement>>();
        for (HwNode node : tmap.getArch().getBUSs()) {

            vertex v = vertex(node.getName(), node.getID());

            if (!g.containsVertex(v)) {
                g.addVertex(v);

                updatemainBar("getBUSs");

            }

            if (tmap.getLisMappedChannels(node).size() > 0) {
                buschannel.put(node.getName(), tmap.getLisMappedChannels(node));

            }

        }

        return buschannel;

    }

    private void addLinkEdges() {
        // TODO Auto-generated method stub
        for (HwLink link : links) {

            vertex vlink1 = vertex(link.hwnode.getName(), link.hwnode.getID());
            vertex vlink2 = vertex(link.bus.getName(), link.bus.getID());
            if (g.containsVertex(getvertex(link.hwnode.getName())) && g.containsVertex(getvertex(link.bus.getName()))) {

                g.addEdge(vlink1, vlink2);
                g.addEdge(vlink2, vlink1);
    }

    private void addFlowEdges() {
        // TODO Auto-generated method stub
        if (addedEdges.size() > 0) {
            for (Entry<String, String> edge : addedEdges.entrySet()) {
                g.addEdge(getvertex(edge.getKey()), getvertex(edge.getValue()));
    }

    private void addSendEventWaitEventEdges() {
        // TODO Auto-generated method stub
        if (sendEventWaitEventEdges.size() > 0) {
            for (Entry<String, HashSet<String>> edge : sendEventWaitEventEdges.entrySet()) {

                for (String waitEventEdge : edge.getValue())

                    g.addEdge(getvertex(edge.getKey()), getvertex(waitEventEdge));

    }

    private void addReadWriteChannelEdges() {
        // TODO Auto-generated method stub
        if (readWriteChannelEdges.size() > 0) {
            for (Entry<String, HashSet<String>> edge : readWriteChannelEdges.entrySet()) {

                for (String readChannelEdge : edge.getValue()) {

                    g.addEdge(getvertex(edge.getKey()), getvertex(readChannelEdge));

                    getvertex(edge.getKey()).setTaintFixedNumber(getvertex(edge.getKey()).getTaintFixedNumber() + 1);

                }
            }
        }

    }

    private void addForkreadEdges() {
        // TODO Auto-generated method stub
        if (forkreadEdges.size() > 0) {
            for (Entry<String, HashSet<String>> edge : forkreadEdges.entrySet()) {

                HashSet<String> writech = forkwriteEdges.get(edge.getKey());

                for (String readChannelEdge : edge.getValue()) {

                    for (String wch : writech) {

                        g.addEdge(getvertex(readChannelEdge), getvertex(wch));

                    }
                }
            }
        }
    }

    // draw the vertices and edges for the tasks mapped to the CPUs

    private void addJoinreadEdges() {
        // TODO Auto-generated method stub
        if (joinreadEdges.size() > 0) {
            for (Entry<String, HashSet<String>> edge : joinreadEdges.entrySet()) {

                HashSet<String> writech = joinwriteEdges.get(edge.getKey());

                for (String readChannelEdge : edge.getValue()) {
                    for (String wch : writech) {
                        g.addEdge(getvertex(readChannelEdge), getvertex(wch));

                    }
                }
            }
        }

    }

    private void addWriteReadChannelEdges() {
        // TODO Auto-generated method stub
        if (writeReadChannelEdges.size() > 0) {
            for (Entry<String, HashSet<String>> edge : writeReadChannelEdges.entrySet()) {

                for (String readChannelEdge : edge.getValue()) {

                    g.addEdge(getvertex(edge.getKey()), getvertex(readChannelEdge));
                    getvertex(readChannelEdge).setTaintFixedNumber(getvertex(readChannelEdge).getTaintFixedNumber() + 1);

                }
    private void addRequestEdges() {
        // TODO Auto-generated method stub
        if (requestEdges.size() > 0) {

            for (Entry<String, HashSet<String>> edge : requestEdges.entrySet()) {

                for (String requestsingleEdges : edge.getValue()) {

                    g.addEdge(getvertex(edge.getKey()), getvertex(requestsingleEdges));
    private void addunOrderedSeqEdges() {
        // TODO Auto-generated method stub
        if (unOrderedSequenceEdges.size() > 0) {
            for (Entry<String, HashSet<String>> edge : unOrderedSequenceEdges.entrySet()) {
                for (String sequenceEdge : edge.getValue())
maysam zoor's avatar
maysam zoor committed

                    g.addEdge(getvertex(edge.getKey()), getvertex(sequenceEdge));
maysam zoor's avatar
maysam zoor committed

maysam zoor's avatar
maysam zoor committed

maysam zoor's avatar
maysam zoor committed

    private void addSeqEdges() {
        if (sequenceEdges.size() > 0) {
            for (Entry<String, HashSet<String>> edge : sequenceEdges.entrySet()) {

                for (String sequenceEdge : edge.getValue())
maysam zoor's avatar
maysam zoor committed

                    g.addEdge(getvertex(edge.getKey()), getvertex(sequenceEdge));

            }
    private void expectedNumberofVertex() {
        for (HwA node : tmap.getArch().getHwA()) {
            if (tmap.getLisMappedTasks(node).size() > 0) {
                nodeNbProgressBar = tmap.getLisMappedTasks(node).size() + nodeNbProgressBar;
                for (TMLTask task : tmap.getLisMappedTasks(node)) {
                    for (TMLActivityElement ae : task.getActivityDiagram().getElements()) {
                        if (ae.getName().equals("Stop after infinite loop")) {
                        } else {
                            nodeNbProgressBar++;
        for (HwNode node : tmap.getArch().getCPUs()) {
            if (tmap.getLisMappedTasks(node).size() > 0) {
                nodeNbProgressBar = tmap.getLisMappedTasks(node).size() + nodeNbProgressBar;
                for (TMLTask task : tmap.getLisMappedTasks(node)) {
                    for (TMLActivityElement ae : task.getActivityDiagram().getElements()) {
                        if (ae.getName().equals("Stop after infinite loop")) {
                            nodeNbProgressBar++;

            }
        }
        HashSet<String> mappedcomm = new HashSet<String>();
        for (HwNode node : tmap.getArch().getBUSs()) {
            if (tmap.getLisMappedChannels(node).size() > 0) {
                for (TMLElement entry : tmap.getLisMappedChannels(node)) {

                    if (!mappedcomm.contains(entry.getName())) {
                        mappedcomm.add(entry.getName());
                        nodeNbProgressBar++;
        for (HwNode node : tmap.getArch().getHwBridge()) {
            if (tmap.getLisMappedChannels(node).size() > 0) {
                for (TMLElement entry : tmap.getLisMappedChannels(node)) {
                    if (!mappedcomm.contains(entry.getName())) {
                        mappedcomm.add(entry.getName());
                        nodeNbProgressBar++;
        for (HwNode node : tmap.getArch().getMemories()) {
            if (tmap.getLisMappedChannels(node).size() > 0) {
                for (TMLElement entry : tmap.getLisMappedChannels(node)) {
                    if (!mappedcomm.contains(entry.getName())) {
                        mappedcomm.add(entry.getName());
                        nodeNbProgressBar++;
        for (TMLChannel ch : tmap.getTMLModeling().getChannels()) {
            if (!mappedcomm.contains(ch.getName())) {
                mappedcomm.add(ch.getName());
                nodeNbProgressBar++;
    private void updatemainBar(String string) {
        nbOfNodes++;
        if (callingFrame == 0)
        {
            frameLatencyDetailedAnalysis.updateBar(nbOfNodes);
        } else if (callingFrame == 1) {
            frameCompareLatencyDetail.updateBar(nbOfNodes);
    public HashMap<String, HashSet<String>> getCPUTaskMap(HashMap<String, HashSet<TMLTask>> cpuTask) {
        HashMap<String, HashSet<String>> cpuTaskMap = new HashMap<String, HashSet<String>>();
        if (tmap == null) {
            return cpuTaskMap;
        }
        for (Entry<String, HashSet<TMLTask>> entry : cpuTask.entrySet()) {
            String key = entry.getKey();
            int keyID = cpuIDs.get(key);
            HashSet<TMLTask> value = entry.getValue();
            Vector<TMLActivityElement> multiNexts = new Vector<TMLActivityElement>();
            // Map <String, String> sendEvt;
            sendEvt = new HashMap<String, List<String>>();
            waitEvt = new HashMap<String, List<String>>();
            sendData = new HashMap<String, String>();
            receiveData = new HashMap<String, String>();
            // HashMap<String, List<String>> sendEvt = new HashMap<String, List<String>>();
            // GEt List of all requests
            requestedTask(value);
            for (TMLTask task : value) {
                int taskID = task.getID();
                String taskName = task.getName();
                // get the names and params of send events per task and their corresponding wait
                // events
                taskAc = task;
                sendEventsNames();
                // get the names of read channels per task and their corresponding write
                // channels
                readChannelNames();

                // get the names of write channels per task and their corresponding read
                // channels

                writeChannelNames();
                // get the names and params of wait events per task and their corresponding send
                // events
                waitEventNames();
                // add the name of the task as a vertex
                if (!g.vertexSet().contains(getvertex(key))) {
                    g.addVertex(vertex(key, keyID));
                    updatemainBar(key);
                }
                if (!g.vertexSet().contains(getvertex(taskName))) {
                    g.addVertex(vertex(taskName, taskID));
                    updatemainBar(taskName);
                }
                g.addEdge(getvertex(key), getvertex(taskName));
                activity = task.getActivityDiagram();
                opCount = 1;
                currentElement = activity.getFirst();
                taskStartName = "";
                // int taskStartid;
                forLoopNextValues = new HashMap<String, List<String>>();
                // loop over all the activites corresponding to a task
                while (opCount <= activity.nElements()) {
                    String eventName = null;
                    // int eventid = currentElement.getID();
                    if (currentElement.getName().equals("Stop after infinite loop")) {
                        opCount++;
                        if (opCount <= activity.nElements()) {
                            if (currentElement.getNexts().size() == 1) {

                                currentElement = currentElement.getNexts().firstElement();

                            } else if (!multiNexts.isEmpty()) {
                                currentElement = multiNexts.get(0);
                                multiNexts.remove(0);
                            continue;
                        } else {
                            break;
                        }
                    } else if (currentElement.getName().equals("startOfFork") || currentElement.getName().equals("junctionOfFork")
                            || currentElement.getName().equals("startOfJoin") || currentElement.getName().equals("junctionOfJoin")) {
                        opCount++;
                        currentElement = currentElement.getNexts().firstElement();
                        continue;
                    } else if (taskName.startsWith("FORKTASK_S_") && currentElement.getName().equals("ReadOfFork")) {
                        String name = ((TMLReadChannel) (currentElement)).getChannel(0).getName();
                        int id = ((TMLReadChannel) (currentElement)).getChannel(0).getID();
                        if (!g.containsVertex(getvertex(name))) {
                            g.addVertex(vertex(name, id));
                        g.addEdge(getvertex(taskName), getvertex(((TMLReadChannel) (currentElement)).getChannel(0).getName()));
                        HashSet<String> readForkVertex = new HashSet<String>();
                        readForkVertex.add(((TMLReadChannel) (currentElement)).getChannel(0).getName());
                        if (forkreadEdges.containsKey(taskName)) {
                            if (!forkreadEdges.get(taskName).contains(((TMLReadChannel) (currentElement)).getChannel(0).getName())) {
                                forkreadEdges.get(taskName).add(((TMLReadChannel) (currentElement)).getChannel(0).getName());
                            }
                        } else {
                            forkreadEdges.put(taskName, readForkVertex);
                        opCount++;
                        currentElement = currentElement.getNexts().firstElement();
                        continue;
                    } else if (taskName.startsWith("FORKTASK_S_") && currentElement.getName().startsWith("WriteOfFork_S")) {
                        String vName = ((TMLWriteChannel) (currentElement)).getChannel(0).getName();
                        int vid = ((TMLWriteChannel) (currentElement)).getChannel(0).getID();
                        vertex v = getvertex(vName);
                        if (!g.containsVertex(v)) {
                            g.addVertex(vertex(vName, vid));
                        }

                        HashSet<String> writeForkVertex = new HashSet<String>();
                        writeForkVertex.add(((TMLWriteChannel) (currentElement)).getChannel(0).getName());

                        if (forkwriteEdges.containsKey(taskName)) {

                            if (!forkwriteEdges.get(taskName).contains(((TMLWriteChannel) (currentElement)).getChannel(0).getName())) {
                                forkwriteEdges.get(taskName).add(((TMLWriteChannel) (currentElement)).getChannel(0).getName());