Skip to content
Snippets Groups Projects
DirectedGraphTranslator.java 110 KiB
Newer Older
        // message = "there exists " +path.size()+" between: " + task12 + " and " +
        // task22;
        if (path2 != null && path2.getLength() > 0) {
            for (Entry<String, ArrayList<String>> entry : channelPaths.entrySet()) {
                String ChannelName = entry.getKey();
                ArrayList<String> busChList = entry.getValue();
                GraphPath<String, DefaultEdge> pathTochannel = DijkstraShortestPath.findPathBetween(g, task12, ChannelName);
                GraphPath<String, DefaultEdge> pathFromChannel = DijkstraShortestPath.findPathBetween(g, ChannelName, task22);
                if (pathTochannel != null && pathTochannel.getLength() > 0 && pathFromChannel != null && pathFromChannel.getLength() > 0) {
                    devicesToBeConsidered.addAll(busChList);
            for (Entry<String, ArrayList<String>> entry : channelPaths.entrySet()) {
                String ChannelName = entry.getKey();
                ArrayList<String> busChList = entry.getValue();
                GraphPath<String, DefaultEdge> pathTochannel = DijkstraShortestPath.findPathBetween(g, task12, ChannelName);
                GraphPath<String, DefaultEdge> pathFromChannel = DijkstraShortestPath.findPathBetween(g, ChannelName, task22);
                if ((pathTochannel != null && pathTochannel.getLength() > 0) || (pathFromChannel != null && pathFromChannel.getLength() > 0)) {
                    devicesToBeConsidered.addAll(busChList);
        for (SimulationTransaction st : transFile1) {
            if (st.id.equals(idTask1)) {
                Task1Traces.add(st);
                task1DeviceName = st.deviceName;
                times1.add(Integer.valueOf(st.startTime));
                Collections.sort(times1);
            if (st.id.equals(idTask2)) {
                Task2Traces.add(st);
                task2DeviceName = st.deviceName;
                times2.add(Integer.valueOf(st.endTime));
                Collections.sort(times1);
            }
        }
        // one to one
        int minIndex = 0;
        if (times1.size() != times2.size()) {
            minIndex = Math.min(times1.size(), times2.size());
        } else {
            minIndex = times1.size();
        }
        dataByTask = new Object[minIndex][7];
        dataByTaskBYRow = new Object[minIndex][2];
        dataByTaskHWBYRow = new Object[minIndex][2];
        for (int i = 0; i < minIndex; i++) {
            HashMap<String, ArrayList<SimulationTransaction>> relatedHWs = new HashMap<String, ArrayList<SimulationTransaction>>();
            HashMap<String, ArrayList<SimulationTransaction>> relatedTasks = new HashMap<String, ArrayList<SimulationTransaction>>();
            relatedsimTraces = new Vector<SimulationTransaction>();
            delayDueTosimTraces = new Vector<SimulationTransaction>();
            runnableTimePerDevice = new HashMap<String, ArrayList<ArrayList<Integer>>>();
            for (SimulationTransaction st : transFile1) {
                Boolean onPath = false;
                // if (Integer.valueOf(st.startTime) >= times1.get(i) &&
                // Integer.valueOf(st.startTime) < times2.get(i)) {
                if (!(Integer.valueOf(st.startTime) < times1.get(i) && Integer.valueOf(st.endTime) < times1.get(i))
                        && !(Integer.valueOf(st.startTime) > times2.get(i) && Integer.valueOf(st.endTime) > times2.get(i))) {
                    // if (Integer.valueOf(st.startTime) >= minTime && Integer.valueOf(st.startTime)
                    // < maxTime) {
                    if (Integer.valueOf(st.endTime) > times2.get(i)) {
                        st.endTime = times2.get(i).toString();
                        st.length = Integer.valueOf(Integer.valueOf(times2.get(i)) - Integer.valueOf(st.startTime)).toString();
                    }
                    if (Integer.valueOf(st.startTime) < times1.get(i)) {
                        st.startTime = Integer.valueOf(times1.get(i)).toString();
                        st.length = Integer.valueOf(Integer.valueOf(st.endTime) - Integer.valueOf(times1.get(i))).toString();
                    }
                    if (Integer.valueOf(st.startTime) < times1.get(i) && Integer.valueOf(st.endTime) > times2.get(i)) {
                        st.startTime = Integer.valueOf(times1.get(i)).toString();
                        st.endTime = times2.get(i).toString();
                        st.length = Integer.valueOf(Integer.valueOf(times2.get(i)) - Integer.valueOf(times1.get(i))).toString();
                    }
                    for (String tasknameCheck : g.vertexSet()) {
                        String[] taskToAdd = tasknameCheck.replaceAll(" ", "").split("__");
                        int taskToAddindex = taskToAdd.length;
                        String taskToAddid = taskToAdd[taskToAddindex - 1];
                        if (isNumeric(taskToAddid)) {
                            if (Integer.valueOf(taskToAddid).equals(Integer.valueOf(st.id))) {
                                taskname = tasknameCheck;
                                break;
                    String[] name = st.deviceName.split("_");
                    String deviceName = name[0];
                    // there is a path between task 1 and task 2
                    if (path2 != null && path2.getLength() > 0) {
                        if (!taskname.equals(null) && !taskname.equals("")) {
                            GraphPath<String, DefaultEdge> pathToOrigin = DijkstraShortestPath.findPathBetween(g, task12, taskname);
                            GraphPath<String, DefaultEdge> pathToDestination = DijkstraShortestPath.findPathBetween(g, taskname, task22);
                            if (taskname.equals(task12) || taskname.equals(task22) || (pathToOrigin != null && pathToOrigin.getLength() > 0
                                    && pathToDestination != null && pathToDestination.getLength() > 0)) {
                                relatedsimTraces.add(st);
                                ArrayList<Integer> timeValues = new ArrayList<Integer>();
                                timeValues.add(0, Integer.valueOf(st.runnableTime));
                                timeValues.add(1, Integer.valueOf(st.startTime));
                                if (!(st.runnableTime).equals(st.startTime)) {
                                    if (runnableTimePerDevice.containsKey(st.deviceName)) {
                                        if (!runnableTimePerDevice.get(st.deviceName).contains(timeValues)) {
                                            runnableTimePerDevice.get(st.deviceName).add(timeValues);
                                        ArrayList<ArrayList<Integer>> timeValuesList = new ArrayList<ArrayList<Integer>>();
                                        timeValuesList.add(timeValues);
                                        runnableTimePerDevice.put(st.deviceName, timeValuesList);
                            } else if (((st.deviceName.equals(task2DeviceName)) || st.deviceName.equals(task1DeviceName)
                                    || devicesToBeConsidered.contains(deviceName)) && !st.id.equals(idTask1) && !st.id.equals(idTask2)) {
                                delayDueTosimTraces.add(st);
                        if (!taskname.equals(null) && !taskname.equals("")) {
                            GraphPath<String, DefaultEdge> pathExistsTestwithTask1 = DijkstraShortestPath.findPathBetween(g, task12, taskname);
                            GraphPath<String, DefaultEdge> pathExistsTestwithTask2 = DijkstraShortestPath.findPathBetween(g, taskname, task22);
                            if (pathExistsTestwithTask1 != null && pathExistsTestwithTask1.getLength() > 0
                                    || pathExistsTestwithTask2 != null && pathExistsTestwithTask2.getLength() > 0) {
                                relatedsimTraces.add(st);
                            } else if (((st.deviceName.equals(task2DeviceName)) || st.deviceName.equals(task1DeviceName)
                                    || devicesToBeConsidered.contains(deviceName)) && !st.id.equals(idTask1) && !st.id.equals(idTask2)) {
                                delayDueTosimTraces.add(st);
            dataByTask[i][0] = task12;
            dataByTask[i][1] = times1.get(i);
            dataByTask[i][2] = task22;
            dataByTask[i][3] = times2.get(i);

            dataByTask[i][4] = times2.get(i) - times1.get(i);
            dataByTask[i][5] = "";

            dataByTaskR.put(i, relatedsimTraces);
            dataBydelayedTasks.put(i, delayDueTosimTraces);
            timeDelayedPerRow.put(i, runnableTimePerDevice);
            // dataByTask[i][5] = list.getModel();
            // dataByTask[i][6] = totalTime;

    // fill the detailed latency table once a row is selected
    public Object[][] getTaskByRowDetails(int row) {
        Object[][] dataByTaskRowDetails = new Object[dataByTaskR.get(row).size()][5];
        int i = 0;

        for (SimulationTransaction st : dataByTaskR.get(row)) {
            dataByTaskRowDetails[i][0] = st.command;
            dataByTaskRowDetails[i][1] = nameIDTaskList.get(st.id);
            dataByTaskRowDetails[i][2] = st.deviceName;
            dataByTaskRowDetails[i][3] = Integer.valueOf(st.startTime);
            dataByTaskRowDetails[i][4] = Integer.valueOf(st.endTime);
            i++;
        }

        return dataByTaskRowDetails;
    }

    // fill the detailed latency table once a row is selected
    public List<SimulationTransaction> getRowDetailsTaks(int row) {

        return dataByTaskR.get(row);
    }

    // fill the detailed latency table once a row is selected
    public List<SimulationTransaction> getRowDetailsByHW(int row) {

        return dataBydelayedTasks.get(row);
    }

    // fill the detailed latency table once a row is selected
    public HashMap<String, ArrayList<ArrayList<Integer>>> getRowDelayDetailsByHW(int row) {

        return timeDelayedPerRow.get(row);
    }

    // fill the detailed latency table once a row is selected from min/max table
    public Vector<SimulationTransaction> getMinMaxTasksByRow(int row) {

        return relatedsimTraces;
    }

    // fill the tasks that run on the same hardware but don't belong to the path
    // between selected activities
    public Vector<SimulationTransaction> getTaskMinMaxHWByRowDetails(int row) {

        return delayDueTosimTraces;
    }

    // get the details of the delay for a selected min or max delay row
    public void getRowDetailsMinMax(int row) {

        String task12 = (String) dataByTaskMinMax[row][0];
        int minTime = (int) dataByTaskMinMax[row][1];
        String task22 = (String) dataByTaskMinMax[row][2];
        int maxTime = (int) dataByTaskMinMax[row][3];

        HashMap<String, ArrayList<SimulationTransaction>> relatedHWs = new HashMap<String, ArrayList<SimulationTransaction>>();
        HashMap<String, ArrayList<SimulationTransaction>> relatedTasks = new HashMap<String, ArrayList<SimulationTransaction>>();
        relatedsimTraces = new Vector<SimulationTransaction>();
        delayDueTosimTraces = new Vector<SimulationTransaction>();
        runnableTimePerDevice = new HashMap<String, ArrayList<ArrayList<Integer>>>();

        // AllDirectedPaths<String, DefaultEdge> allPaths = new AllDirectedPaths<String,
        // DefaultEdge>(g);

        // List<GraphPath<String, DefaultEdge>> path = allPaths.getAllPaths(task12,
        // task22, false, g.vertexSet().size());

        // int size = path.size();

        GraphPath<String, DefaultEdge> path2 = DijkstraShortestPath.findPathBetween(g, task12, task22);

        if (path2 != null && path2.getLength() > 0) {

            for (Entry<String, ArrayList<String>> entry : channelPaths.entrySet()) {

                String ChannelName = entry.getKey();
                ArrayList<String> busChList = entry.getValue();

                GraphPath<String, DefaultEdge> pathTochannel = DijkstraShortestPath.findPathBetween(g, task12, ChannelName);
                GraphPath<String, DefaultEdge> pathFromChannel = DijkstraShortestPath.findPathBetween(g, ChannelName, task22);

                if (pathTochannel != null && pathTochannel.getLength() > 0 && pathFromChannel != null && pathFromChannel.getLength() > 0) {

                    devicesToBeConsidered.addAll(busChList);

                }

            }

        } else {

            for (Entry<String, ArrayList<String>> entry : channelPaths.entrySet()) {

                String ChannelName = entry.getKey();
                ArrayList<String> busChList = entry.getValue();

                GraphPath<String, DefaultEdge> pathTochannel = DijkstraShortestPath.findPathBetween(g, task12, ChannelName);
                GraphPath<String, DefaultEdge> pathFromChannel = DijkstraShortestPath.findPathBetween(g, ChannelName, task22);

                if ((pathTochannel != null && pathTochannel.getLength() > 0) || (pathFromChannel != null && pathFromChannel.getLength() > 0)) {

                    devicesToBeConsidered.addAll(busChList);

                }

            }

        }

        for (SimulationTransaction st : transFile) {
            Boolean onPath = false;

            if (!(Integer.valueOf(st.startTime) < minTime && Integer.valueOf(st.endTime) < minTime)
                    && !(Integer.valueOf(st.startTime) > maxTime && Integer.valueOf(st.endTime) > maxTime)) {

maysam zoor's avatar
maysam zoor committed
                // if (Integer.valueOf(st.startTime) >= minTime && Integer.valueOf(st.startTime)
                // < maxTime) {

                if (Integer.valueOf(st.endTime) > maxTime) {
                    st.endTime = Integer.valueOf(maxTime).toString();
                    st.length = Integer.valueOf(Integer.valueOf(maxTime) - Integer.valueOf(st.startTime)).toString();
                }
maysam zoor's avatar
maysam zoor committed

                if (Integer.valueOf(st.startTime) < minTime) {
                    st.startTime = Integer.valueOf(minTime).toString();
maysam zoor's avatar
maysam zoor committed
                    st.length = Integer.valueOf(Integer.valueOf(st.endTime) - Integer.valueOf(minTime)).toString();
maysam zoor's avatar
maysam zoor committed

                if (Integer.valueOf(st.startTime) < minTime && Integer.valueOf(st.endTime) > maxTime) {
                    st.startTime = Integer.valueOf(minTime).toString();
                    st.endTime = Integer.valueOf(maxTime).toString();
                    st.length = Integer.valueOf(Integer.valueOf(maxTime) - Integer.valueOf(minTime)).toString();
                }
                for (String tasknameCheck : g.vertexSet()) {
                    String[] taskToAdd = tasknameCheck.split("__");

                    int taskToAddindex = taskToAdd.length;

                    String taskToAddid = taskToAdd[taskToAddindex - 1];
                    if (isNumeric(taskToAddid)) {
                        if (Integer.valueOf(taskToAddid).equals(Integer.valueOf(st.id))) {

                            taskname = tasknameCheck;

                String[] name = st.deviceName.split("_");
                String deviceName = name[0];

                // there is a path between task 1 and task 2
                if (path2 != null && path2.getLength() > 0) {
                    if (!taskname.equals(null) && !taskname.equals("")) {

                        GraphPath<String, DefaultEdge> pathToOrigin = DijkstraShortestPath.findPathBetween(g, task12, taskname);
                        GraphPath<String, DefaultEdge> pathToDestination = DijkstraShortestPath.findPathBetween(g, taskname, task22);

                        if (taskname.equals(task12) || taskname.equals(task22) || (pathToOrigin != null && pathToOrigin.getLength() > 0
                                && pathToDestination != null && pathToDestination.getLength() > 0)) {

                            relatedsimTraces.add(st);

                            ArrayList<Integer> timeValues = new ArrayList<Integer>();
                            timeValues.add(0, Integer.valueOf(st.runnableTime));
                            timeValues.add(1, Integer.valueOf(st.startTime));

                            if (!(st.runnableTime).equals(st.startTime)) {

                                if (runnableTimePerDevice.containsKey(st.deviceName)) {

                                    if (!runnableTimePerDevice.get(st.deviceName).contains(timeValues)) {
                                        runnableTimePerDevice.get(st.deviceName).add(timeValues);
                                    }
                                } else {

                                    ArrayList<ArrayList<Integer>> timeValuesList = new ArrayList<ArrayList<Integer>>();
                                    timeValuesList.add(timeValues);

                                    runnableTimePerDevice.put(st.deviceName, timeValuesList);

                                }

                            }

                        } else if (((st.deviceName.equals(task2DeviceName)) || st.deviceName.equals(task1DeviceName)
                                || devicesToBeConsidered.contains(deviceName)) && !st.id.equals(idTask1) && !st.id.equals(idTask2)) {
                    timeDelayedPerRow.put(row, runnableTimePerDevice);

                } else {
                    if (!taskname.equals(null) && !taskname.equals("")) {

                        GraphPath<String, DefaultEdge> pathExistsTestwithTask1 = DijkstraShortestPath.findPathBetween(g, task12, taskname);
                        GraphPath<String, DefaultEdge> pathExistsTestwithTask2 = DijkstraShortestPath.findPathBetween(g, taskname, task22);

                        if (pathExistsTestwithTask1 != null && pathExistsTestwithTask1.getLength() > 0
                                || pathExistsTestwithTask2 != null && pathExistsTestwithTask2.getLength() > 0) {
                            relatedsimTraces.add(st);

                        } else if (((st.deviceName.equals(task2DeviceName)) || st.deviceName.equals(task1DeviceName)
                                || devicesToBeConsidered.contains(deviceName)) && !st.id.equals(idTask1) && !st.id.equals(idTask2)) {
                            delayDueTosimTraces.add(st);

                        }

                    }

                }

            }
        }

    }

    // fill the tasks that run on the same hardware but don't belong to the path
    // between selected activities
    public Object[][] getTaskHWByRowDetails(int row) {

        Object[][] dataByTaskRowDetails = new Object[dataBydelayedTasks.get(row).size()][6];

        int i = 0;

        for (SimulationTransaction st : dataBydelayedTasks.get(row)) {

            dataByTaskRowDetails[i][0] = st.command;
            dataByTaskRowDetails[i][1] = nameIDTaskList.get(st.id);
            dataByTaskRowDetails[i][2] = st.deviceName;
            dataByTaskRowDetails[i][3] = Integer.valueOf(st.startTime);
            dataByTaskRowDetails[i][4] = Integer.valueOf(st.endTime);

            HashMap<String, ArrayList<ArrayList<Integer>>> delayTime = timeDelayedPerRow.get(row);
            boolean causeDelay = false;
            if (delayTime.containsKey(st.deviceName)) {
                for (Entry<String, ArrayList<ArrayList<Integer>>> entry : delayTime.entrySet()) {
                    if (entry.getKey().equals(st.deviceName)) {
                        ArrayList<ArrayList<Integer>> timeList = entry.getValue();
                        for (int j = 0; j < timeList.size(); j++) {
                            if (Integer.valueOf(st.startTime) > timeList.get(j).get(0) && Integer.valueOf(st.startTime) < timeList.get(j).get(1)) {
            dataByTaskRowDetails[i][5] = causeDelay;
        return dataByTaskRowDetails;
    // fill the Min max delay table on main latency analysis frame
    public Object[][] latencyMinMaxAnalysis(String task12ID, String task22ID, Vector<SimulationTransaction> transFile1) {
        List<Integer> times1MinMAx = new ArrayList<Integer>();
        List<Integer> times2MinMAx = new ArrayList<Integer>();

        String[] task1 = task12ID.split("__");

        int task1index = task1.length;

        idTask1 = task1[task1index - 1];

        String[] task2 = task22ID.split("__");

        int task2index = task2.length;

        idTask2 = task2[task2index - 1];

        String task12 = nameIDTaskList.get(idTask1);
        String task22 = nameIDTaskList.get(idTask2);

        times1MinMAx = times1;
        times2MinMAx = times2;

        HashMap<Integer, ArrayList<Integer>> minTimes = new HashMap<Integer, ArrayList<Integer>>();

        for (int time1 : times1MinMAx) {
            int match = Integer.MAX_VALUE;
            // Find the first subsequent transaction
            int time = Integer.MAX_VALUE;
            for (int time2 : times2MinMAx) {

                int diff = time2 - time1;
                if (diff < time && diff >= 0) {
                    time = diff;
                    match = time2;
                }
            }
            try {
                if (times2MinMAx.contains(match)) {
                    times2MinMAx.remove(Integer.valueOf(match));
                }
            } catch (Exception e) {
            }
            if (time != Integer.MAX_VALUE) {
                ArrayList<Integer> startEndT = new ArrayList<Integer>();
                startEndT.add(time1);
                startEndT.add(match);
                minTimes.put(time, startEndT);
            }
        }
        dataByTaskMinMax = new Object[2][5];

        if (minTimes.size() > 0) {
            Integer min = Collections.min(minTimes.keySet());
            Integer max = Collections.max(minTimes.keySet());

            dataByTaskMinMax = new Object[2][5];

            ArrayList<Integer> numMax = minTimes.get(max);
            ArrayList<Integer> numMin = minTimes.get(min);

            dataByTaskMinMax[0][0] = task12;
            dataByTaskMinMax[0][1] = numMin.get(0);
            dataByTaskMinMax[0][2] = task22;
            dataByTaskMinMax[0][3] = numMin.get(1);
            dataByTaskMinMax[0][4] = min;

            dataByTaskMinMax[1][0] = task12;
            dataByTaskMinMax[1][1] = numMax.get(0);
            dataByTaskMinMax[1][2] = task22;
            dataByTaskMinMax[1][3] = numMax.get(1);
            dataByTaskMinMax[1][4] = max;

        }

        return dataByTaskMinMax;
    }

    // fill the detailed latency table once a row is selected from min/max table
    public Object[][] getTasksByRowMinMax(int row) {
        Object[][] dataByTaskRowDetails = new Object[relatedsimTraces.size()][5];

        int i = 0;

        for (SimulationTransaction st : relatedsimTraces) {

            dataByTaskRowDetails[i][0] = st.command;
            dataByTaskRowDetails[i][1] = nameIDTaskList.get(st.id);
            dataByTaskRowDetails[i][2] = st.deviceName;
            dataByTaskRowDetails[i][3] = Integer.valueOf(st.startTime);
            dataByTaskRowDetails[i][4] = Integer.valueOf(st.endTime);
            i++;
        }

        return dataByTaskRowDetails;
    }

    // fill the tasks that run on the same hardware but don't belong to the path
    // between selected activities
    public Object[][] getTaskHWByRowDetailsMinMax(int row) {
        Object[][] dataByTaskRowDetails = new Object[delayDueTosimTraces.size()][5];

        int i = 0;

        for (SimulationTransaction st : delayDueTosimTraces) {

            dataByTaskRowDetails[i][0] = st.command;
            dataByTaskRowDetails[i][1] = nameIDTaskList.get(st.id);
            dataByTaskRowDetails[i][2] = st.deviceName;
            dataByTaskRowDetails[i][3] = Integer.valueOf(st.startTime);
            dataByTaskRowDetails[i][4] = Integer.valueOf(st.endTime);
            i++;
        }

        return dataByTaskRowDetails;
    }

    // import graph in .graphml format
    public void importGraph(String filename) throws ExportException, IOException, ImportException {

        FileReader ps = new FileReader(filename + ".graphml");
        // gmlExporter.exportGraph(g, PS);

        // FileWriter PS2 = new FileWriter(filename + "test.graphml");

        VertexProvider<String> vertexProvider = (id, attributes) -> {
            String cv = new String(id);
            return cv;
        };

        EdgeProvider<String, DefaultEdge> edgeProvider = (from, to, label, attributes) -> new DefaultEdge();

        GraphMLImporter<String, DefaultEdge> importer = new GraphMLImporter<String, DefaultEdge>(vertexProvider, edgeProvider);

        Graph<String, DefaultEdge> importedGraph = null;

        importer.importGraph(importedGraph, ps);

    }

maysam zoor's avatar
maysam zoor committed
    public List<TMLComponentDesignPanel> getCpanels() {
        return cpanels;
    }

    public void setCpanels(List<TMLComponentDesignPanel> cpanels) {
        this.cpanels = cpanels;
    }