OperatorInfoMetric.java 2.9 KB

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