Skip to content
Snippets Groups Projects
DirectedGraphTranslator.java 107 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 java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilterWriter;
import java.io.IOException;
import java.io.Writer;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Vector;

import javax.imageio.ImageIO;
import javax.swing.DefaultListModel;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;

import org.apache.commons.math3.geometry.spherical.twod.Vertex;
import org.apache.derby.tools.sysinfo;
import org.graphstream.graph.Edge;
import org.jgrapht.Graph;
import org.jgrapht.GraphPath;
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.ComponentNameProvider;
import org.jgrapht.io.EdgeProvider;
import org.jgrapht.io.ExportException;
import org.jgrapht.io.GraphImporter;
import org.jgrapht.io.GraphMLExporter;
import org.jgrapht.io.GraphMLImporter;
import org.jgrapht.io.ImportException;
import org.jgrapht.io.VertexProvider;

import com.mxgraph.layout.mxCircleLayout;
import com.mxgraph.layout.mxIGraphLayout;
import com.mxgraph.layout.hierarchical.mxHierarchicalLayout;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.util.mxCellRenderer;
import com.sun.prism.paint.Color;

import tmltranslator.HwA;
import tmltranslator.HwCommunicationNode;
import tmltranslator.HwLink;
import tmltranslator.HwNode;
import tmltranslator.TMLActivity;
import tmltranslator.TMLActivityElement;
import tmltranslator.TMLChannel;
import tmltranslator.TMLElement;
import tmltranslator.TMLError;
import tmltranslator.TMLMapping;
import tmltranslator.TMLReadChannel;
import tmltranslator.TMLRequest;
import tmltranslator.TMLSendEvent;
import tmltranslator.TMLTask;
import tmltranslator.TMLWaitEvent;
import tmltranslator.TMLWriteChannel;
import tmltranslator.tomappingsystemc2.DiploSimulatorCodeGenerator;
import ui.TGComponent;
import ui.TGConnectingPoint;
import ui.TGConnector;
import ui.TMLComponentDesignPanel;
import ui.interactivesimulation.SimulationTransaction;
import ui.tmlad.TMLADActionState;
import ui.tmlad.TMLADChoice;
import ui.tmlad.TMLADDecrypt;
import ui.tmlad.TMLADDelay;
import ui.tmlad.TMLADDelayInterval;
import ui.tmlad.TMLADEncrypt;
import ui.tmlad.TMLADExecC;
import ui.tmlad.TMLADExecCInterval;
import ui.tmlad.TMLADExecI;
import ui.tmlad.TMLADExecIInterval;
import ui.tmlad.TMLADForEverLoop;
import ui.tmlad.TMLADForLoop;
import ui.tmlad.TMLADForStaticLoop;
import ui.tmlad.TMLADNotifiedEvent;
import ui.tmlad.TMLADRandom;
import ui.tmlad.TMLADReadChannel;
import ui.tmlad.TMLADReadRequestArg;
import ui.tmlad.TMLADSelectEvt;
import ui.tmlad.TMLADSendEvent;
import ui.tmlad.TMLADSendRequest;
import ui.tmlad.TMLADSequence;
import ui.tmlad.TMLADStartState;
import ui.tmlad.TMLADStopState;
import ui.tmlad.TMLADUnorderedSequence;
import ui.tmlad.TMLADWaitEvent;
import ui.tmlad.TMLADWriteChannel;
import ui.tmlcompd.TMLCPrimitivePort;

/**
 * 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;
    private TMLComponentDesignPanel tmlcdp;

    private TMLTask task, task1, task2;

    protected TMLActivity activity;

    // List<HwNode> path;

    private TMLActivityElement currentElement;
    private TMLActivityElement backwardElement;
    private ArrayList<String> SummaryCommMapping;

    private Graph<String, DefaultEdge> g;

    public Graph<String, DefaultEdge> getG() {
        return g;
    }

    public void setG(Graph<String, DefaultEdge> g) {
        this.g = g;
    }

    private static final Dimension DEFAULT_SIZE = new Dimension(530, 320);
    private final 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>> 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>>();

    public HashMap<String, String> getNameIDTaskList() {
        return nameIDTaskList;
    }

    public JScrollPane getScrollPane() {
        return scrollPane;
    }

    public static void setScrollPane(JScrollPane scrollPane) {
        DirectedGraphTranslator.scrollPane = scrollPane;
    }

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

    HashMap<Integer, List<SimulationTransaction>> dataByTaskR = new HashMap<Integer, List<SimulationTransaction>>();
    HashMap<Integer, List<SimulationTransaction>> dataBydelayedTasks = new HashMap<Integer, List<SimulationTransaction>>();
    HashMap<Integer, HashMap<String, ArrayList<ArrayList<Integer>>>> timeDelayedPerRow = new HashMap<Integer, HashMap<String, ArrayList<ArrayList<Integer>>>>();

    HashMap<Integer, List<String>> detailsOfMinMaxRow = new HashMap<Integer, List<String>>();
    HashMap<Integer, List<SimulationTransaction>> dataBydelayedTasksOfMinMAx = new HashMap<Integer, List<SimulationTransaction>>();
    private final JFrame frame = new JFrame("The Sys-ML Model As Directed Graph");

    List<Integer> times1 = new ArrayList<Integer>();
    List<Integer> times2 = new ArrayList<Integer>();

    Vector<SimulationTransaction> transFile;
    String idTask1;
    String idTask2;
    String task2DeviceName = "";
    String task1DeviceName = "";
    ArrayList<String> devicesToBeConsidered = new ArrayList<String>();

    Vector<SimulationTransaction> relatedsimTraces = new Vector<SimulationTransaction>();
    Vector<SimulationTransaction> delayDueTosimTraces = new Vector<SimulationTransaction>();

    HashMap<String, ArrayList<ArrayList<Integer>>> runnableTimePerDevice = new HashMap<String, ArrayList<ArrayList<Integer>>>();

    @SuppressWarnings("deprecation")
    public DirectedGraphTranslator(TMLMapping<TGComponent> tmap1, List<TMLComponentDesignPanel> cpanels1) {

        tmap = tmap1;
        cpanels = cpanels1;

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

        tmlcdp = cpanels.get(0);

        DrawDirectedGraph();

        /*
         * JGraphXAdapter<String, DefaultEdge> graphAdapter = new JGraphXAdapter<String,
         * DefaultEdge>(g);
         * 
         * mxHierarchicalLayout layout = new mxHierarchicalLayout(graphAdapter);
         * 
         * layout.setInterHierarchySpacing(100); layout.setInterRankCellSpacing(100);
         * layout.setIntraCellSpacing(100);
         * 
         * layout.execute(graphAdapter.getDefaultParent());
         * 
         * scrollPane.setViewportView(new mxGraphComponent(graphAdapter));
         * 
         * scrollPane.setVisible(true);
         * 
         * scrollPane.revalidate(); scrollPane.repaint(); frame = new
         * JFrame("The Sys-ML Model As Directed Graph"); frame.add(scrollPane);
         * frame.pack();
         */
        // frame.setVisible(false);

    }

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

    private void DrawDirectedGraph() {

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

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

            g.addVertex(node.getName());

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

            }

        }

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

            g.addVertex(node.getName());

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

            }

        }

        for (HwA node : tmap.getArch().getHwA()) {

            if (tmap.getLisMappedTasks(node).size() > 0) {
                cpuTask.put(node.getName(), tmap.getLisMappedTasks(node));

            }

            cpuTasks = getCPUTaskMap(cpuTask);

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

            // }

        }

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

            g.addVertex(node.getName());

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

            }

        }

        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();
                g.addVertex(ChannelName);
                g.addEdge(busName, ChannelName);

                TMLChannel tmlch = (TMLChannel) busCh;

                String writeChannel = tmlch.getDestinationTask().getName() + "__" + "writechannel:" + tmlch.getDestinationPort();
                String readChannel;

            }

        }

        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();
                g.addVertex(ChannelName);
                g.addEdge(busName, ChannelName);
            }

        }

        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();
                g.addVertex(ChannelName);
                g.addEdge(busName, ChannelName);
            }

        }

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

            if (!g.vertexSet().contains(ch.getName())) {
                g.addVertex(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);
                    }

                    if (!g.containsEdge(node.getName(), ch.getName())) {
                        g.addEdge(node.getName(), ch.getName());
                    }

                }

            }

        }

        SummaryCommMapping = tmap.getSummaryCommMapping();

        for (HwNode node : tmap.getArch().getCPUs()) {
            if (tmap.getLisMappedTasks(node).size() > 0) {
                cpuTask.put(node.getName(), tmap.getLisMappedTasks(node));

            }

            cpuTasks = getCPUTaskMap(cpuTask);

        }

        for (HwLink link : links) {

            if (g.containsVertex(link.hwnode.getName()) && g.containsVertex(link.bus.getName())) {

                g.addEdge(link.hwnode.getName(), link.bus.getName());
                g.addEdge(link.bus.getName(), link.hwnode.getName());
            }

        }

        if (addedEdges.size() > 0) {
            for (Entry<String, String> edge : addedEdges.entrySet()) {
                g.addEdge(edge.getKey(), edge.getValue());

            }
        }

        if (sendEventWaitEventEdges.size() > 0) {
            for (Entry<String, HashSet<String>> edge : sendEventWaitEventEdges.entrySet()) {

                for (String waitEventEdge : edge.getValue())

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

            }
        }
        if (readWriteChannelEdges.size() > 0) {
            for (Entry<String, HashSet<String>> edge : readWriteChannelEdges.entrySet()) {

                for (String readChannelEdge : edge.getValue())

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

            }
        }

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

                for (String sequenceEdge : edge.getValue())

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

            }
        }

        if (unOrderedSequenceEdges.size() > 0) {
            for (Entry<String, HashSet<String>> edge : unOrderedSequenceEdges.entrySet()) {

                for (String sequenceEdge : edge.getValue())

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

            }
        }

        if (requestEdges.size() > 0) {

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

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

                    g.addEdge(edge.getKey(), requestsingleEdges);

                }

            }

        }

    }

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

    public HashMap<String, HashSet<String>> getCPUTaskMap(HashMap<String, HashSet<TMLTask>> cpuTask) {
        HashMap<String, HashSet<String>> cpuTaskMap = new HashMap<String, HashSet<String>>();
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
        if (tmap == null) {
            return cpuTaskMap;
        }

        for (Entry<String, HashSet<TMLTask>> entry : cpuTask.entrySet()) {

            String key = entry.getKey();
            HashSet<TMLTask> value = entry.getValue();
            Vector<TMLActivityElement> multiNexts = new Vector<TMLActivityElement>();
            TMLActivityElement elt;
            // Map <String, String> sendEvt;
            HashMap<String, List<String>> sendEvt = new HashMap<String, List<String>>();
            HashMap<String, List<String>> waitEvt = new HashMap<String, List<String>>();

            HashMap<String, String> sendData = new HashMap<String, String>();
            HashMap<String, String> receiveData = new HashMap<String, String>();

            // GEt List of all requests

            for (TMLTask task : value) {

                if (task.isRequested()) {
                    TMLRequest requestToTask = task.getRequest();

                    requestToTask.getReferenceObject();

                    requestToTask.getDestinationTask();

                    requestToTask.getOriginTasks().get(0);

                    requestToTask.ports.get(0).getName();
                    requestToTask.getExtendedName();

                    String destinationRequest = requestToTask.getDestinationTask().getName() + "__"
                            + requestToTask.getDestinationTask().getActivityDiagram().get(0).getName() + "__"
                            + requestToTask.getDestinationTask().getActivityDiagram().get(0).getID();

                    String destinationRequestName = requestToTask.getDestinationTask().getName();

                    for (TMLTask originTask : requestToTask.getOriginTasks()) {

                        String requestOriginTaskName = originTask.getName();

                        if (requestsOriginDestination.containsKey(requestOriginTaskName)) {
                            if (!requestsOriginDestination.get(requestOriginTaskName).contains(destinationRequestName)) {
                                requestsOriginDestination.get(requestOriginTaskName).add(destinationRequestName);
                            }
                        } else {
                            ArrayList<String> destinationRequestNames = new ArrayList<String>();
                            destinationRequestNames.add(destinationRequestName);
                            requestsOriginDestination.put(requestOriginTaskName, destinationRequestNames);
                        }

                    }

                    for (TMLCPrimitivePort requestsPort : requestToTask.ports) {

                        String requestsPortName = requestsPort.getPortName();

                        if (requestsPorts.containsKey(task.getName())) {
                            if (!requestsPorts.get(task.getName()).contains(requestsPortName)) {
                                requestsPorts.get(task.getName()).add(requestsPortName);
                            }
                        } else {
                            ArrayList<String> requestsPortNames = new ArrayList<String>();
                            requestsPortNames.add(requestsPortName);
                            requestsPorts.put(task.getName(), requestsPortNames);
                        }

                    }

                    if (requestsDestination.containsKey(destinationRequestName)) {
                        if (!requestsDestination.get(destinationRequestName).contains(destinationRequest)) {
                            requestsDestination.get(destinationRequestName).add(destinationRequest);
                        }
                    } else {
                        ArrayList<String> destinationRequestNames = new ArrayList<String>();
                        destinationRequestNames.add(destinationRequest);
                        requestsDestination.put(destinationRequestName, destinationRequestNames);
                    }

                }

            }

            for (TMLTask task : value) {

                for (TMLComponentDesignPanel dpPanel : cpanels) {
                    String[] taskpanel = task.getName().split("__");

                    if (dpPanel.getNameOfTab().equals(taskpanel[0])) {
                        tmlcdp = dpPanel;
                    }

                }
                // get the names and params of send events per task and their corresponding wait
                // events
                for (TMLSendEvent sendEvent : task.getSendEvents()) {
                    TMLCPrimitivePort sendingPortdetails = sendEvent.getEvent().port;
                    TMLCPrimitivePort receivePortdetails = sendEvent.getEvent().port2;

                    String sendingPortparams = sendEvent.getAllParams();

                    TMLTask destinationTasks = sendEvent.getEvent().getDestinationTask();

                    sendEvt.put("sendevent:" + sendingPortdetails.getPortName() + "(" + sendingPortparams + ")", new ArrayList<String>());

                    for (TMLWaitEvent wait_sendEvent : destinationTasks.getWaitEvents()) {
                        String receivePortparams = wait_sendEvent.getAllParams();

                        sendEvt.get("sendevent:" + sendingPortdetails.getPortName() + "(" + sendingPortparams + ")")
                                .add("waitevent:" + receivePortdetails.getPortName() + "(" + receivePortparams + ")");

                    }

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

                for (TMLReadChannel readChannel : task.getReadChannels()) {

                    int i = readChannel.getNbOfChannels();

                    for (int j = 0; j < i; j++) {

                        String sendingDataPortdetails = readChannel.getChannel(j).getOriginPort().getName();
                        String receiveDataPortdetails = readChannel.getChannel(j).getDestinationPort().getName();

                        if (!sendingDataPortdetails.equals(receiveDataPortdetails)) {
                            receiveData.put(receiveDataPortdetails, sendingDataPortdetails);

                        }

                    }

                }
                // get the names of write channels per task and their corresponding read
                // channels
                for (TMLWriteChannel writeChannel : task.getWriteChannels()) {

                    int i = writeChannel.getNbOfChannels();

                    for (int j = 0; j < i; j++) {

                        // writeChannel.getChannel(j);
                        String sendingDataPortdetails = writeChannel.getChannel(j).getOriginPort().getName();
                        String receiveDataPortdetails = writeChannel.getChannel(j).getDestinationPort().getName();

                        if (!sendingDataPortdetails.equals(receiveDataPortdetails)) {

                            sendData.put(sendingDataPortdetails, receiveDataPortdetails);
                        }

                    }

                }
                // get the names and params of wait events per task and their corresponding send
                // events

                for (TMLWaitEvent waitEvent : task.getWaitEvents()) {
                    // TMLCPrimitivePort portdetails = waitEvent.getEvent().port;
                    TMLCPrimitivePort sendingPortdetails = waitEvent.getEvent().port;
                    TMLCPrimitivePort receivePortdetails = waitEvent.getEvent().port2;

                    String receivePortparams = waitEvent.getAllParams();

                    // tmlcdp.tmlctdp.getAllPortsConnectedTo(portdetails);

                    waitEvt.put("waitevent:" + receivePortdetails.getPortName() + "(" + receivePortparams + ")", new ArrayList<String>());

                    TMLTask originTasks = waitEvent.getEvent().getOriginTask();

                    for (TMLSendEvent wait_sendEvent : originTasks.getSendEvents()) {

                        String sendingPortparams = wait_sendEvent.getAllParams();

                        waitEvt.get("waitevent:" + receivePortdetails.getPortName() + "(" + receivePortparams + ")")
                                .add("sendevent:" + sendingPortdetails.getPortName() + "(" + sendingPortparams + ")");

                    }

                }

                // add the name of the task as a vertex
                g.addVertex(key);
                g.addVertex(task.getName());

                g.addEdge(key, task.getName());

                activity = task.getActivityDiagram();
                int count = 1;
                currentElement = activity.getFirst();
                String taskStartName = "";
                String taskEndName = "";

                int countTillStart = 0;
                boolean hasSequence = false;
                boolean hasForLoop = false;

                HashMap<String, List<String>> forLoopNextValues = new HashMap<String, List<String>>();

                // loop over all the activites corresponding to a task
                while (count <= activity.nElements()) {

                    String eventName;
                    String preEventName;

                    if (currentElement.getName().equals("Stop after infinite loop")) {
                        count++;

                        if (count <= 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.getReferenceObject() instanceof TMLADRandom) {
                        eventName = task.getName() + "__" + currentElement.getName() + "__" + currentElement.getID();

                    } else {
                        eventName = task.getName() + "__" + currentElement.getReferenceObject().toString() + "__" + currentElement.getID();

                    }

                    if (currentElement.getNexts().size() > 1) {
                        for (TMLActivityElement ae : currentElement.getNexts()) {
                            multiNexts.add(ae);

                        }

                    }

                    // in case an end was encountered , the previous activities should be checked:
                    // in
                    // case it is an end for a loop or sequence speavial edges should be added

                    if (currentElement.getReferenceObject() instanceof TMLADStopState) {

                        taskEndName = task.getName() + "__" + currentElement.getName() + "__" + currentElement.getID();

                        preEventName = task.getName() + "__" + activity.getPrevious(currentElement).getReferenceObject().toString() + "__"
                                + activity.getPrevious(currentElement).getID();

                        g.addVertex(taskEndName);
                        // allTasks.add(taskEndName);

                        if (!(activity.getPrevious(currentElement).getReferenceObject() instanceof TMLADSequence)) {
                            g.addEdge(preEventName, taskEndName);
                        }

                        @SuppressWarnings({ "unchecked", "rawtypes" })
                        AllDirectedPaths<String, DefaultEdge> allPaths = new AllDirectedPaths<String, DefaultEdge>(g);
                        if (orderedSequenceList.size() > 0) {

                            int noForLoop = 0;
                            // get path from sequence to end
                            for (Entry<String, ArrayList<String>> sequenceListEntry : orderedSequenceList.entrySet()) {

                                int directlyConnectedSeq = 0;

                                if (g.containsVertex(sequenceListEntry.getKey())) {

                                    List<GraphPath<String, DefaultEdge>> path = allPaths.getAllPaths(sequenceListEntry.getKey(), taskEndName, false,
                                            g.vertexSet().size());

                                    for (Entry<String, ArrayList<String>> othersequenceListEntryValue : orderedSequenceList.entrySet()) {

                                        for (int i = 0; i < path.size(); i++) {

                                            if (!othersequenceListEntryValue.getKey().equals(sequenceListEntry.getKey())) {

                                                if (path.get(i).getVertexList().contains(othersequenceListEntryValue.getKey())) {

                                                    directlyConnectedSeq++;

                                                }
                                            }
                                        }
                                    }

                                    if (path.size() > 0 && sequenceListEntry.getValue().size() > 0 && directlyConnectedSeq == 0) {

                                        for (int i = 0; i < path.size(); i++) {

                                            for (String sequenceListEntryValue : sequenceListEntry.getValue()) {

                                                if (g.containsVertex(sequenceListEntryValue)) {

                                                    if (path.get(i).getVertexList().contains(sequenceListEntryValue)) {

                                                        if (forLoopNextValues.size() > 0) {

                                                            for (Entry<String, List<String>> forloopListEntry : forLoopNextValues.entrySet()) {

                                                                if (path.get(i).getVertexList().contains(forloopListEntry.getValue().get(0))) {

                                                                    noForLoop++;
                                                                }
                                                            }
                                                        }

                                                        if (forEverLoopList.size() > 0) {

                                                            for (String forloopListEntry : forEverLoopList) {

                                                                if (path.get(i).getVertexList().contains(forloopListEntry)) {

                                                                    noForLoop++;
                                                                }
                                                            }
                                                        }

                                                        if (noForLoop == 0) {

                                                            int nextIndex = sequenceListEntry.getValue().indexOf(sequenceListEntryValue) + 1;

                                                            if (nextIndex < sequenceListEntry.getValue().size()) {

                                                                HashSet<String> endSequenceVertex = new HashSet<String>();
                                                                endSequenceVertex.add(sequenceListEntry.getValue().get(nextIndex));

                                                                if (sequenceEdges.containsKey(taskEndName)) {

                                                                    if (!sequenceEdges.get(taskEndName)
                                                                            .contains(sequenceListEntry.getValue().get(nextIndex))) {
                                                                        sequenceEdges.get(taskEndName)
                                                                                .add(sequenceListEntry.getValue().get(nextIndex));
                                                                    }

                                                                } else {

                                                                    sequenceEdges.put(eventName, endSequenceVertex);

                                                                }

                                                            } else if (nextIndex == sequenceListEntry.getValue().size()
                                                                    && orderedSequenceList.size() > 1) {

                                                                for (Entry<String, ArrayList<String>> othersequenceListEntryValue : orderedSequenceList
                                                                        .entrySet()) {

                                                                    if (!othersequenceListEntryValue.getKey().equals(sequenceListEntry.getKey())) {

                                                                        int connectedSeq = 0;

                                                                        List<GraphPath<String, DefaultEdge>> pathBetweenSeq = allPaths.getAllPaths(
                                                                                othersequenceListEntryValue.getKey(), taskEndName, false,
                                                                                g.vertexSet().size());

                                                                        for (int j = 0; j < pathBetweenSeq.size(); j++) {

                                                                            for (Entry<String, ArrayList<String>> adjacentsequenceListEntryValue : orderedSequenceList
                                                                                    .entrySet()) {
                                                                                if (!adjacentsequenceListEntryValue.getKey()
                                                                                        .equals(sequenceListEntry.getKey())
                                                                                        && !adjacentsequenceListEntryValue.getKey()
                                                                                                .equals(othersequenceListEntryValue.getKey())) {

                                                                                    if (path.get(i).getVertexList()
                                                                                            .contains(adjacentsequenceListEntryValue)) {

                                                                                        connectedSeq++;

                                                                                    }

                                                                                }
                                                                            }

                                                                        }

                                                                        if (connectedSeq == 0 && pathBetweenSeq.size() > 0) {

                                                                            for (String othersequenceListValue : othersequenceListEntryValue
                                                                                    .getValue()) {

                                                                                List<GraphPath<String, DefaultEdge>> pathToNextValue = allPaths
                                                                                        .getAllPaths(othersequenceListValue, taskEndName, false,
                                                                                                g.vertexSet().size());

                                                                                if (pathToNextValue.size() > 0)

                                                                                {

                                                                                    int nextAdjIndex = othersequenceListEntryValue.getValue()
                                                                                            .indexOf(othersequenceListValue) + 1;

                                                                                    if (nextAdjIndex < othersequenceListEntryValue.getValue()
                                                                                            .size()) {

                                                                                        HashSet<String> nextSequenceVertex = new HashSet<String>();
                                                                                        nextSequenceVertex.add(othersequenceListEntryValue.getValue()
                                                                                                .get(nextAdjIndex));

                                                                                        if (sequenceEdges.containsKey(taskEndName)) {

                                                                                            if (!sequenceEdges.get(taskEndName)
                                                                                                    .contains(othersequenceListEntryValue.getValue()
                                                                                                            .get(nextAdjIndex))) {
                                                                                                sequenceEdges.get(taskEndName)
                                                                                                        .add(othersequenceListEntryValue.getValue()
                                                                                                                .get(nextAdjIndex));
                                                                                            }

                                                                                        } else {

                                                                                            sequenceEdges.put(eventName, nextSequenceVertex);

                                                                                        }
                                                                                    }

                                                                                }

                                                                            }

                                                                        }

                                                                    }

                                                                }
                                                            }

                                                        }

                                                    }

                                                }

                                            }

                                        }

                                    }

                                }
                            }

                        }

                        if (unOrderedSequenceList.size() > 0) {

                            // get path from sequence to end
                            for (Entry<String, ArrayList<String>> sequenceListEntry : unOrderedSequenceList.entrySet()) {

                                if (g.containsVertex(sequenceListEntry.getKey())) {

                                    int noForLoop = 0;

                                    List<GraphPath<String, DefaultEdge>> path = allPaths.getAllPaths(sequenceListEntry.getKey(), taskEndName, false,
                                            g.vertexSet().size());

                                    for (int i = 0; i < path.size(); i++) {

                                        if (path.size() > 0 && sequenceListEntry.getValue().size() > 0) {

                                            if (forLoopNextValues.size() > 0) {

                                                for (Entry<String, List<String>> forloopListEntry : forLoopNextValues.entrySet()) {

                                                    if (path.get(i).getVertexList().contains(forloopListEntry.getKey())) {

                                                        noForLoop++;
                                                    }
                                                }
                                            }

                                            if (forEverLoopList.size() > 0) {

                                                for (String forloopListEntry : forEverLoopList) {

                                                    if (path.get(i).getVertexList().contains(forloopListEntry)) {

                                                        noForLoop++;
                                                    }
                                                }
                                            }