%root: main.tex
\usetikzlibrary{shapes.geometric}%for cylinder
\usetikzlibrary{shapes.arrows}%for arrow shape
\usetikzlibrary{shapes.misc}
%rid of vertical spacing for booktabs rules
\renewcommand{\aboverulesep}{0pt}
\renewcommand{\belowrulesep}{0pt}


\begin{figure*}[t!]
	\centering
	\resizebox{\textwidth}{!}{%
	\begin{tikzpicture}
		%pdb cylinder
		\node[cylinder, text width=0.28\textwidth, align=center, draw=black, text=black, cylinder uses custom fill, cylinder body fill=blue!10, aspect=0.12, minimum height=2.5cm, minimum width=2.5cm, cylinder end fill=blue!50, shape border rotate=90] (cylinder) at (0, 0) {
		\tabcolsep=0.1cm
		\begin{tabular}[t]{>{\small}c | >{\small}c | >{\small}c}
				\multicolumn{2}{c}{$\boldsymbol{T}$}\\
				%\toprule
				Point & $\Phi$  \\%& $\semN$\\
				\midrule
	                     $e_1$    & $A$ \\%& 1 \\
	                     $e_2$     & $B$ \\%& 1\\
	                     $e_3$      & $C$ \\%& 1\\
	                     $e_4$      & $E$ \\%& 1\\	                     
			\end{tabular}\hspace{0.15cm}
			\tabcolsep=0.05cm
			%\captionof{table}{Route}
			\begin{tabular}[t]{>{\footnotesize}c | >{\footnotesize}c | >{\footnotesize}c | >{\footnotesize}c}
				\multicolumn{3}{c}{$\boldsymbol{R$}}\\
				%\toprule
				$\text{Point}_1$ & $\text{Point}_2$ & $\Phi$\\% & $\semN$ \\
				\midrule
	                    $e_1$         & $e_2$         & $U$\\%          & 2       \\
	                    $e_2$         & $e_4$          & $Y$\\%          & 4        \\
	                    %& $\cdots$        & $\cdots$        & $\cdots$     & $\cdots$   \\
	                    $e_2$         & $e_3$          & $Z$\\%          & 3       \\
			\end{tabular}};
			%label below cylinder
			\node[below=0.2 cm of cylinder]{{\LARGE$ \pdb$}};
		%First arrow
		\node[single arrow, right=0.25 of cylinder, draw=black, fill=black!65, text=white, minimum height=0.75cm, minimum width=0.25cm](arrow1) {\textbf{\abbrStepOne}};
		\node[above=of arrow1](arrow1Label) {$\query_2$};
		\usetikzlibrary{arrows.meta}%for the following arrow configurations
			\draw[line width=0.5mm, dashed, arrows = -{Latex[length=3mm, open]}] (arrow1Label)->(arrow1);
		%Query output (output of step 1)
		\node[rectangle, right=0.175 of arrow1, draw=black, text=black, fill=purple!10, minimum height=2.5cm, minimum width=2cm](rect) {
		\tabcolsep=0.075cm
		%\captionof{table}{Q}
		%\setlength{\cellspacetoplimit}{4pt}
		%\setlength\extrarowheight{10pt}
%		\setlength{\cellspacetoplimit}{10mm}
%		\setlength{\cellspacebottomlimit}{10mm}
		%\renewcommand{\arraystretch}{1.5}
		 \begin{tabular}{>{\footnotesize}c | >{\centering\arraybackslash\footnotesize}m{1.95cm} | >{\centering\arraybackslash\footnotesize}m{3.95cm}}
	            %\multicolumn{3}{c}{$\boldsymbol{\query_2(\pdb)}$}\\[1mm]
	            %\toprule
	            Point    & $\Phi$ & Circuit\\%                          & $\expct_{\idb \sim \probDist}[\query_2(\db)(t)]$ \\ \hline
			\midrule
	          	%\hline 
	          	%\\\\[-3.5\medskipamount]
	                 $e_1$ & $AU$ &\adjustbox{valign=b}{\resizebox{!}{9mm}{
	                       \begin{tikzpicture}[thick]
	                       		\node[gen_tree_node](sink) at (0.5, 0.8){$\boldsymbol{\circmult}$};
	                       		\node[gen_tree_node](source1) at (0, 0){$A$};
	                       		\node[gen_tree_node](source2) at (1, 0){$U$};
	                       		\draw[->](source1)--(sink);
	                       		\draw[->] (source2)--(sink);
					\end{tikzpicture}$\inparen{1}$% & $0.5 \cdot 1.0 + 0.5 \cdot 1.0 = 1.0$   
					}}\\%                 & $0.9$                                            \\
	                       $e_2$ & $B(Y + Z)$ Or $BY+ BZ$&
	            			\adjustbox{valign=m}{
	                       \resizebox{!}{14mm} {
						\begin{tikzpicture}[thick]
							\node[gen_tree_node] (a1) at (1, 0){$Y$};
							\node[gen_tree_node] (b1) at (2, 0){$Z$};
							%level 1
							\node[gen_tree_node] (a2) at (0.75, 0.8){$B$};
							\node[gen_tree_node] (b2) at (1.5, 0.8){$\boldsymbol{\circplus}$};
							%level 0
							\node[gen_tree_node] (a3) at (1.1, 1.6){$\boldsymbol{\circmult}$};
							%edges
							\draw[->] (a1) -- (b2);
							\draw[->] (b1) -- (b2);
							\draw[->] (a2) -- (a3);
							\draw[->] (b2) -- (a3);
						\end{tikzpicture}$\inparen{2}$
					}} \adjustbox{valign=m}{Or}
					%%%%%%%%%%%
					%Non factorized circuit%
					%%%%%%%%%%%
					\adjustbox{valign=m}{
	                       \resizebox{!}{14mm} {
					\begin{tikzpicture}[thick]
						\node[gen_tree_node] (a2) at (0, 0){$Y$};
						\node[gen_tree_node] (b2) at (1, 0){$B$};
						\node[gen_tree_node] (c2) at (2, 0){$Z$};
						%level 1
						\node[gen_tree_node] (a1) at (0.5, 0.8){$\boldsymbol{\circmult}$};
						\node[gen_tree_node] (b1) at (1.5, 0.8){$\boldsymbol{\circmult}$};
						%level 0
						\node[gen_tree_node] (a0) at (1.0, 1.6){$\boldsymbol{\circplus}$};
						%edges
						\draw[->] (a2) -- (a1);
						\draw[->] (b2) -- (a1);
						\draw[->] (b2) -- (b1);
						\draw[->] (c2) -- (b1);
						\draw[->] (a1) -- (a0);
						\draw[->] (b1) -- (a0);
					\end{tikzpicture}
				}}\\
	          \end{tabular}
		};
		%label below rectangle
		\node[below=0.2cm of rect]{{\LARGE $\query_2(\pdb)\inparen{\tup}\equiv \poly\inparen{\vct{X}}$}};
		%Second arrow
		\node[single arrow, right=0.25 of rect, draw=black, fill=black!65, text=white, minimum height=0.75cm, minimum width=0.25cm](arrow2) {\textbf{\abbrStepTwo}};
		%Expectation computation; (output of step 2)
		\node[rectangle, right=0.25 of arrow2, rounded corners, draw=black, fill=red!10, text=black, minimum height=2.5cm, minimum width=2cm](rrect) {
		\tabcolsep=0.09cm
		%\captionof{table}{Q}
		\begin{tabular}{>{\small}c | >{\arraybackslash\normalsize}c}%m{1.95cm}}
			%\multicolumn{2}{c}{$\expct\pbox{\poly(\vct{X})}$}\\[1mm]
			%\toprule
			Point & $\mathbb{E}[\poly(\vct{X})]$\\
			\midrule%[0.05pt]
			$e_1$ & $\inparen{\prob_{A_1} +\prob_{A_2}}\cdot\left(\prob_{U_1} + 2\prob_{U_2}\right)$\\%$1.0 \cdot 0.9 = 0.9$\\[3mm]
			$e_2$ & $\inparen{\prob_{B_1} + \prob_{B_2}}\inparen{\prob_{Y_1}+2\prob_{Y_2} + \prob_{Z_1} + 2\prob_{Z_2}}$\\%$(0.5 \cdot 1.0) + $\newline $\hspace{0.2cm}(0.5 \cdot 1.0)$\newline $= 1.0$\\
		\end{tabular}
			};
		%label of rounded rectangle
		\node[below=0.2cm of rrect]{{\LARGE $\expct\pbox{\poly(\vct{X})}$}};
	\end{tikzpicture}
	}
	%\setlength{\abovecaptionskip}{-0.35cm}
	\savecaptionspace{
	\caption{Intensional Query Evaluation Model $(\query_2 = \project_{\text{Point}}$ $\inparen{T\join_{\text{Point} = \text{Point}_1}R}$ where, for table $R,~\bound = 2$, while for $T,~\bound = 1.)$}
	\label{fig:two-step}
	}{-0.35cm}{-0.43cm}
	%\vspace{-0.43cm}
\end{figure*}

