% !TEX options=--shell-escape
\documentclass [12pt]{article}
\usepackage {amsmath}
\usepackage {amsthm}
\usepackage {amssymb}
\usepackage {graphicx}
\usepackage {float}
\usepackage {multirow}
\usepackage {xcolor}
\usepackage {algorithmic}
\usepackage [ruled,vlined,commentsnumbered,titlenotnumbered]{algorithm2e} \usepackage {array}
\usepackage {booktabs}
\usepackage {url}
\usepackage {parskip}
\usepackage [margin=1in]{geometry}
\usepackage [T1]{fontenc}
\usepackage {cmbright}
\usepackage [many]{tcolorbox}
\usepackage [colorlinks = true,
            linkcolor = blue,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = blue]{hyperref}
\usepackage {enumitem}
\usepackage {xparse}
\usepackage {verbatim}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{csquotes}
\usepackage[cache=false]{minted}
\usepackage{mdframed}
\usepackage{tikz}
\usetikzlibrary{shapes.symbols}
\newtheorem{theorem}{Theorem}

\DeclareTColorBox {Solution}{}{breakable, title={Solution}}
\DeclareTColorBox {Solution*}{}{breakable, title={Solution (provided)}}
\DeclareTColorBox {Instruction}{}{boxrule=0pt, boxsep=0pt, left=0.5em, right=0.5em, top=0.5em, bottom=0.5em, arc=0pt, toprule=1pt, bottomrule=1pt}
\DeclareDocumentCommand {\Expecting }{+m}{\textbf {[We are expecting:} #1\textbf {]}}
\DeclareDocumentCommand {\Points }{m}{\textbf {(#1 pt.)}}
\newcommand {\hint }[1]{\noindent {[\textbf {HINT:} \em #1 \em ]}} \newcommand {\pts }[1]{\textbf {(#1 pt.)}}

\begin{document}

{\LARGE \textbf {COMP 285 (NC A\&T, Spr `22)}\hfill \textbf {Weekly Quiz 6} }

\begin{Instruction}

\paragraph{Reporting Issues} If you find any issues with the solutions, reach out to Chi Wang (author) or Luis Perez (reviewer).

\end{Instruction}

\section{} Snakey the snake is in the bottom left corner of the grid, and is trying to reach O, the ultimate Oreo.
Snakey can move from her current cell to the adjacent cells (right, left, up, or down) if they exist and are not marked with X (X cells are blocked). However, every time that Snakey moves from one cell to the other, Snakey has to eat a cookie. What is the minimum number of cookies Snakey needs to eat to get to the O?

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{6.png}
    \label{fig:my_label}
\end{figure}

\begin{Solution}
10.
\paragraph{}
Shortest path problem. Go right, right, right, up, right, right, up, up, left, left.
\end{Solution}

\section{} Consider the general case of this problem, where a grid is given as an input with blocked and available cells and the locations of the Snakey and Oreo, and the goal is to find the minimum number of cookies for Snakey to reach the Oreo. Which algorithm would you use to solve this problem?

\begin{Solution}
BFS.
\end{Solution}

\section{} Assume you want to find the connected components of an undirected graph. Which algorithm would you use?

\begin{Solution}
BFS, DFS.
\end{Solution}

\section{} Consider the directed graph below. How many strongly connected components does this graph have?

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{2.png}
    \label{fig:my_label}
\end{figure}

\begin{Solution}
4
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.2]{4.jpeg}
    \label{fig:my_label}
\end{figure}
\end{Solution}

\section{} Consider the directed graph below. What is the minimum number of directed edges to add to this graph to make all the vertices strongly connected?
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{2.png}
    \label{fig:my_label}
\end{figure}

\begin{Solution}
1
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.2]{5.jpeg}
    \label{fig:my_label}
\end{figure}
\end{Solution}

\section{} Consider the Directed Acyclic Graph (DAG) below. Which of the below is a valid topological sorting of the graph?
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{3.png}
    \label{fig:my_label}
\end{figure}

\begin{Solution}
FDCEBA
\end{Solution}

\section{} Consider the DAG below. What is the lexicographically smallest topological ordering of the vertices? There are many valid topological orderings - out of the valid ones, write the one where letters earlier in the alphabet appear first. To receive credit, enter your answer as capital letters with no spaces (eg, ABCDEF).
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{3.png}
    \label{fig:my_label}
\end{figure}

\begin{Solution}
CFBDEA
\end{Solution}

\section{} Assume you have two vertices u and v in a directed graph where u and v are in the same strongly connected components (SCC). Which one of the following is incorrect about u and v?

\begin{Solution}
There exists a DFS tree where u is not in v 's subtree and v is not in u's subtree.
\paragraph{}

A directed graph G = (V,E) is strongly connected if:
for all $v, w$ in V: (1) there is a path from v to w and (2) there is a path from w to v.
So there couldn't exist such a DFS tree.
\end{Solution}

\section{} Assume you have two vertices u and v in a directed graph where there exists a path from u to v. Which one of the following is incorrect about u and v?

\begin{Solution}
u's DFS finish time is always greater than v's DFS finish time.
\paragraph{}
It depends.
\end{Solution}

\end{document}


%
% body.tex
%
% Copyright © 2020 Libao Jin <jinlibao@outlook.com>
% Distributed under terms of the MIT license.
%
Please note that the deadline will be enforced as per the previous homework. Remember that you are allowed to work in teams of two on this assignment. You are encouraged to prepare your work in \LaTeX{}; a template will be provided to help you put it all together. If you choose  to submit a hard copy, you may submit only one copy for a team, indicating the names of both contributors. Online submission is encouraged, however, in that case both members of a team should submit the PDF file containing  their work and showing both their names.

\emph{All plots generated in this homework should have a title, legend, and labeled $x$ and $y$-axes.} \\[15pt]

\textbf{Instruction}

\begin{enumerate}[label={\arabic*.}]
  \item Go to \url{https://www.overleaf.com} and sign in (required).
  \item Click \emph{Menu} (up left corner), then \emph{Copy Project}.
  \item Go to \verb|LaTeX/meta.tex| (the file \verb|meta.tex| under the folder \verb|LaTeX|) to change the section and your name, e.g.,
    \begin{itemize}
      \item change title to \verb|\title{MATH 3340-01 Scientific Computing Homework 4}|
      \item change author to \verb|\author{Albert Einstein \& Carl F. Gauss}|
    \end{itemize}
  \item For Problem 1, you can either type the solution in \LaTeX{} or write it on the printout.
  \item For Problem 2, 3, 4, you need to write function/script files, store results to output files, and save graphs to figure files. Here are suggested names for function files, script files, output files, and figure files:
    \begin{table}[!hbtp]
      \centering
      % \caption{caption}
      % \label{tab:label}
      \begin{tabular}{cllll}
        \toprule
        Problem & Function File            & Script File     & Output File       & Figure File \\
        \midrule
        2       & \verb|newtonNonlinear.m| & \verb|hw4_p2.m| & \verb|hw4_p2.txt| &                   \\
        3       &                          & \verb|hw4_p3.m| & \verb|hw4_p3.txt| & \verb|hw4_p3.pdf| \\
        4       &                          & \verb|hw4_p4.m| & \verb|hw4_p4.txt| & \verb|hw4_p4.pdf| \\
        \bottomrule
      \end{tabular}
    \end{table}

    Once finished, you need to upload these files to the folder \verb|src| on Overleaf. If you have different filenames, please update the filenames in \verb|\lstinputlisting{../src/your_script_name.m}| accordingly. You can code in the provided files in \href{https://libaoj.in/courses/2021s/MATH3340/Homework/4/hw4.zip}{hw4.zip}, and use the MATLAB script \verb|save_results.m| to generate the output files and store the graphs to \verb|.pdf| files automatically (the script filenames should be exactly same as listed above).
  \item Recompile, download, and print out the generated PDF.
  \item You may find \href{https://libaoj.in/files/LaTeX.Mathematical.Symbols.pdf}{\LaTeX{}.Mathematical.Symbols.pdf} and the second part of \href{https://libaoj.in/courses/2021s/MATH3341/slides/Math.3341.Lab.01.Slides.pdf}{Lab 01 Slides} and \href{https://libaoj.in/courses/2021s/MATH3341/slides/Math.3341.Lab.02.Slides.pdf}{Lab 02 Slides} helpful.
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Problem 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Problem 1}%
\label{sec:problem_1}
Do by hand, on paper, one iteration of Newton's method for the nonlinear system:
\begin{equation*}
  \begin{cases}
    x^{2} + y^{3} - 1 = 0, \\
    x^{3} - y^{2} + 0.25 = 0.
  \end{cases}
\end{equation*}
Start with the initial guess $\mathbf{x}^{0} = [x^{0}, y^{0}]^{T} = [0.5, 0.5]^{T}$ and compute the next iterate $\mathbf{x}^{1}$. Also compare the norm of the residual at the new iterate with the residual norm computed for the initial guess.
\begin{solution}
  \quad \vfill % delete this line if you type the answer in LaTeX
  \begin{itemize}
    \item
      Script file \verb|hw4_p1.m|
      \lstinputlisting[style=MATLAB]{../src/hw4_p1.m}
    \item
      Output file \verb|hw4_p1.txt|
      \lstinputlisting[style=Plain]{../src/hw4_p1.txt}
  \end{itemize}

\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Problem 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Problem 2}%
\label{sec:problem_2}
Solve the system
\begin{equation*}
  \begin{cases}
    10 - x + \sin(x + y) - 1 = 0 \\
    8 y - \cos^{2}(z - y) - 1 = 0 \\
    12 z + \sin(z) - 1 = 0
  \end{cases}
\end{equation*}
using a residual tolerance of $10^{-6}$ and the initial guess, $\mathbf{x}^{0} = [0.1, 0.25, 0.08]^{T}$. Print out the values for $x$, $y$, and $z$ for each iteration in a table similar to  the one you created for the problem of the previous  homework. You should submit your code (which can again be organized as a function and the script calling this function) together with your output.
\begin{solution}
  \quad
  \begin{itemize}
    \item
      Function file \verb|newtonNonlinear.m|
      \lstinputlisting[style=MATLAB]{../src/newtonNonlinear.m}
    \item
      Script file \verb|hw4_p2.m|
      \lstinputlisting[style=MATLAB]{../src/hw4_p2.m}
    \item
      Output file \verb|hw4_p2.txt|
      \lstinputlisting[style=Plain]{../src/hw4_p2.txt}
  \end{itemize}
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Problem 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Problem 3}%
\label{sec:problem_3}
In a script file, find  an exponential fit of the form $f(x) = C e^{Ax}$ to the data (Table \ref{tab:p3}).
\begin{table}[!hbtp]
  \centering
  \caption{Problem 3 Data Points}
  \label{tab:p3}
  \begin{tabular}{ccccccc}
    \toprule
    $x$ & $0.0$   & $0.1$   & $0.2$   & $0.3$   & $0.4$   & $0.5$ \\
    \midrule
    $y$ & $1.388$ & $1.647$ & $1.951$ & $2.633$ & $3.321$ & $3.977$ \\
    \bottomrule
  \end{tabular}
\end{table}
Print your values for $A$ and $C$, then plot $f(x)$ vs. $x$ where \verb|x = 0:0.01:0.5| along with the original data points. Use a visible marker to mark the data points. Include the values of $A$ and $C$ in your report file along with the generated  plot and script file contained your code.
\begin{solution}
  \quad
  \begin{itemize}
    \item
      Script file \verb|hw4_p3.m|
      \lstinputlisting[style=MATLAB]{../src/hw4_p3.m}
    \item
      Output file \verb|hw4_p3.txt|
      \lstinputlisting[style=Plain]{../src/hw4_p3.txt}
      \begin{figure}[!hbtp]
        \centering
        \includegraphics[width=0.8\linewidth]{../src/hw4_p3.pdf}
        \caption{}%
        \label{fig:}
      \end{figure}
  \end{itemize}
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Problem 4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Problem 4}%
\label{sec:problem_4}
Write a script file to find a quadratic fit of the form $f(x) = A x^{2} + B x + C$ to the data (Table \ref{tab:p4}).
\begin{table}[!hbtp]
  \centering
  \caption{Problem 4 Data Points}
  \label{tab:p4}
  \begin{tabular}{cccccc}
    \toprule
    $x$ & $0$     & $1$      & $2$      & $3$     & $4$ \\
    \midrule
    $y$ & $0.695$ & $-1.475$ & $-1.275$ & $0.882$ & $4.765$ \\
    \bottomrule
  \end{tabular}
\end{table}
Print your values for $A$, $B$, and $C$, then plot $f(x)$ vs $x$ where \verb|x = 0:0.1:4| along with the original data  points. Use a visible marker for the data points. Include the values of $A$, $B$, and $C$ in your report file along with the generated plot and script file containing your code.
\begin{solution}
  \quad
  \begin{itemize}
    \item
      Script file \verb|hw4_p4.m|
      \lstinputlisting[style=MATLAB]{../src/hw4_p4.m}
    \item
      Output file \verb|hw4_p4.txt|
      \lstinputlisting[style=Plain]{../src/hw4_p4.txt}
      \begin{figure}[!hbtp]
        \centering
        \includegraphics[width=0.8\linewidth]{../src/hw4_p4.pdf}
        \caption{}%
        \label{fig:}
      \end{figure}
  \end{itemize}
\end{solution}


\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}

%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

%% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\usepackage[colorinlistoftodos]{todonotes}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\usepackage{color}
\usepackage{url}

%% display solutions or not
\newif\ifsol
\soltrue % comment out to hide solutions

\title{Section 3: Games and CSPs}
\author{CS 182 - Artificial Intelligence}
\date{}

\begin{document}
\maketitle

%\begin{abstract}
%Your abstract.
%\end{abstract}

\noindent Recall the formalization of a \textbf{Deterministic Game} from lecture:
\begin{itemize}
\setlength\itemsep{0.2em}
\item States: $S$ (with start state $S_0$)
\item Actions: $A$ (may depend on player/state)
\item Transition Function: $R:$ $S \times A \rightarrow S$
\item Players: $P=\{1 \ldots N\}$ (usually take turns)
\item Terminal Test: $T:$ $S \rightarrow \{True,False\}$
\item Terminal Utilities: $U:$ $S \times P \rightarrow R$
\end{itemize}

\noindent And that a solution for a player is a policy $\Pi: S \rightarrow A$.
\\ \\
\noindent Note that the difference between a game and a search problem is that introduction of multiple players and their policies and a goal test / terminal utility instead of a cost of actions and a goal state set.
\\ \\
\textbf{Minimax:} Recall that in games, every state has a value $V$. For terminal states, $V(s)$ is known. In single-player games, you can calculate the value for non-terminal states as
$$V(s) = \underset{s' \in \textrm{successors}(s)}{\operatorname{max}} V(s')$$
Now imagine a two-player, zero-sum, turn-based game like Tic Tac Toe. We still know $V(s)$ for terminal states, but now we have to anticipates the opponents' turn. In the minimax algorithm, we assume that the opponent plays rationally and tries to minimize your reward (thus maximizing theirs). Therefore, for your opponents' turns, we calculate the value of a state as
$$V(s') = \underset{s \in \textrm{successors}(s')}{\operatorname{min}} V(s)$$
Therefore, with two rational agents the optimal strategy is to maximize your moves and assume your opponent will do the same (thus minimizing your utility on their turn), thus minimax. Of course if our opponent isn't optimal, then we can still use this type of procedure if we consider the opponent's move in expectation, thus expectimax!
\\ \\
\textbf{Alpha-Beta Pruning} is an extension of Minimax which increases efficiency by reducing the number of nodes searched. While we traverse the tree, we keep track of two values, $\alpha$, and $\beta$. $\alpha$ is MAX's best solution on the path to root, $\beta$ is MIN's best option on the path to root. We then follow the procedure below allowing us to eliminate the need to search over sections of the tree to which we know will not be a part of the optimal solution.
\begin{figure}[ht]
\centering
\includegraphics[width=0.7\textwidth]{figs/abalg}
\end{figure}

\subsection*{Practice Problems}

\begin{enumerate}
\item Describe Tic Tac Toe as a deterministic game. How many states exist?

\ifsol
    \begin{itemize}
    \color{blue}
    \item $S$: A state in this problem describes the current board state. Every field can have any of three values: \textit{empty}, \textit{X}, and \textit{O}. If we represent them using the numbers $0, 1, 2$, we can represent a board as an array of length 9, e.g. $[0,0,1,0,0,2,0,0,0]$. Using this representation, there are $3^9 = 19683$ possible states. Side note: This representation allows many illegal states (game is already over, too many $X$ or $O$, etc). This is not a problem for search algorithms because they will never expand those illegal states. However, for an accurate calculation of possible legal states, you can look here:  \url{http://brianshourd.com/posts/2012-11-06-tilt-number-of-tic-tac-toe-boards.html}
    \item $A$: All legal actions change an empty field to either a $X$ or $O$ depending on the current player. A valid representation would be to encode this as a tuple $(i, p)$, where $i$ is the index of the empty field, and $p$ is the current player.
    \item Transition Function: $R$: The transition function takes the state and an action and returns the new state by switching the active player and adding an X or O into the appropriate empty space on the board.
    \item $P$: Tic Tac Toe is a two-player game, so this is $\{0,1\}$
    \item Terminal Test: $T$: The test checks whether there are any three $X$ or $O$ in a diagonal, row, or column. As a simplification, the test only has to check the symbol for the player who most recently played their turn.
    \item Terminal Utilities: $U$: The winning player gets $+1$, the losing player $-1$, a tie is worth $0$.
    \end{itemize}
\else
    \vspace{15em}
\fi

\item Draw the search tree including the terminal utilities for the board below. When drawing the tree, you can assume that $X$ plays perfectly and that you know $X$'s response to any play in advance. Therefore, you only need to expand $O$'s options in the tree.

\begin{figure}[h]
\centering
\includegraphics[width=0.1\textwidth]{figs/ttt}
\end{figure}

\ifsol
    \textcolor{blue}{the terminal utilities are all $-1$. No matter what $O$ does, $X$ will win.\footnote{Pictures taken from \url{http://neverstopbuilding.com/minimax}}}

    \begin{figure}[h]
    \centering
    \includegraphics[width=0.5\textwidth]{figs/ttt-sol}
    \end{figure}
\else
    \vspace{17em}
\fi

\item What move would $O$ play? How would you change the utility function for O to play something different?

\ifsol
    \textcolor{blue}{The move that $O$ plays would only depend on your implementation of this algorithm, since all the actions have the same value to $O$. A possible adjustment is to change the utility function to take the depth of the tree into account}
\else
    \vspace{7em}
\fi

\item Under what assumptions about player 2 should player 1 use minimax rather than expectimax search to select a move? Under what assumptions about player 2 should player 1 use expectimax rather than minimax search?

\ifsol
    \textcolor{blue}{Player 1 should use minimax if they expect player 2 to move optimally. If player 1 expects player 2 to move randomly, they should use expectimax to maximize their expected utility.}
\else
    \vspace{7em}
    \pagebreak
\fi

\item Imagine that player 1 wishes to act optimally (rationally), and player 1 knows that player 2 also intends to act optimally. However, player 1 also knows that player 2 (mistakenly) believes that player 1 is moving uniformly at random rather than optimally. How should player 1 use this knowledge to select a move?

\ifsol
    \textcolor{blue}{This problem can be solved by adding a second game tree. The new game tree is used to anticipate player 2's action. Here, all nodes for player 1 are replaced by chance nodes and player 1 can use expectimax to find player 2's policy. In the original game tree, player 1 can prune all actions by player 2 but the one resulting from expectimax.}
\else
    \vspace{10em}
\fi

\item Conduct alpha-beta pruning for the following minimax tree.

\begin{figure}[h]
\centering
\includegraphics[width=0.7\textwidth]{figs/ab}
\end{figure}

\ifsol
    \textcolor{blue}{The following pictures show the final solution and then the steps to computing the solution. If you want to practice your pruning skills, we recommend the website: \url{http://inst.eecs.berkeley.edu/~cs61b/fa14/ta-materials/apps/ab_tree_practice/}}\\
    \begin{center}
        \includegraphics[width=0.7\textwidth]{figs/ab-sol}

        \includegraphics[width=0.7\textwidth]{figs/alpha_beta_1} \includegraphics[width=0.7\textwidth]{figs/alpha_beta_2} \includegraphics[width=0.7\textwidth]{figs/alpha_beta_3} \includegraphics[width=0.9\textwidth]{figs/alpha_beta_4} \includegraphics[width=0.9\textwidth]{figs/alpha_beta_5}
    \end{center}
\else
    \vspace{10em}
\fi
\end{enumerate}
\pagebreak

\section*{CSPs}
CSPs are formalized as a triple $\langle X,D,C \rangle$.
\begin{enumerate}
\item $X = \{X_1, \ldots, X_n\}$: A set of variables in the problem
\item $D = \{D_1, \ldots, D_n\}$: The domains for these variables
\item $C = \{C_1, \ldots, C_m\}$: Constraints
\end{enumerate}
Constraints encode the limits on the values/domains for each variable contingent on the values/domains of other variables.
\\ \\
\noindent One way to solve a CSP is through \textbf{backtracking search} which is simply DFS with two changes:
\begin{enumerate}
\item Fix the variable ordering ($X_1 = D_1 \rightarrow X_2 = D_2 \equiv X_2 = D_2 \rightarrow X_1 = D_1$).
\item Check constraints as you go and backtrack if you violate any.
\end{enumerate}

\subsection*{Tasks}

Assume there are 5 CS classes that meet on MWF:
\begin{enumerate}
\item CS50 - Intro to CS: Meets from 8:00-9:00am
\item CS124 - Algorithms: Meets from 9:00-10:00am
\item CS181 - Machine Learning: Meets from 10:30-11:30am
\item CS182 - Artificial Intelligence: Meets from 8:30-9:30am
\item CS187 - Natural Language Processing: Meets from 9:00-10:00am
\end{enumerate}
and 3 professors who will be teaching these classes:
\begin{enumerate}
\item Professor A, who can teach CS50, CS181, and CS182.
\item Professor B, who can teach CS124, CS187, and CS181.
\item Professor C, who can teach CS50, CS124, and CS187.
\end{enumerate}
You are in charge of scheduling and are constrained by the fact that each professor can only teach one class at a time (Problem Adapted from Berkeley material).
\begin{enumerate}
\item Formulate this problem as a CSP  problem in which there is one variable per class, stating the domains, and constraints. Constraints should be specified formally and precisely, but may be implicit rather than explicit.

\ifsol
\textcolor{blue}{
    The following list first shows the variable and then the domains:
    \begin{itemize}
    \item $CS50$ - $\{A, C\}$
    \item $CS124$ - $\{B, C\}$
    \item $CS181$ - $\{A, B\}$
    \item $CS182$ - $\{A\}$
    \item $CS187$ - $\{B, C\}$
    \end{itemize}
    Implicit constraints: $\{CS50 \neq CS182, CS124 \neq CS182, CS124 \neq CS187, CS182 \neq CS187\}$
    }
\else
    \vspace{12em}
\fi

\item Draw the constraint graph associated with your CSP

\ifsol
    \vspace{1em}
    \begin{tikzpicture}[
            shorten >=1pt, auto, thick,
            node distance=2.5cm,
        main node/.style={circle,draw,fill=blue!20,font=\sffamily\Large\bfseries}
                                ]
          \node[main node] (a) at (0,0) {~50};
          \node[main node] (b) at (3,0) {124};
          \node[main node] (c) at (6,0) {181};
          \node[main node] (d) at (0,-3) {182};
          \node[main node] (e) at (3,-3) {187};

          \path[every node/.style={font=\sffamily\small}]
            (a) edge node {} (d)
            (b) edge node {} (d)
            (b) edge node {} (e)
            (d) edge node {} (e);
    \end{tikzpicture}
    \vspace{1em}
\else
    \vspace{12em}
    \pagebreak
\fi

\item Describe the standard backtracking search strategy to solve this problem. Write down a possible solution that you found using the strategy.

\ifsol
    \textcolor{blue}{We can use backtracking to solve this problem. The domains dictate the possible next assignments, and we consider one assignment per step. We then check whether constraints are violated after each assignment. Once an incomplete end is reached, we backtrack up the search tree. In the following solution, we use the standard backtracking approach and assign the variables numerical order and professors in alphabetical order (You can look at the lecture notes for heuristics for picking the next unassigned variable, or to filter possible solutions which will solve this problem faster!):
    \begin{enumerate}
    \item We first pick $CS50: A$. There are no violated constraints.
    \item We now pick $CS124: B$. There are no violated constraints. The partial solution is $\{$CS50: A, CS124: B$\}$.
    \item We now pick $CS181: A$. There are no violated constraints. The partial solution is $\{$CS50: A, CS124: B, CS181: A$\}$.
    \item We now pick $CS182: A$. This violates the constraint $CS50 \neq CS182$. Therefore, we backtrack all the way to step (a) before we can address this.
    \item We now first pick $CS50: C$. There are no violated constraints.
    \item We now pick $CS124: B$. There are no violated constraints. The partial solution is $\{$CS50: C, CS124: B$\}$.
    \item We now pick $CS181: A$. There are no violated constraints. The partial solution is $\{$CS50: C, CS124: B, CS181: A$\}$.
    \item We now pick $CS182: A$. There are no violated constraints. The partial solution is $\{$CS50: C, CS124: B, CS181: A, CS182: A$\}$.
    \item We pick $CS187: B$. This does violate the constraint $CS124 \neq CS187$. We backtrack to step (h).
    \item We pick $CS187: C$. This does not violate a constraint. We are done. The final solution is $\{$CS50: C, CS124: B, CS181: A, CS182: A, CS187: C$\}$.
    \end{enumerate}}
\else
    \vspace{35em}
\fi

\item Explain why it is a good heuristic to choose the variable that is most constrained but the value that is least constraining in a CSP search

\ifsol
    \textcolor{blue}{The reason that this heuristic is effective is that the variable with the least options is the hardest to satisfy, while the least constraining value leaves open the most options for other variables. This gives the highest chance of success. If we had done this above we would have finished the problem faster -- try it yourself!}
\else
    \vspace{5em}
\fi

\end{enumerate}

\end{document}


\subsection{VIPUR approach}
Variant interpretation using Rosetta (VIPUR) is a machine learning approach for predicting deleteriousness of proteins (loss of function) and uses sequential and structural information.
To train it the VIPUR training set (VTS) was made which contained sequential an structural features from protein structures that were acquired from Modbase \cite{pieper_modbase_2009} and
% modbase, a database of annotated comparative protein structure models and associated resources, pieper
SWISS-MODEL \cite{guex_automated_2009,bertoni_modeling_2017,benkert_toward_2011,bienert_swiss-model_2017,waterhouse_swiss-model:_2018}.
% Automated comparative protein structure modeling with SWISS-MODEL and Swiss-PdbViewer: A historical perspective, Guex
% Modeling protein quaternary structure of homo- and hetero-oligomers beyond binary interactions by homology, Bertoni
% Toward the estimation of the absolute quality of individual protein structure models, Benkert
% The SWISS-MODEL Repository—new features and functionality, Bienert
% SWISS-MODEL: homology modelling of protein structures and complexes, Waterhouse
Proteins that did not have a structure in modbase or SWISS-MODEL were modeled with Modeller (Section \ref{subsec:MM_Modeller}) from proteins that had the highest amino acid sequence identity to the desired protein.
based on protein fragments that had the highest amino acid sequence identity to the protein
Some structures from the databases had: duplicate chains, ligands, metals and non-standard amino acids which were removed to avoid inconsistencies for the generated features by tools.
For all proteins a mutation file was made that described which and how many residues had to be mutated, with this file DDG monomer (Section \ref{subsubsec:MM_DDG_Monomer}) could determine changes in the protein structure, most results by ddg were used as features.
Structural mutations of proteins that are in the VTS were introduced by a script using PyMOL (Section \ref{subsec:MM_PyMOL}) by default or PyRosetta (Section \ref{subsec:MM_PyRosetta}) when PyMOL was not available.
After a mutation the structure was optimized by the relax application (Section \ref{subsubsec:MM_Relax}) that produced 50 structures of a single variant, for each of these structures property scores where available of which all quartiles have been used as a machine learning feature.
of which the quartiles are used as a learning feature. Probe (Section \ref{subsec:MM_Probe}) calculated the solvent accessible surface area (SASA/ACCP) of a protein in square {\AA}ngstrom ({\AA}$^2$) which was used as a structural machine learning feature.
The sequence features of VIPUR were produced by PSI-blast (Section \ref{subsec:MM_PSI_BLAST}) on non mutated sequences and blasted against the NCBI protein database (nr) which resulted in a position specific scoring matrix (PSSM).
From the PSSM scores of the information content, non-mutated, mutated, the difference in scores between non-mutated and mutated and the difference between groups \cite{baugh_robust_2016, poultney_rational_2011} used as sequential feature for VIPUR.
% Robust classification of protein variation using structural modelling and large-scale data integration, Baugh et al.
% Rational Design of Temperature-Sensitive Alleles Using Computational Structure Prediction, Poultney et al.
With 106 features generated by the mentioned tools deleteriousness of a protein variant is determined with sparse logistic regression. The term sparse implies that a limited set of features was used because the weights "shrink" to 0 with regularization \cite{baugh_supplementary:_2016}.
%SUPPLEMENTARY: Robust classification of protein variation using structural modelling and large-scale data integration, Baugh et al.
\label{subsec:MM_VIPUR}

\subsection{VIPUR specific tools}

\subsubsection{PSI-BLAST}
Position specific iterative basic local alignment search tool (PSI-BLAST) focuses on distant relatives of proteins by making a profile of the sequence and querying it at a protein sequence database. With the generated results a new profile is constructed which is queried to the same database as the previous query. These steps are repeated several times to determine which residues are found in distant relatives and results is a position specific scoring matrix (PSSM) that describes the frequency of which residues are substituted by a specific other residue \cite{ncbi_psiblast_nodate,ncbi_pssm_nodate,wikipedia_blast_2019}.
%PSIBLAST, NCBI
%PSSM Viewer, NCBI
%BLAST, Wikipedia
From the PSSMs sequences features were acquired for the VIPUR machine learning method.
\label{subsec:MM_PSI_BLAST}
\newline
\textit{Position-Specific Iterated BLAST 2.7.1+}

\subsubsection{Probe}
Probe is able to evaluate atom packing for a single protein or for interacting proteins. It does this by creating a probe, which is described as a sphere like object, that marks an area with dots when at least two non-covalent atoms are in contact with the probe. \cite{word_visualizing_1999, richardson_lab_probe_nodate}. VIPUR used this tool to calculate solvent accessible surface area (SASA or ACCP).
%Visualizing and quantifying molecular goodness-of-fit: small-probe contact dots with explicit hydrogen atoms11Edited by J. Thornton,Word
%Probe Software : Kinemage Website, Richardson LAB
\label{subsec:MM_Probe}
\newline
\textit{version 2.16.130520}

\subsection{Rosetta}
Rosetta is a software suite that has a variety of tools that are developed to aid in macro molecular and antibody, analysis, design and prediction \cite{rosetta_commons_about_nodate}.
% About | RosettaCommons, Rosetta Commons
However no tools in the suite have been encountered that could introduce missense mutations in the proteins and was done by other software (Sections \ref{subsec:MM_PyMOL}, \ref{subsec:MM_PyRosetta}, \ref{subsec:MM_Modeller}). With the introduced mutations water had to be removed because some tools cannot predict structures well with: water, metals and amino acids that are no part of the standard (20) amino acids \cite{rosetta_commons_how_nodate}.
%How to prepare structures for use in Rosetta, Rosetta commons

Within the tools from Rosetta various scores are assigned to different properties related to bonds, interactions, energies and geometries within structures and are written into a score file.
From all different scoring metrics the Rosetta score, Rosetta energy unit (REU) or total\_score in the score files, can be used to compare models from the same protein with the same tool.
Not only is the score based on energy but also it has statistical terms which influence the score based on known favorable folds from existing structures that reside in the curated Rosetta database \cite{shourya_scoring_nodate}.
In summary to asses models, a lower Rosetta score makes a more natural model.
%Scoring Tutorial, Shourya et al.
\label{subsec:MM_Rosetta}
\newline
\textit{Rosetta software suite Version 3.10}

\subsubsection{Relax}
The Relax application was used by VIPUR and by SPVAA to relax the side chains to minimize energy levels within the local conformational search space \cite{rosetta_commons_relax_nodate} of the structure.
It determines the energy levels with a Monte Carlo method (Section \ref{section:Chap_Monte_Carlo}) and after a certain set of moves it produces a structure and starts anew \cite{conway_relaxation_2014,tyka_alternate_2011}.
%Relax application, Rosetta Commons
%Relaxation of backbone bond geometry improves protein energy landscape modeling, Conway et al.
%Alternate States of Proteins Revealed by Detailed Energy Landscape Mapping, Tyka et al.
\label{subsubsec:MM_Relax}

\subsubsection{DDG Monomer}
DDG monomer is meant to predict energetic stability of a point mutation in  monomeric protein.
The application was used by VIPUR to collect features related to energies bonds, bridges  and constraints differences between the wild type and a mutated protein.
To execute the tool a script had to be ran which renumbered the wild type pdb file and it required a "mutation file" that described the changes of a residues based on name and position\cite{leaver-fay_ddg_monomer_nodate}.
%ddg_monomer application, Andrew Leaver-Fay
\label{subsubsec:MM_DDG_Monomer}

\subsubsection{Rescore}
With this tool Rosetta scores can be calculated based on PDB files proteins structures \cite{jared_score_2016} , the output is identical to that is written within the score files produced by Relax (Section \ref{subsubsec:MM_Relax}).
%Score Commands, Jared
\label{subsubsec:MM_Rescore}

\subsubsection{Backrub}
The backrub application is based on the Monte Carlo method (Section \ref{section:Chap_Monte_Carlo}), and alters a protein by moving its backbone residues with a strategy called fix end move (FEM).
With this strategy, groups of residues are selected at random from the structure that can contain up to: four dihedral, two bond angles and two end points.
Both ends of a group are fixated at their position in which a new angle $\alpha$ arises, within this angle residues are pivoted in their natural occurring maximum range of $\pm \ang{10}$ \cite{betancourt_efficient_2005, smith_backrub_nodate}.
%Efficient Monte Carlo trial moves for polypeptide simulations, Betancourt
%Backrub application, Smith
With this application backbones of newly introduced mutations were altered, for each attempt a new file was generated and the scores were written to a score file. The lowest Rosetta scoring model was selected to undergo side chain relaxation with the Relax application (Section \ref{subsubsec:MM_Relax}).
\label{subsubsec:MM_Backrub}

\subsection{Structure prediction web services}

\subsubsection{Robetta prediction server}
The web tool Robetta integrates several tools to form protein structures with homology modeling (Section \ref{subsec:GD_Protein_modeling_techniques}).
Its only requirement is an amino acid sequence, but optionally constrains and fragments can be added to disallow movement of certain structures or add known fragments to avoid calculating pieces that are already known. With this information Robetta searches with the help of sequence aligners for known fragments and tries to incorporate them into a single protein structure \cite{song_high-resolution_2013,soding_protein_2005,kallberg_template-based_2012,yang_improving_2011,ovchinnikov_protein_2017}.
%High-Resolution Comparative Modeling with RosettaCM, Song
%Protein homology detection by HMM-HMM comparison, Soding
%Template-based protein structure modeling using the RaptorX web server,Källberg
%Improving protein fold recognition and template-based modeling by employing probabilistic-based matching between predicted one-dimensional structural properties of query and corresponding native properties of templates, Yang
%Protein structure determination using metagenome sequence data,Ovchinnikov
The known fragments of TNFRSF1A (Section \ref{subsec:GD_Protein_modeling_techniques}) were given as a template to Robetta and modeled into a whole protein to make it possible to introduce mutations and predict pathogenicity of a variants.\\
\label{subsec:MM_Robetta}
\textit{http://new.robetta.org/}

\subsubsection{I-TASSER prediction server}
The I-TASSER web server is a tool that is able to predict protein structures with a FASTA sequence. The first step it takes is finding structural templates which resemble the sequence by local meta-threading server (LOMETS).
LOMETS starts with multiple sequence alignment of which several sequences will undergo protein threading by different programs to form structural templates.
The templates are assessed made from: the highest alignment Z-score, a program within LOMETS specific confidence score and sequence identity \cite{zhang_lab_lomets_nodate, wu_lomets:_2007}.
%LOMETS, Zhang LAB
%LOMETS: A local meta-threading-server for protein structure prediction, Wu
The known fragments of TNFRSF1A (Section \ref{subsec:GD_Protein_modeling_techniques}) were given as a template to I-TASSER and modeled into a whole protein to make it possible to introduce mutations and predict pathogenicity of a variants.
\label{subsec:MM_I_TASSER}
\newline
\textit{Server version, https://zhanglab.ccmb.med.umich.edu/I-TASSER/}

\subsubsection{HOPE}
Have yOur Protein Explained (HOPE) is a web service that collects information of about a user specified missense mutation in a protein and comes from various sources. Uniprot (Section \ref{subsec:MM_Uniprot}) is queried with BLAST to find homologous sequences and structures, other features that are found on Uniprot are active sites, domains and various other sequence features that help to identify the function of a region. From the BLAST results homology models are made with Yasara that are sent of to WHAT IF web services that calculate structural information about the protein. Before the formation of a report all information is put into a decision tree to asses mutational effects in context of: contacts, structural locations, non-structural features, previous variant information and amino acid properties. \cite{venselaar_protein_2010,cmbi_hope_nodate,cmbi_hope_nodate-1,cmbi_hope_nodate-2}.
%Protein structure analysis of mutations causing inheritable diseases. An e-Science approach with life scientist friendly interfaces, Venselaar
%HOPE, CMBI
%HOPE about, CMBI
%HOPE methods, CMBI
With this method it is not possible to asses ligands and complexes at once but only a single missense mutation within a protein.
\label{subsec:MM_HOPE}
\textit{Version 1.1.1, https://www3.cmbi.umcn.nl/hope/}

\subsection{Structural modification and visualization software}

\subsubsection{Modeller}
The Modeller software that is developed for homology modeling but it was used for its utilities. Which allowed to complete protein data bank (PDB) structures with missing atoms, predict disulfide bonds that were missing and mutate protein residues \cite{modeller_about_nodate,eswar_comparative_2006,sali_comparative_1993,fiser_modeling_2000}.
%About MODELLER, Modeller
%Comparative Protein Structure Modeling Using Modeller, Eswar
%Comparative Protein Modelling by Satisfaction of Spatial Restraints, Sali
%Modeling of loops in protein structures., Fiser
\label{subsec:MM_Modeller}
\newline
\textit{Version 9.21}

\subsubsection{PyMOL}
Visualization of 3D structures, making images of proteins, putting monomeres in the correct position, replacing TNF $\beta$ structure with a TNF $\alpha$ in the bound structure and aligning the structures to measure the distance between models and X-ray structures were done with PyMOL \cite{schrodinger_pymol_nodate}. PyMOL was in VIPUR used in combination with Python (Section \ref{subsec:MM_Python}) to perform mutagenesis on the protein structures.
% PyMOL | pymol.org, Schrödinger
\label{subsec:MM_PyMOL}
\newline
\textit{Version 2.2.3}

\subsubsection{PyRosetta}
Is an application programming (API) which has Python bindings (Section \ref{subsec:MM_Python}) for the Rosetta software suite (Section \ref{subsec:MM_Rosetta}) and founds its use in VIPUR when no PyMOL (Section \ref{subsec:MM_PyMOL}) was available to mutate residues in a structure \cite{jeffrey_pyrosetta_nodate}.
%PyRosetta, Jeffry
\label{subsec:MM_PyRosetta}
\newline
\textit{Version 4}

\subsection{Amino acid sequence variant tables}

\subsubsection{GAVIN Machine Learning Data Table}
Is a collection of nucleotide mutations from rare diseases used by the GAVIN \cite{van_der_velde_gavin:_2017} machine learning approach. From this set the genes of TNFRSF1A (Section \ref{section:Chap_Cell_Death}) with a missense mutation were filtered (Section \ref{subsec:MM_R}) and written into a format which the variant effect predictor could (VEP) \cite{ensembl_variant_nodate} could read and translate from nucleotide to protein mutations. The classification of the variants was done by experts based on the five tier IARC classification system \cite{plon_sequence_2008}.
%GAVIN: Gene-Aware Variant INterpretation for medical sequencing, Van der Velde
%Variant Effect Predictor - Homo sapiens - GRCh37 Archive browser 96, ensembl
%Sequence variant classification and reporting: recommendations for improving the interpretation of cancer susceptibility genetic test results, Plon
\label{subsec:MM_GAVIN_data_table}

\subsubsection{gnomAD}
The gnomAD database consists of unified data from large scale genome sequencing data projects and is based on genome reference consortium human genome build 37 human genome 19 (GRCh37/hg19). From this database missense mutations were collected for TNFRSF1A (Section \ref{subsec:CD_TNFRSF1A}), no classification was known from these mutations \cite{gnomad_gnomad_nodate}.
%gnomAD,gnomAD
\label{subsec:MM_GnomAD}

\subsubsection{Infevers}
Infevers is a website about auto hereditary inflammatory diseases for which each are tables that contain information about mutations and their classification. The table for TRAPS (Section \ref{subsec:CD_TNFRSF1A}) was used to collect missense mutations of TNFRSF1A gene \cite{sarrauste_de_menthiere_infevers:_2003}.
%INFEVERS: the Registry for FMF and hereditary inflammatory disorders mutations, Sarrauste de Menthière
\label{subsec:MM_Infevers}

\subsection{Protein functional and structural databases}

\subsubsection{Research Collaboratory for Structural Bioinformatics}
Research Collaboratory for Structural Bioinformatics (RCSB) is a database where whole or fragmented experimentally determined proteins structures, that are published, can be found and downloaded. The Fragments for modeling (Sections \ref{subsec:MM_Robetta}, \ref{subsec:MM_I_TASSER}) whole TNFRSF1A (Section \ref{subsec:CD_TNFRSF1A}) (1EXT \cite{naismith_structures_1996}) and determining the differences in energy levels (Section \ref{subsubsec:MM_Relax}) with TNF $\alpha$ -$\beta$ (1TNR \cite{banner_crystal_1993}) with the interaction site were acquired from this database \cite{burley_rcsb_2018}.
%Structures of the extracellular domain of the type I tumor necrosis factor receptor,Naismith
%Crystal structure of the soluble human 55 kd TNF receptor-human TNFβ complex: Implications for TNF receptor activation, Banner
%RCSB Protein Data Bank: Sustaining a living digital data resource that enables breakthroughs in scientific research and biomedical education, Burley
\label{subsec:MM_RCSB}

\subsubsection{Uniprot}
Knowledge from various omic domains about proteins have been linked together into single database called Uniprot which makes all information accessible at once. For TNFRSF1A (Section \ref{section:Chap_Cell_Death}) the FASTA sequences were collected from Uniprot and for structures it redirected to (Section \ref{subsec:MM_RCSB}) \cite{the_uniprot_consortium_uniprot:_2015}.
%UniProt: a hub for protein information,The UniProt Consortium
\label{subsec:MM_Uniprot}

\subsection{Scripting languages}

\subsubsection{Python}
Both VIPUR and the single protein variant analysis approach (SPVAA) were written in Python. SPVAA was written in Python because of its ease of use and the modeller bindings (Section \ref{subsec:MM_Modeller}) that were available.
The mutations that were put together from the different tables (Sections \ref{subsec:MM_GnomAD}, \ref{subsec:MM_Infevers}, \ref{subsec:MM_GAVIN_data_table}) with R (Section \ref{subsec:MM_R}) were filtered by a Python script.
From the mutations a compact list was made by a different script that described the chains that had to be altered by modeller to introduce the appropriate mutation into a PDB file. From these PDB files several were selected to be optimized by pipeline that used backrub (Section \ref{subsubsec:MM_Backrub}) and Relax (Section \ref{subsubsec:MM_Relax} ) to optimize the structure.
\label{subsec:MM_Python}
\newline
\textit{Laptop version 2.7.15}
\newline
\textit{Server version 2.7.11}

\subsubsection{R scripting language}
With R the tables from gnomAD, GAVIN and Infevers (Sections \ref{subsec:MM_GnomAD}, \ref{subsec:MM_GAVIN_data_table}, \ref{subsec:MM_Infevers}) of TNFRSF1A missense mutations (Section \ref{subsec:CD_TNFRSF1A}) were merged together in a new comma seperated values file with their known classifications. Ordering and filtering the double mutations and removing double classifcations where done with Python (Section \ref{subsec:MM_Python}). It has also been used in combination ggplot2 \cite{wickham_create_nodate} and data.table \cite{dowle_rs_2019} to make density plots of all scores acquired from Rosetta Backrub and Relax (See the supplementary for R package versions).
%ggplot Wickham
% data table, Dowl et al
\label{subsec:MM_R}
\newline
\noindent
\textit{R scripting front-end version 3.5.2 (2018-12-20)}

\subsection{Utility software}

\subsubsection{Bash}
Unix like operating systems (OS) have a shell which allows users to interact with programs on a computer or with the computer itself based on commands submitted.  The default shell for MacOS and also for several Linux distributions is the Bourne again shell (Bash) which was used to launch Python scripts (Section \ref{subsec:MM_Python}) and submit jobs to the SLURM workload manager (Section \ref{subsec:MM_SLURM}).
\label{subsec:MM_Bash}
\newline
\textit{Laptop Version GNU bash, version 3.2.57(1)-release (x86\_64-apple-darwin18)}
\newline
\textit{Server Version GNU bash, version 4.1.2(2)-release (x86\_64-redhat-linux-gnu)}

\subsubsection{SLURM}
For computational jobs where a laptop or desktop does not suffice because due to the lack computational resources a computer cluster could come to aid.
These clusters consist out of several computers that execute resource intensive tasks, to manage these systems as optimal and fair as possible a workload manager like simple Linux utility resource management (SLURM), is installed. Jobs are submitted that request resources for execution and are scheduled on the systems queue.
\label{subsec:MM_SLURM}

\subsubsection{MPI}
Some tools from the Rosetta software suite (Sections \ref{subsec:MM_Rosetta}) have the ability to use multiple central processing unit (CPU) cores from a single computer or from multiple computers. With a message parsing interface (MPI) it is possible for software to communicate between CPU cores on the same and on different computers to exchange information about processes giving the ability to share work between computers and CPUs.
\label{subsec:MM_MPI}
\newline
\textit{OpenMPI/1.8.8-GNU-4.9.3-2.25}
\newline


%-*- coding:utf-8 -*-

\title{ALPS Tutorial \\ 03 -- Application Tutorial (1)}

\begin{document}

\lstset{language={C++},showspaces=false,rulecolor=\color[cmyk]{0, 0.29,0.84,0}}

\begin{frame}
  \titlepage
\end{frame}

\section*{Outline}
\begin{frame}[t,fragile]
   \tableofcontents
\end{frame}

\section{Before starting simulations}

\subsection*{\redb\whiteb\greenm}
\begin{frame}[t,fragile]{Before starting simulations -- common operations}
  \begin{itemize}
    % \setlength{\itemsep}{1em}
  \item Open terminal
    \begin{itemize}
    \item \alert{On MateriAps LIVE!: Start Menu $\Rightarrow$ ``System Tools'' $\Rightarrow$ ``LXTerminal''}
    \item On macOS: Open ``Terminal'' application
    \item If using a remote workstation, open the terminal and SSH to the remote node
    \end{itemize}

  \item PATH setting
    \begin{itemize}
    \item \alert{On MateriAps LIVE!: PATH has been configured already}
    \item In other environment, you have to run alpsvars.sh. ex)
\begin{lstlisting}
$ source /usr/local/alps/bin/alpsvars.sh
\end{lstlisting}
    \end{itemize}

  \item Tutorial files
    \begin{itemize}
    \item \alert{On MateriApps LIVE!: Tutorial files can be found in /usr/share/alps/tutorials/}
    \item In other environment, there should be ``tutorials'' directory in the place where ALPS is installed
    \end{itemize}
  \end{itemize}
\end{frame}

\section{Two-dimensional ferromagnetic Ising model}

\subsection*{\redb\whiteb\greenm}
\begin{frame}[t,fragile]{Phase transition in two-dimensional ferromagnetic Ising model (1)}
  \begin{itemize}
    % \setlength{\itemsep}{1em}
  \item Most simplest model that exhibits a phase transiton
    \[
      {\cal H} = - J \sum_{\langle i,j \rangle} \sigma_i \sigma_j \qquad (\sigma = \pm 1)
      \]
    \item Second-order phase transition happens  at critical temperature ($T_{\rm c} = 2/\log(1+\sqrt{2}) = 2.269\cdots$)
    \item At high temperatures ($T > T_{\rm c}$): paramagnetic phase, no long-range order due to entropy effect
    \item At low temperatures ($T < T_{\rm c}$): ferromagnetic phase, long-range order due to interaction between spins
    \item Specific heat and susceptibility diverge at the critical point (critical phenomena)
    \item Simulation of equilibrium state by simplemc classical Monte Carlo code (Metropolis method)
  \end{itemize}
\end{frame}

\subsection*{\redb\whiteb\greenm}
\begin{frame}[t,fragile]{Phase transition in two-dimensional ferromagnetic Ising model (2)}
  \begin{itemize}
    % \setlength{\itemsep}{1em}
  \item Copy tutorial file
\begin{lstlisting}
$ cp -r /usr/share/alps/tutorials/mc-09-snapshot .
$ cd mc-09-snapshot
\end{lstlisting}
  \item Convert parameter file into XML files parm9a.*.in.xml
\begin{lstlisting}
$ parameter2xml parm9a
\end{lstlisting}
  \item Execute simulation
\begin{lstlisting}
$ simplemc parm9a.in.xml
\end{lstlisting}
\item Plot results
\begin{lstlisting}
$ python plot9a.py
\end{lstlisting}
\item Close three plot windows
  \end{itemize}
\end{frame}

\subsection*{\redb\whiteb\greenm}
\begin{frame}[t,fragile]{Paramter file (parm9a)}
  \begin{itemize}
    \setlength{\itemsep}{1em}
  \item Look at the contents by ``less parm9a''
    \begin{itemize}
    \item \verb+LATTICE="square lattice"+ : specify square lattice
    \item \verb+J=1+ : ferromagnetic interaction ($J>0$)
    \item \verb+ALGORITHM="ising"+ : use Ising model simulator
    \item \verb+SWEEPS=65536+ : Monte Carlo steps
    \item \verb+L=8+ : linear extent of lattice ($L=8, 16, 24$)
    \item \verb+{ T = 5.0 }+ : list of temperatures
    \end{itemize}
  \item Variables not enclosed in \{ \} are common parameters
  \item Simulation is performed for each \{ \} (XML file (*.task*.*) is created for each temperature)
  \end{itemize}
\end{frame}

\subsection*{\redb\whiteb\greenm}
\begin{frame}[t,fragile,shrink]{Python plot script (plot9a.py)}
  \begin{itemize}
    % \setlength{\itemsep}{1em}
  \item Extraction results from data files
\begin{lstlisting}
data = pyalps.loadMeasurements(pyalps.getResultFiles(prefix='parm9a'),
  ['Specific Heat','Magnetization Density^2','Binder Ratio of Magnetization'])
\end{lstlisting}
  \item Organize by system sizes
\begin{lstlisting}
for item in pyalps.flatten(data):
    item.props['L'] = int(item.props['L'])
magnetization2 = pyalps.collectXY(data, x='T',y='Magnetization Density^2',
  foreach=['L'])
magnetization2.sort(key=lambda item: item.props['L'])
\end{lstlisting}
  \item Plot using matplotlib
\begin{lstlisting}
pyplot.figure()
alpsplot.plot(magnetization2)
\end{lstlisting}
  \end{itemize}
\end{frame}

\subsection*{\redb\whiteb\greenm}
\begin{frame}[t,fragile]{Visualization of snapshot of Ising spins (1)}
  \begin{itemize}
    % \setlength{\itemsep}{1em}
  \item Look at spin state in paramagnetic phase, in critical point, and in ferromagnetic phase
  \item Parameter SNAPSHOT\_INTERVAL is added in the parameter file (parm9b)
  \item Convert parameter file
\begin{lstlisting}
$ parameter2xml parm9b
\end{lstlisting}
  \item Execute simulation
\begin{lstlisting}
$ simplemc parm9b.in.xml
\end{lstlisting}
\item Convert snapshot
\begin{lstlisting}
$ snap2vtk parm9b.*.snap
\end{lstlisting}
  \end{itemize}
\end{frame}

\subsection*{\redb\whiteb\greenm}
\begin{frame}[t,fragile]{Visualization of snapshot of Ising spins (2)}
  \begin{itemize}
    % \setlength{\itemsep}{1em}
  \item Start ParaView (Start Menu $\Rightarrow$ ``Education'' $\Rightarrow$ ``ParaView Viewer''
  \item file $\Rightarrow$ open $\Rightarrow$ choose parm9b.task1.clone1.16384.vtk $\Rightarrow$ OK $\Rightarrow$ Apply
    \begin{itemize}
    \item filters $\Rightarrow$ common $\Rightarrow$ glyph (or click globe-like icon)
    \item Glyph Type = Box, X Length = 0.08, Y Length = 0.08, Maximum Number of Points = 20000 $\Rightarrow$ Apply
    \end{itemize}
  \item Click horizontal division icon at upper right corner
  \item file $\Rightarrow$ open $\Rightarrow$ choose parm9b.task2.clone1.16384.vtk $\Rightarrow$ OK $\Rightarrow$ Apply
    \begin{itemize}
    \item filters $\Rightarrow$ common $\Rightarrow$ glyph (or click globe-like icon)
    \item Set Glyph in the same way
    \end{itemize}
  \end{itemize}
\end{frame}

\subsection*{\redb\whiteb\greenm}
\begin{frame}[t,fragile]{Visualization of snapshot of Ising spins (3)}
  \begin{itemize}
    % \setlength{\itemsep}{1em}
  \item Click horizontal division icon at upper right corner
  \item file $\Rightarrow$ open $\Rightarrow$ choose parm9b.task3.clone1.16384.vtk $\Rightarrow$ OK $\Rightarrow$ Apply
    \begin{itemize}
      \item filters $\Rightarrow$ common $\Rightarrow$ glyph (or click globe-like icon)
      \item Set Glyph in the same way
    \end{itemize}
  \item Link cameras
    \begin{itemize}
    \item Adjust windows to become the same size
    \item Click middle window $\Rightarrow$ Tools $\Rightarrow$ Add Camera Link $\Rightarrow$ click left window
    \item Link right window to left one similarly
    \end{itemize}
  \end{itemize}
\end{frame}

\section{Visualization of spin vortices}

\subsection*{\redb\whiteb\greenm}
\begin{frame}[t,fragile]{Visualization of spin vortex in two-dimensional classical XY model}
  \begin{itemize}
    % \setlength{\itemsep}{1em}
  \item Convert parameter file, execute simulation, convert snapshots
\begin{lstlisting}
$ parameter2xml parm9c
$ simplemc parm9c.in.xml
$ snap2vtk parm9c.*.snap
\end{lstlisting}
Note that \verb+ALGORITHM="xy"+ in the parameter file
  \item Visualization using ParaView
    \begin{itemize}
      \item file $\Rightarrow$ open $\Rightarrow$ choose parm9c.task1.clone1.16384.vtk $\Rightarrow$ OK
      \item properties tab $\Rightarrow$ Apply
      \item Add Glyph
      \item Glyph Type = Arrow, Tip Radius = 0.2, Shaft Radius = 0.06, Translate = -0.1 0 0, Scale = 0.2 0.2 0.2 $\Rightarrow$ Apply
    \end{itemize}
  \end{itemize}
\end{frame}

\section{Antiferromagnetic classical Heisenberg model on triangular lattice}

\subsection*{\redb\whiteb\greenm}
\begin{frame}[t,fragile]{Antiferromagnetic classical Heisenberg model on triangular lattice}
  \begin{itemize}
    % \setlength{\itemsep}{1em}
  \item Convert parameter file, execute simulation, convert snapshots
\begin{lstlisting}
$ parameter2xml parm9d
$ simplemc parm9d.in.xml
$ snap2vtk parm9d.*.snap
\end{lstlisting}
Note that \verb+LATTICE+, \verb+J+, \verb+ALGORITHM+, \verb+H+ in the parameter file
  \item Visualization using ParaView
    \begin{itemize}
      \item file $\Rightarrow$ open $\Rightarrow$ choose parm9d.task1.clone1.16384.vtk $\Rightarrow$  OK
      \item properties tag $\Rightarrow$ Apply
      \item Add Glyph and set Arrow
      \item Display tag $\Rightarrow$ Color by $\Rightarrow$ Glyph Vector $\Rightarrow$ Z $\Rightarrow$ Properties tag
      \item Display one more snapshot (parm9d.task2.clone1.16384.vtk) and link cameras
    \end{itemize}
  \end{itemize}
\end{frame}

\end{document}