OperatorInfoMetric.java 3.0 KB

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