OperatorInfoMetric.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package de.tu_darmstadt.informatik.tk.scopviz.metrics;
  2. import java.util.LinkedList;
  3. import java.util.stream.Collectors;
  4. import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
  5. import de.tu_darmstadt.informatik.tk.scopviz.graphs.MappingGraphManager;
  6. import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyEdge;
  7. import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
  8. import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyNode;
  9. import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
  10. import de.tu_darmstadt.informatik.tk.scopviz.metrics.interfaces.ScopvizGraphMetric;
  11. import javafx.util.Pair;
  12. /**
  13. * Class to show Information about the different Operator Graphs, implemented as
  14. * a metric. For each Operator Graph, this shows its priority and whether it was
  15. * fully placed.
  16. *
  17. * @author Jan Enders
  18. * @version 1.0
  19. *
  20. */
  21. public class OperatorInfoMetric implements ScopvizGraphMetric {
  22. @Override
  23. public boolean isSetupRequired() {
  24. return false;
  25. }
  26. @Override
  27. public String getName() {
  28. return "Operator Info";
  29. }
  30. @Override
  31. public void setup() {
  32. // No Setup needed.
  33. }
  34. @Override
  35. public LinkedList<Pair<String, String>> calculate(MyGraph g) {
  36. LinkedList<Pair<String, String>> result = new LinkedList<Pair<String, String>>();
  37. for (MyGraph subGraph : g.getAllSubGraphs()) {
  38. if ((subGraph.getAttribute("layer").equals("OPERATOR")
  39. || subGraph.getAttribute("layer").equals(Layer.OPERATOR)) && !subGraph.isComposite()) {
  40. Debug.out("no problems");
  41. String graphId = subGraph.getId();
  42. String info = "";
  43. Double priority = Double.valueOf(subGraph.getAttribute("priority"));
  44. boolean placed = fullyPlaced(subGraph, g);
  45. info = info.concat("Priority: " + priority.doubleValue());
  46. if (placed) {
  47. info = info.concat(", fully placed.");
  48. } else {
  49. info = info.concat(", not fully placed.");
  50. }
  51. result.add(new Pair<String, String>(graphId, info));
  52. }
  53. }
  54. return result;
  55. }
  56. /**
  57. * Checks whether an operator Graph is fully mapped onto the underlay.
  58. *
  59. * @param operator
  60. * the operator Graph
  61. * @param mapping
  62. * the mapping Graph
  63. * @return true if all Nodes of the operator Graph have a valid mapping
  64. */
  65. private boolean fullyPlaced(MyGraph operator, MyGraph mapping) {
  66. boolean result = true;
  67. LinkedList<MyEdge> mappingEdges = new LinkedList<MyEdge>(mapping.<MyEdge>getEdgeSet().stream()
  68. .filter(e -> (((Boolean) e.getAttribute(MappingGraphManager.ATTRIBUTE_KEY_MAPPING)) == true))
  69. .collect(Collectors.toList()));
  70. // build list of the operator nodes within the mapping graph
  71. LinkedList<MyNode> operatorNodes = new LinkedList<MyNode>();
  72. for (MyNode n : mapping.<MyNode>getNodeSet()) {
  73. String originalGraph = n.getAttribute("originalGraph");
  74. if ((originalGraph != null && originalGraph.equals(operator.getId()))
  75. || n.getAttribute(MappingGraphManager.ATTRIBUTE_KEY_MAPPING_PARENT_ID).equals(operator.getId())) {
  76. operatorNodes.add(n);
  77. }
  78. }
  79. // check if they have a mapping
  80. for (MyNode n : operatorNodes) {
  81. boolean isMapped = false;
  82. for (MyEdge e : mappingEdges) {
  83. if (e.getNode0().getId().equals(n.getId())) {
  84. isMapped = true;
  85. }
  86. }
  87. if (!isMapped) {
  88. result = false;
  89. }
  90. }
  91. return result;
  92. }
  93. }