Commit 64eb5e2f authored by Javier Costa's avatar Javier Costa
Browse files

Fixed errors on compile graphviz

parent eeb6ff0e
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -47,13 +47,8 @@ public class Main {
                "*         GRAPHVIZ         *\n" +
                "****************************"
        );
//        Graphviz.fromString(graph.toGraphvizRepresentation()).render(Format.PNG).toFile(new File("graph"));
        Logger.log(graph.toGraphvizRepresentation());
        Logger.log();
//        for (Vertex<?, ?> vertex : graph.getVerticies()) {
//            PDGNode node = (PDGNode) vertex;
//            Logger.format("node %s. Level %s\n", node.getId(), node.getLevel());
//        }
        Logger.format("Done in %.2f ms", (tt - t0) / 10e6);
    }

+22 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@ package tfm.arcs;
import tfm.arcs.data.ArcData;
import tfm.nodes.Node;

import java.util.Objects;

public abstract class Arc<D extends ArcData> extends edg.graphlib.Arrow<String, D> {

    @SuppressWarnings("unchecked")
@@ -34,4 +36,24 @@ public abstract class Arc<D extends ArcData> extends edg.graphlib.Arrow<String,
                to.getId()
        );
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getData()) + getFrom().hashCode() + getTo().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;

        if (!(o instanceof Arc))
            return false;

        Arc arc = (Arc) o;

        return Objects.equals(arc.getData(), getData()) &&
                Objects.equals(arc.getFrom(), getFrom()) &&
                Objects.equals(arc.getTo(), getTo());
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ public class DataDependencyArc extends Arc<VariableArcData> {

    @Override
    public String toGraphvizRepresentation() {
        return String.format("%s [style=dashed, color=red, label=\"%s\"]", super.toGraphvizRepresentation(), getData().toString());
        return String.format("%s [style=dashed, color=red, label=\"%s\"];", super.toGraphvizRepresentation(), getData().toString());
    }
}
+39 −0
Original line number Diff line number Diff line
package tfm.graphs;

import com.github.javaparser.ast.stmt.Statement;
import edg.graphlib.Arrow;
import edg.graphlib.Vertex;
import tfm.arcs.Arc;
import tfm.arcs.data.ArcData;
import tfm.nodes.Node;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
@@ -41,6 +44,42 @@ public abstract class Graph<NodeType extends Node> extends edg.graphlib.Graph<St
        super();
    }

    @Override
    /*
      Library fix: if a node had an edge to itself resulted in 2 outgoing nodes instead of 1 outgoing and 1 incoming
     */
    public boolean addEdge(Arrow<String, ArcData> arrow) {
        Vertex<String, ArcData> from = arrow.getFrom();
        Vertex<String, ArcData> to = arrow.getTo();
        int cost = arrow.getCost();
        ArcData data = arrow.getData();

        if (!verticies.contains(from))
            throw new IllegalArgumentException("from is not in graph");
        if (!verticies.contains(to))
            throw new IllegalArgumentException("to is not in graph");

        List<Arrow<String, ArcData>> es2 = from.findEdges(to);

        for (Arrow<String, ArcData> e2 : es2) {
            if (e2 != null && cost == e2.getCost() &&
                    ((data == null && e2.getData() == null) ||
                            (data != null && data.equals(e2.getData()))))
                return false;
        }

        // FIX
        if (Objects.equals(from, to)) {
            from.getOutgoingArrows().add(arrow);
            from.getIncomingArrows().add(arrow);
        } else {
            from.addEdge(arrow);
            to.addEdge(arrow);
        }
        edges.add(arrow);
        return true;
    }

    @SuppressWarnings("unchecked")
    public NodeType getRootNode() {
        return (NodeType) super.getRootVertex();
+1 −1
Original line number Diff line number Diff line
@@ -113,8 +113,8 @@ public abstract class PDGGraph extends Graph<PDGNode> {
        return "digraph g{" + lineSep +
                "splines=true;" + lineSep +
                nodesDeclaration + lineSep +
                rankedNodes.toString() +
                arrows + lineSep +
                rankedNodes.toString() +
                "}";
    }
}
Loading