OperatorInfoMetric.java 3.1 KB

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