\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{minted}
\usepackage{hyperref}
\title{Second Project: <Name>.}
\lstset{
language=C, % choose the language of the code
numbers=left, % where to put the line-numbers
stepnumber=1, % the step between two line-numbers.
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=true, % sets if automatic breaks should only happen at whitespace
title=\lstname, % show the filename of files included with \lstinputlisting;
}
\author{
Santiago, Gamboa Ramírez\\
\texttt{santigr17@gmail.com}
\and
Juan Esteban, Navarro Camacho\\
\texttt{jnavcamacho@gmail.com}
}
\date{\today}
\begin{document}
\maketitle
\begin{abstract}
This project will discuss the usage of the logical programming language called Prolog to solve a diabolic magic squares made with 4 by 4 squares and Python as a front-end. A diabolic magic squares are matrix of 4 rows and 4 columns which have unique numbers on each cell from 1 to 16. This project will implement the solution of this problem using logical deduction.
\end{abstract}
\section{Introduction}
A diabolic magic squares are an special matrix made by n rows and n columns and each cell of this matrix has an unique value from 1 to \begin{math} n^2\end{math}. This matrix in some cases has an interesting behavior. This behavior makes to this matrix have some mathematical properties; form example the sum of each cell to make a row has the same result as the others. \newline
The diagonals have the same sum like the rows, the sum of all values from a column have the same value as the rows or diagonal have.
\begin{figure}
\centering
\includegraphics[width=0.7\textwidth]{diabolic01.png}\textit{}
\caption{\label{fig:i01} Making queries into a table.}
\end{figure}
\section{Objectives}
\section{Problem description}
On the image \ref{fig:i01} it shows a diagonal magic square, and if the user make a sum of the cells of some rows or some column the result will be the same for both expressions. There are more conditions that proves this square as magic or diabolic.\newline
For example:
\section{Requirements}
For the implementation of this project, its necessary to create 2 programs that will be interacting with each other.\newline
\begin{itemize}
\item A Frontend, which purpose will be to interact with the user , take care of I/O operations and communicate with the backend.
\item A backend, where all the diabolic magic square resolution is going to happen.
\item This backend will be receiving the entries for the execution of the predicates.
\item The Frontend will be developed in any language chosen by the student, it has to connect with the backend (Prolog) to pass over to the Prolog program the operation requested by the user.
\end{itemize}
\section{User Guide}
The next series of images illustrate the use of the program.
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms0.png}\textit{}
\caption{\label{fig:i0} Command to run the program}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms1.png}\textit{}
\caption{\label{fig:i0} This is the main window of the program, here the user can see the grid to insert a square, also has the option to ask for an amount of Diabolic Magic Squares}
\end{figure}
The following images show the different kind of errors that can occur.
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms2.png}\textit{}
\caption{\label{fig:i0} This message show when the button "verify" is pressed.}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms2.png}\textit{}
\caption{\label{fig:i0} This message show when the button "verify" is pressed.}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms2.png}\textit{}
\caption{\label{fig:i0} This message show when the button "verify" is pressed.}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms2.png}\textit{}
\caption{\label{fig:i0} This message show when the button "verify" is pressed.}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms3.png}\textit{}
\caption{\label{fig:i0} This message show when the button "verify" is pressed.}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms4.png}\textit{}
\caption{\label{fig:i0} This message show when the button "show" is pressed.}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms5.png}\textit{}
\caption{\label{fig:i0} This message show when the button "verify" is pressed.}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms6.png}\textit{}
\caption{\label{fig:i0} This is a warning for the user in order to ask for patience when the button "show" is pressed.}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms7.png}\textit{}
\caption{\label{fig:i0} This window is displayed when the button "show" is pressed and the value is correct.}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{dms8.png}\textit{}
\caption{\label{fig:i0} Here the program asks to the user if he wants to continue to a building part of the program.}
\end{figure}
\section{Development environment}
\subsection{SWI-Prolog}
This framework offers and easy way to implement prolog queries in terminal, it is compatible with the most common programming languages and development environments like Java, Python and Netbeans as an IDE.
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{diabolic02.png}\textit{}
\caption{\label{fig:i02} SWI-Prolog environment on GNU-Linux}
\end{figure}
\subsection{Python with PySwip}
PySWIP requires SWI-Prolog as a shared library to make an interface to make queries from Python to Prolog.\newline
To install PySwip this tutorial will show how to: \url{https://pyswip.googlecode.com/svn-history/r129/trunk/INSTALL}
\subsection {JPL for Java}
JPL is a set of Java classes and C functions providing an interface between Java and Prolog. This framework uses Java Native Interface to work with the prolog queries. This framework has to types of interfaces, the low level and the high level.\newline
\begin{itemize}
\item Low Level: For C and C++ development.
\item High Level: For Java programmers.
\end{itemize}
\subsection{NetBeans Java}
There is another option to make queries to from from another programming language, this language is called Java.For Netbeans IDEs, after install jpl libraries the user must to include the .jar files.
\section{Program design}
The program consists of two main parts, the first is the logical part responsible for calculating the Diabolic Magic Squares, it is composed of a function that checks whether a list is a Diabolic Magic Square and returns true or false.
Part two consists fronted, or user interface, which query logic to the outcome of the question asked by the user.
It also has the function of displaying pictures, which are displayed in a new window, depending on the amount desired by the user.
\section{Data Structures and functions}
\subsection{User Interface}
class guiDMsquares: with this class we manage the windows and create all the interface\newline
function verify: this function valid all the entries and if these are right concatenates the values.\newline
function suqares1-10: Here is where we construct the squares and place them in the new window, this function also calls the query to ask prolog for the squares.\newline
function error: We manage the errors by a code, in the message is the causes of the error and we unify the errors in one function.\newline
function random: With this processor we fill all the grid with random values.\newline
function clear: It is in charge to clean the values of the entries grid.
\subsection{Diabolic.pl}
function diabolic: This function is called when we need to verify a list.\newline
function diabolico: This other function return all the possible Diabolic Magic Squares.
\section{Student activity log}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
Date & Juan's Task Description & Spent Time \\
\hline\hline
8/April/2016 & Design and understanding the project & 4 hours\\
10/April/2016 & Deciding which language is better for the project & 3 hours\\
11/April/2016 & Understanding prolog using swi prolog & 2 hours\\
12/April/2016 & Research diabolic magic squares, how to verify one & 14 hours\\
13/April/2016 & Design the principal menu with Santiago and simple functions & 10 hours\\
14/April/2016 & Research how to use Java jpl library & 4 hours\\
15/April/2016 & Fixing errors with pyswip, figure it out how to communicate in other way. & 4 hours\\
\hline
& Total & 54 hours\\
\hline
\end{tabular}
\end{center}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
Date & Santiago's Task Description & Spent Time \\
\hline\hline
06/April/2016 & Installing swi prolog and looking for other options & 4 hours\\
07/April/2016 & Try some functions. Install pyswip and test it & 4 hours\\
09/April/2016 & Create a simple interface & 4 hours\\
10/April/2016 & Meeting with Juan to define the structures of the table. Scheme and register. Start programming the table, define the modules. & 4 hours\\
11/April/2016 & Create a method that gets user entries and put it into a list. & 4 hours\\
12/April/2016 & Error connecting python and swi prolog. & 6 hours\\
14/April/2016 & Trying to install java jpl for project& 6 hours\\
15/April/2016 & finish the interface and doing documentation & 7 hours\\
\hline
& Total & 21 hours\\
\hline
\end{tabular}
\end{center}
\section{Project final status}
This program has successfully verify and query for less than 26 squares.
The communication between python and prolog is slow and take a while.
The interface has a good validation of the entries and give feedback or message errors to the user.
\subsection{Bugs}
If you consult for a number of squares and them try to verify another square the query fails.
\subsection{Not resolved Problems}
Show all, the method to show all the possible solutions for a Diabolic Magic Square stops when solves the 26th square.
\subsubsection{Casting List from Prolog to Python}
This is the main not resolved problem: \newline
When the user types to get a Diabolic Magic Square using Prolog from terminal the result will be like this example.
\noindent Getting a diabolic magic square :
\begin{minted}{bash}
$ prolog diabolic.pl
$ ?-diabolico(X).
$ X = [1, 8, 10, 15, 12, 13, 3, 6, 7|...] [write]
$ X = [1, 8, 10, 15, 12, 13, 3, 6, 7, 2, 16, 9, 14, 11, 5, 4]
\end{minted}
But in python when the user wants to include this line into a query on Python, the result will be.
\noindent Print on Python
\begin{minted}{bash}
$ python test.py
>> {X = Variable (16), Variable(16),...}
>>
\end{minted}
This means that prolog array of int can't be displayed using a normal casting.
\subsubsection{Including .jar Import to Link Java and Prolog}
After intalling swi-prolog on linux, netbeans can't link the jar to the file.
\subsubsection{Pwsip install on Linux Mint}
The make file to install the swi-prolog made some erros on Juan's computer, just Santiago's can run pyswip with python
\section{Conclusions}
There is no enough updated documentation to the usage of Python with Pyswip for complex Prolog and Python Applications. It means for complex projects Python is not a good option.
\section{Suggestions and recommendations}
For JPl and Java development. As the site web says: currently JPL only supports the embedding of a Prolog engine within the Java VM.
For many further versions this API will be available for C and C++ development. \newline
Python and PySwip are good options to implement queries if the code on prolog has the facts defined, but it the user wants to implement a query with a prolog returned variables is not warrantied the success of the app.\newline
If the user wants to implement Netbeans and JPL: Ensure that the Linux distribution doesn't have OpenJDK intalled this is because JPL works with JDK private version, the non-free. \newline
To install the correctly version of JDK the user needs to go the the following web site and follow every step described there. This web site has the install guide for x86 and x64 architectures for GNU-Linux.\newline
Prolog Mode for Emacs: This is and IDE to manage and debug prolog applications and brings with some tools to understand and read efficiently prolog syntax. Its debug plugin is useful to follow the track of the logic fact deduction.\newline
\section{References}
\begin{itemize}
\item Itself, have. "Have A Function In Scheme Return Value (Or Do Something Else) And Call Itself". Stackoverflow.com. N.p., 2016. Web. 8 Apr. 2016.
\item Boyer, C. "Multimagie News." Apr. 4, 2006. \url{http://www.multimagie.com//English/News0604.htm.}
\item Sloane, N. J. A. Sequence A027567 in "The On-Line Encyclopedia of Integer Sequences."\url {}
\item Rosser, J. B. and Walker, R. J. "The Algebraic Theory of Diabolical Squares." Duke Math. J. 5, 705-728, 1939. \url{}
\item Kraitchik, M. "Panmagic Squares." §7.9 in Mathematical Recreations. New York: W. W. Norton, pp. 143 and 174-176, 1942. \url{}
\item Hunter, J. A. H. and Madachy, J. S. "Mystic Arrays." Ch. 3 in Mathematical Diversions. New York: Dover, pp. 24-25, 1975. \url{}
\item Gardner, M. "Magic Squares and Cubes." Ch. 17 in Time Travel and Other Mathematical Bewilderments. New York: W. H. Freeman, pp. 213-225, 1988.
\item Gardner, M. The Second Scientific American Book of Mathematical Puzzles Diversions: A New Selection. New York: Simon and Schuster, pp. 135-137, 1961.
\end{itemize}
\end{document}