Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. * Gets called after the RoBDD was created with the information stored in the
  2. * syntax tree. Starts with the last func and recursively calls the Then- and
  3. * Else- funcs
  4. */
  5. private void visualizeRoBDD() {
  6. RoBDD.Func func = m_model.getRob().m_lastFunc;
  7. helperRoBDD(func, null, false);
  8. m_connector.improveLayout();
  9. }
  10.  
  11. private void helperRoBDD(RoBDD.Func func, RoBDD.Func fromFunc, boolean isThen) {
  12. /*
  13. * In case there are multiple funcs/nodes with the same variable, to still get
  14. * unique IDs for uDraw, the hashCode of the funcs are added to the var
  15. */
  16. if (fromFunc == null) {
  17. m_connector.addRootRoBDD(m_model.getRob().getKeyFromVar(func.m_ciVar), func.m_ciVar, func.hashCode());
  18. } else {
  19. m_connector.addNodeRoBDD(m_model.getRob().getKeyFromVar(func.m_ciVar), func.m_ciVar, func.hashCode(),
  20. fromFunc.m_ciVar, fromFunc.hashCode(), isThen);
  21. }
  22.  
  23. if (func.m_cThen != null) {
  24. helperRoBDD(func.m_cThen, func, true);
  25. }
  26. if (func.m_cElse != null) {
  27. helperRoBDD(func.m_cElse, func, false);
  28. }
  29. }
  30.  
  31. /*
  32. * always saves the result of genVar or ite in RoBDD.m_lastFunc
  33. */
  34. private RoBDD.Func syntaxTreeToRoBDD(Node n) {
  35. if (n != null) {
  36. switch (n.type()) {
  37.  
  38. case VAR:
  39. m_model.getRob().m_lastFunc = m_model.getRob().genVar(n.name());
  40. return m_model.getRob().m_lastFunc;
  41.  
  42. case NOT:
  43. m_model.getRob().m_lastFunc = m_model.getRob().ite(syntaxTreeToRoBDD(n.left()),
  44. m_model.getRob().m_cFalse, m_model.getRob().m_cTrue);
  45. return m_model.getRob().m_lastFunc;
  46.  
  47. case AND:
  48. // ite(f,g,0)
  49. m_model.getRob().m_lastFunc = m_model.getRob().ite(syntaxTreeToRoBDD(n.left()),
  50. syntaxTreeToRoBDD(n.right()), m_model.getRob().m_cFalse);
  51. return m_model.getRob().m_lastFunc;
  52.  
  53. case OR:
  54. // ite(f,1,g)
  55. m_model.getRob().m_lastFunc = m_model.getRob().ite(syntaxTreeToRoBDD(n.left()),
  56. m_model.getRob().m_cTrue, syntaxTreeToRoBDD(n.right()));
  57. return m_model.getRob().m_lastFunc;
  58.  
  59. case IMPLIES:
  60. // ite(f,g,1)
  61. m_model.getRob().m_lastFunc = m_model.getRob().ite(syntaxTreeToRoBDD(n.left()),
  62. syntaxTreeToRoBDD(n.right()), m_model.getRob().m_cTrue);
  63. return m_model.getRob().m_lastFunc;
  64.  
  65. case EQUIV:
  66. // ite(f,g,!g)
  67. m_model.getRob().m_lastFunc = m_model.getRob().ite(syntaxTreeToRoBDD(n.left()),
  68. syntaxTreeToRoBDD(n.right()), m_model.getRob().ite(syntaxTreeToRoBDD(n.right()),
  69. m_model.getRob().m_cFalse, m_model.getRob().m_cTrue));
  70. return m_model.getRob().m_lastFunc;
  71.  
  72. }
  73. }
  74. return null;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement