2architecture.tex 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. \section{Assumptions}\label{sec:assumptions}
  2. Our implementation makes the folliowing assumptions:
  3. \begin{enumerate}
  4. \item \label{itm:hyperedges} There are no hyperedges.
  5. \item \label{itm:constraints} There are no port constraints.
  6. \item \label{itm:labels} There are no labels.
  7. \item \label{itm:cross-hierarchy-edges} There are no cross-hierarchy edges
  8. \item \label{itm:multi-layer-edge} No edges over multiple layers (the previous phases should add dummy nodes).
  9. \item \label{itm:connected} Graphs are connected.
  10. \end{enumerate}
  11. Assumptions~\ref{itm:hyperedges},~\ref{itm:constraints} and~\ref{itm:labels} were made just to make it easier for us by reducing the complexity of the task.
  12. Assumption~\ref{itm:cross-hierarchy-edges} was made because these are not possible with the Sugiyama approach.
  13. Regarding assumption~\ref{itm:connected}, we found an example where for a disconnected graph the algorithm behaved incorrectly.
  14. This example is included in the appendix (figure~\ref{fig:error_disconnected}).
  15. \section{Known Issues}\label{sec:knownIssues}
  16. Only the most important unsolved issues are listed here.
  17. For a complete list, see \url{http://gogs.koljastrohm-games.com/GraphDrawer/NodeShuffler/issues}.
  18. \begin{itemize}
  19. \item[\done] The most important issues were solved.
  20. \end{itemize}
  21. \section{Overview}\label{sec:components}
  22. The \code{main} package contains an executable class \code{Main}.
  23. This classes \code{main} method reads a graph from a file using the \code{graph.io} package and then creates a \code{MainView}.
  24. It is also possible to create a \code{MainView} directly from an \code{ElkNode}.
  25. The view then creates the pseudo code for a \code{BKNodePlacement} algorithm and instantiates a \code{PseudoCodeProcessor} to run it.
  26. The \code{PseudoCodeProcessor} repeatedly asks an associated \code{ProcessController} if and what kind of step should be done (this is further explained in section~\ref{sec:theActualAlgorithm}).
  27. Meanwhile the view displays the same \code{LayeredGraphNode}s and \code{LayeredGraphEdge}s on the screen.
  28. Figure~\ref{fig:components} contains a component diagram that illustrates these dependencies of the different packages.
  29. Advantages of our architecture include:
  30. \begin{itemize}
  31. \item It is possible to open multiple windows for different graphs.
  32. This happens already, for example, when loading a graph from a file or when generating a new random graph.
  33. \item Modularity, since the class \code{BKNodePlacement} can be replaced by other node placement algorithms.
  34. Minor changes to the internal data structure might be necessary.
  35. \item Abstraction: When implementing an algorithm there is no need to worry about making \enquote{step over} or \enquote{step out} commands.
  36. Also it is not necessary to define how to undo a step (except for some rare cases), although we do not keep a list of states: This would cost too much Memory (10~743 steps for the graph in figure~\ref{fig:originalpapergraph}).
  37. \end{itemize}
  38. \begin{figure}[htp]
  39. \centering
  40. \includegraphics[width=0.8\linewidth,trim=0 1cm 0 0,clip]{img/components.pdf}
  41. \caption[Component diagram]{Component diagram visualizing the architecture of \appname. Each component resembles a java package.}
  42. \label{fig:components}
  43. \end{figure}
  44. \section{System Requirements and Software Dependencies}\label{sec:systemRequirements}
  45. The software \appname\ relies on is listed in table~\ref{table:softwareDependencies}.
  46. The requirements to any system running \appname\ are demanded in table~\ref{table:systemRequirements}.
  47. \begin{table}[htp]
  48. \centering
  49. \small
  50. \begin{tabular}{l p{1cm} p{6cm}}
  51. \rowcolor{gray!50}
  52. \textbf{Dependency} && \textbf{Version} \\
  53. Java && $\geq8$ \\
  54. \rowcolor{gray!25}
  55. JSON-java~\cite{leary_json-java:_2018} && \\
  56. Eclipse Layout Kernel~\cite{noauthor_elk:_2018} && \\
  57. \\
  58. \end{tabular}
  59. \caption[Software Dependencies]{Software Dependencies. If no version is given, all should work and the latest is recommended.}
  60. \label{table:softwareDependencies}
  61. \end{table}
  62. \begin{table}[htp]
  63. \centering
  64. \small
  65. \begin{tabular}{l l p{6cm}}
  66. \rowcolor{gray!50}
  67. \textbf{Requirement} & \textbf{Minimum} & \textbf{Recommended} \\
  68. Free disk space & 150MB & 150MB \\
  69. \rowcolor{gray!25}
  70. Free RAM & 300MB (single window) & More for multiple windows/graphs \\
  71. \rowcolor{gray!25}
  72. & & At least 2 GB for running the automatic tests. \\
  73. Display & $1024 \times 768$ resolution & $1920 \times 1080$ resolution \\
  74. \rowcolor{gray!25}
  75. CPU & capable of running java applications & faster is better \\
  76. GPU & capable of 2D rendering & rendering in $1920 \times 1080$ resolution\\
  77. \rowcolor{gray!25}
  78. Internet connection & not any & not any\\
  79. \\
  80. \end{tabular}
  81. \caption{System Requirements}
  82. \label{table:systemRequirements}
  83. \end{table}
  84. \section{Input File Format}\label{sec:inputFileFormat}
  85. The input to \appname\ is a JSON file.
  86. An example is displayed in figure~\ref{fig:json-example}.
  87. The structure is as follows:
  88. \begin{itemize}
  89. \item The object in the JSON file is a node.
  90. \item A node has the attributes that are displayed in table~\ref{table:node-attributes}.
  91. \item An edge has the attributes that are displayed in table~\ref{table:edge-attributes}.
  92. \item Any additional attributes not listed here are ignored.
  93. For example they can be used as comment fields, to make the file more readable.
  94. \end{itemize}
  95. For parsing the JSON file the JSON-java library~\cite{leary_json-java:_2018} is used.
  96. The classes for reading and writing those JSON files are displayed in figure~\ref{fig:io}.
  97. The internal representation of graphs is further explained in the section~\ref{sec:graph}.
  98. \begin{table}[htp]
  99. \centering
  100. \small
  101. \begin{tabular}{l l l p{8.5cm}}
  102. \rowcolor{gray!50}
  103. \textbf{Attribute} & \textbf{Type} & \textbf{Optional} & \textbf{Explanation} \\
  104. source & string & no & The name of the source of this edge.
  105. Must be a node with the same parent node as the node specified by the \code{target} attribute. \\
  106. \rowcolor{gray!25}
  107. target & string & no & The name of the target of this edge.
  108. Must be a node with the same parent node as the node specified by the \code{source} attribute. \\
  109. \end{tabular}
  110. \caption{Edge Attributes}
  111. \label{table:edge-attributes}
  112. \end{table}
  113. \begin{table}[htp]
  114. \centering
  115. \small
  116. \begin{tabular}{l l l p{8.5cm}}
  117. \rowcolor{gray!50}
  118. \textbf{Attribute} & \textbf{Type} & \textbf{Optional} & \textbf{Explanation} \\
  119. name & string & yes & If not omitted, this must be unique for a given parent node. \\
  120. \rowcolor{gray!25}
  121. width & integer & yes & The minimum width of the node.
  122. The node can be wider if it contains other nodes that need more space.
  123. If the whole layout is too large, it is resized, such that all nodes are proportionately shrunk: In that case the minimum width can be exceeded after the shrinking.
  124. Default 40.\\
  125. height & integer & yes & The minimum height of the node.
  126. The node can be higher if it contains other nodes that need more space.
  127. If the whole layout is too large, it is resized, such that all nodes are proportionately shrunk: In that case the minimum height can be exceeded after the shrinking.
  128. Default 40.\\
  129. \rowcolor{gray!25}
  130. dummy & boolean & yes & Iff this is explicitly set to true, then the node is a dummy node. This attribute is necessary, because we expect previous stages to have eliminated multilayer edges, see section~\ref{sec:assumptions}. \\
  131. layers & < < node > > & yes & The layers of nodes inside this node (Hierarchy). \\
  132. \rowcolor{gray!25}
  133. edges & < edge > & yes & The edges between nodes whose parent node is this node. \\\\
  134. \end{tabular}
  135. \caption[Node Attributes]{Node Attributes. < \emph{element type} > is a list.}
  136. \label{table:node-attributes}
  137. \end{table}
  138. \begin{figure}[htp]
  139. \centering
  140. \includegraphics[width=\linewidth,trim=0 26cm 0 0,clip]{img/io.pdf}
  141. \caption[Class diagram of the \code{graph.io} package]{Class diagram of the \code{graph.io} package, containing utilities for reading and writing graphs.}
  142. \label{fig:io}
  143. \end{figure}
  144. %\begin{figure}[htp]
  145. % \centering
  146. % \includegraphics[width=0.9\textwidth]{img/json.png}
  147. % \caption[Input file format]{Input file format illustrated as a HERM diagram}
  148. % \label{fig:iff}
  149. %\end{figure}
  150. \begin{figure}[htp]
  151. \begin{lstinputlisting}[language=json,emph={}]{src/graph.json}
  152. \end{lstinputlisting}
  153. \caption[Example input file]{Example input file that is understood by \appname.
  154. The graph is also displayed in figure~\ref{fig:full-application-example}.}
  155. \label{fig:json-example}
  156. \end{figure}
  157. \section{Internal graph representation, \code{graph}}\label{sec:graph}
  158. One feature that is important to us, is to be able to work with hierarchical graphs.
  159. Therefore a node can contain other nodes and edges.
  160. In addition to the variables described in section~\ref{sec:inputFileFormat}, there are multiple attributes that are used during the computation or as output variables.
  161. \begin{itemize}
  162. \item The \member{parent} of a node is the node that contains it in the hierarchy.
  163. \item \member{dummy} specifies whether this node is a dummy node.
  164. \item \member{name} is the name of the node.
  165. \item The attributes \member{shift}, \member{sink}, \member{root} and \member{align} correspond to the variables used by Brandes and Köpf~\cite{brandes_fast_2001}.
  166. %They are summarized in table~\ref{table:bk-variables}.
  167. \item The attribute \member{xUndef} determines whether the x coordinate of the node has already been assigned a value.
  168. \item The attributes \member{x} and \member{y} are the coordinates of the node relative to its \member{parent}.
  169. \item The attributes \member{w} and \member{h} are the width and height of the node.
  170. \item The attributes \member{color} is the color in which the node is displayed.
  171. \item The attribute \member{selected} is used to highlight the node that is currently active in each layout.
  172. \end{itemize}
  173. The last six bullet points are available separately for each of the four extremal layouts.
  174. The last four bullet points are also separately available for the combined layout.
  175. To achieve this, they are stored in the internal classes \code{LayoutInfo} and \code{CombinedLayoutInfo}.
  176. Similarly, edges have the following attributes in addition to those given through the JSON format:
  177. \begin{itemize}
  178. \item \member{dummyEdge} specifies whether they are edges between two dummy nodes.
  179. \item \member{bindPoints} is a list of bend points for the edge, including the beginning and end point of the edge.
  180. \item \member{reversed} specifies if this edge was reversed earlier (not used by \appname).
  181. \item \member{graph} is the node that contains the edges (hierarchy).
  182. \item \member{conflicted} corresponds to the variable used by Brandes and Köpf~\cite{brandes_fast_2001} and indicates that this edge won't be drawn vertically.
  183. \end{itemize}
  184. The last bullet point is available separately for each of the four extremal layouts and for the combined layout.
  185. The user has to make sure that each graph meets the requirements in section~\ref{sec:assumptions}, we do not check them and wrong usage might result in errors.
  186. A class diagram of the package \code{graph} is displayed in figure~\ref{fig:graph}.
  187. There you will find some less important (from a documentation point of view) attributes that were not listed here.
  188. \begin{figure}[htp]
  189. \centering
  190. \includegraphics[width=0.95\linewidth,trim=0 2cm 0 0,clip]{img/graph.pdf}
  191. \caption[Class diagram of the \code{graph} package]{Class diagram of the \code{graph} package. Getters, setters and constructors are omitted.
  192. The package \code{graph.io} is displayed in figure~\ref{fig:io}}
  193. \label{fig:graph}
  194. \end{figure}
  195. %\begin{table}[htp]
  196. % \begin{longtable}{|l|p{10cm}|}
  197. % \hline
  198. % Attribute & Explanation \\\hline\hline
  199. % \member{root} & The root node of the block of this node.
  200. % Unique for all nodes in the same block. \\\hline
  201. % \member{sink} & The topmost sink in the block graph that can be reached from the block that this node belongs to.
  202. % Only used for nodes that are the root of a block.
  203. % Unique for all nodes in the same class. \\\hline
  204. % \member{shift} & The shift of the class that this node belongs to.
  205. % Only used for nodes that are a sink of a class. \\\hline
  206. % \member{align} & The next node in the same block as this node.
  207. % The \member{align} of the last node in the block is the root node of the block again.\\\hline
  208. % \end{longtable}
  209. % \caption{Variables also used by Brandes and Köpf~\cite{brandes_fast_2001}}
  210. % \label{table:bk-variables}
  211. %\end{table}
  212. \section{The actual algorithm}\label{sec:theActualAlgorithm}
  213. This section expects the reader to be familiar with the node placement algorithm by Brandes and Köpf~\cite{brandes_fast_2001}.
  214. We recommend section 3.2.1 of Carstens~\cite{carstens_node_2012} for a detailed explanation, although Carstens uses some terms differently than Brandes and Köpf and draws the graph from left to right.
  215. By these means our implementation is oriented more towards the original paper by Brandes and Köpf~\cite{brandes_fast_2001}.
  216. The \enquote{stages} of the algorithm, located in the package \code{bk}, represent intervals during which each step of the algorithm is performed in a similar way.
  217. These stages, however, do not run the algorithm, but instead create lines of pseudocode, class \code{PseudoCodeNode}, that can be executed (don't be mislead by the term pseudocode!).
  218. More precisely, each \code{PseudoCodeNode} is a line of code that can be displayed and contains a \code{CodeLine} that can be executed.
  219. The \code{PseudoCodeNode}s are arranged hierarchically to form a whole pseudocode tree.
  220. All the stages are displayed in class diagram~\ref{fig:bk} while the different kinds of \code{CodeLine}s are listed in class diagram~\ref{fig:codeline}.
  221. This separation was made to distinguish viewable \code{PseudoCodeNode}s from executable \code{CodeLine}s.
  222. For the execution of the \code{CodeLine}s a \code{PseudoCodeProcessor} interacts with its own \newline\code{ProcessController} and \code{Memory}.
  223. Note that the \code{ProcessController} is not a controller in the MVC sense that it processes user input, but in the sense that it \emph{controls} the execution of steps/stages.
  224. This works the following:
  225. \begin{enumerate}
  226. \item The \code{MainView} creates a node placement algorithm (only \code{BKNodePlacement} available) and a \code{PseudoCodeProcessor} to run it.
  227. \item The processor concurrently asks its associated \code{ProcessController} if it should do a forward or backward step and if that is a \enquote{step into}, \enquote{step over} or \enquote{step out}.
  228. \item The \code{ProcessController} waits until it knows which action to take (for example if the user pressed Alt + Right arrow key, see chapter~\ref{ch:ui}).
  229. Alternatively, if the animation is not paused, it waits until a specific delay has passed.
  230. Then it returns to the processor which step to take next.
  231. \item Depending on the return value, the processor executes one or multiple lines of code in forwards or backwards direction.
  232. \end{enumerate}
  233. A class diagrams for the \code{processor} package is displayed in figure~\ref{fig:processor}.
  234. \section{View}\label{sec:view}
  235. This section only covers the software architecture regarding the views.
  236. For an explanation of what is actually displayed, see chapter~\ref{ch:ui}
  237. \begin{itemize}
  238. \item The main window displays a \code{JLayeredPane} on the left where the graph is shown and a \code{menu} of the class \code{JPanel} on the right, where \code{NiceButton}s and \code{PseudoCodeNode}s are located.
  239. The main window itself is a \code{JFrame} from the Swing library.
  240. \item Additionally a legend, class \code{LegendView}, that is another \code{JPanel} is displayed on the bottom.
  241. \item The \code{PseudoCodeNode}s are rendered by the \code{PseudoCodeRenderer} class.
  242. For example, this class highlights selected code lines.
  243. \item \code{EdgeView} and \code{NodeView} are \code{JPanel}s, which means they can be drawn onto the \code{JLayeredPane}.
  244. For this they have to know about which part of the graph and which layout they belong to (some attributes).
  245. \item A \code{NiceButton} is a \code{JButton} that has an image on it.
  246. \item Next to the \code{PseudoCodeRenderer} is an object of the class \code{PseudoCodeLines}, that extends \code{JComponent}.
  247. \item A \code{RenderHelper} that contains some additional utility functions for the views.
  248. \item Dialogs like the \code{OptionsDialog} and the \code{RandomGraphDialog} are \code{JDialog}s.
  249. \end{itemize}
  250. A class diagram of the package \code{view} is displayed in figure~\ref{fig:view}.
  251. \begin{figure}[htp]
  252. \centering
  253. \includegraphics[width=\linewidth,trim=0 11cm 0 0,clip]{img/main_and_view.pdf}
  254. \caption[Class diagram of the packages \code{view} and \code{main}]{Class diagram of the packages \code{view} and \code{main}.
  255. Getters, setters and contructors are not omitted because most of them perform nontrivial computations.}
  256. \label{fig:view}
  257. \end{figure}
  258. \begin{figure}[htp]
  259. \centering
  260. \includegraphics[width=\linewidth,trim=0 11cm 0 0,clip]{img/bk.pdf}
  261. \caption{Class diagram of the \code{bk} package.}
  262. \label{fig:bk}
  263. \end{figure}
  264. \begin{figure}[htp]
  265. \centering
  266. \includegraphics[width=\linewidth,trim=0 25cm 0 0,clip]{img/codeline.pdf}
  267. \caption{Class diagram of the \code{codeline} package.}
  268. \label{fig:codeline}
  269. \end{figure}
  270. \begin{figure}[htp]
  271. \centering
  272. \includegraphics[width=\linewidth,trim=0 5cm 0 0,clip]{img/processor.pdf}
  273. \caption[Class diagram of the \code{processor} package.]{Class diagram of the \code{processor} package.
  274. Constructors and trivial getters and setters are omitted.}
  275. \label{fig:processor}
  276. \end{figure}