some tricks in latex

how to use the latex

insert reference in your latex

  • \cite{nahin2012chases}

insert a complicated equations in your latex

  • \begin{equation}\label{xx}
  • \begin{split}
  • y(x)& = (n/(1-n^{2})) * x_{0} + [1/2 * (x_{0}-x)]*\
  • & [(1-(x-x/x_{0})^{n}/(1+n) - (1-x/x_{0})^{-n}/(1-n)]\
  • & n = v_{m}/v_{p}
  • \end{split}
  • \end{equation}

insert the pseudo-code

  • The outputs for show:
    -algorithm
  • corresponding codes in latex:
\begin{
    
    algorithm}
\caption{
    
    Hybrid Algorithm}\label{
    
    hybrid}
\begin{
    
    algorithmic}[1]  
	\State\textit{
    
    Initialize $\theta$, $\delta_{
    
    p}$ and } $t \gets 0$
	\While{
    
    \textit{
    
    $(x_{
    
    p},y_{
    
    p}) != (x_{
    
    e},y_{
    
    e})$ }}
		\If {
    
    $y_{
    
    p} = y_{
    
    e}$}  
			\State $e_{
    
    q} = BASIC$
			\Else
			\State $e_{
    
    q} = DEV$  
		\EndIf
		\State $compare(e_{
    
    q}, (x_{
    
    p},y_{
    
    p}), (x_{
    
    e},y_{
    
    e}), \theta, t, v_{
    
    p}, v_{
    
    e}, 0, 0)$
		\State\textit{
    
    Set algo}
		\If{
    
    \textit{
    
    Stack.top = null}}
			\State $capture(algo, e_{
    
    q}, (x_{
    
    p},y_{
    
    p}), (x_{
    
    e},y_{
    
    e}), \theta, t, v_{
    
    p}, v_{
    
    e})$
			\State $return(t,(x_{
    
    p},y_{
    
    p}))$
			\Else
				\If{
    
    $Stack.top(t_{
    
    d}) = t $}
					\State $compare(e_{
    
    q}, (x_{
    
    p},y_{
    
    p}), (x_{
    
    e},y_{
    
    e}), \theta,t, v_{
    
    p}, v_{
    
    e},$ \State $ ang_{
    
    d}, vel_{
    
    d})$
					\State\textit{
    
    Set algo}
					\State $move(algo, e_{
    
    q}, (x_{
    
    p},y_{
    
    p}), (x_{
    
    e},y_{
    
    e}), \theta, t, v_{
    
    p}, v_{
    
    e},$ \State $ ang_{
    
    d}, vel_{
    
    d})$
					\State $Stack.pop()$
					\State\textit{
    
    Update $\delta_{
    
    p}$}
				\Else
					\State $move(algo, e_{
    
    q}, (x_{
    
    p},y_{
    
    p}), (x_{
    
    e},y_{
    
    e}), \theta, t, v_{
    
    p}, v_{
    
    e}, 0, 0)$
				\EndIf
			\EndIf
		\State $t++$
	\EndWhile
	\State \Return $(x_{
    
    p},y_{
    
    p}), t$
\end{
    
    algorithmic}
\end{
    
    algorithm}
  •  ,  ( x p , y p ) (x_{p},y_{p}) (xp,yp), v ⃗ p \vec v_{p} v p
  • v p v_{p} vp
  • ( x e , y e ) (x_{e},y_{e}) (xe,ye), v ⃗ e \vec v_{e} v e
  • \subsection{Terminology}
    \subsubsection*{Pursuer}
    At any given point of time, the coordinates of pursuer will be stored as ( x p , y p ) (x_{p},y_{p}) (xp,yp), v ⃗ p \vec v_{p} v p is the velocity and the magnitude of his speed will be as v p v_{p} vp.\

\subsubsection*{Evader}
Similarly, At any given point of time, the coordinates of evader will be stored as ( x e , y e ) (x_{e},y_{e}) (xe,ye), v ⃗ e \vec v_{e} v e is the velocity and the magnitude of his speed will be as v e v_{e} ve.\

\subsubsection*{Other}
( x s , y s ) (x_{s},y_{s}) (xs,ys) is going to be the final capture point for the given situation, and n = v e / v p n = v_{e}/v_{p} n=ve/vp is the speed ratio of pursuer and evader, δ \delta δ is the inaccuracy by which pursuer is determining the speed of evader.

\subsection{Traditional Approach}
As discussed above, the tradition pursuit analysis gives us the result based upon the concept that initially the pursuer is at (0,0) and evader is at ( 0 , x m ) (0,x_{m}) (0,xm). But that might not be the usual case,

As seen in the fig.2, Initially the pirate ship is considered at $(x_{
    
    p},y_{
    
    p})$ and the merchant ship is at $(x_{
    
    e},y_{
    
    e})$ with speeds $v_{
    
    p} and v_{
    
    e}$.
Now the new equation for such scenario will be 
- \begin{
    
    equation}\label{
    
    xx}
\begin{
    
    split}
y(x)& = (n/(1-n^{
    
    2})) * (x_{
    
    e}-x_{
    
    p}) + [1/2 * (x_{
    
    e}-x_{
    
    p}-x)]*\\
& [(1-(x-x_{
    
    p})/(x_{
    
    e}-x_{
    
    p}))^{
    
    n}/(1+n) - \\
& (1-(x-x_{
    
    p})/(x_{
    
    e}-x_{
    
    p}))^{
    
    -n}/(1-n)]\\
\end{
    
    split}
\end{
    
    equation}

\subsubsection{Distance Deviation}
It is not compulsory for both the pursuer and evader to be in same line, i.e. y e = y p = y ′ y_{e}=y_{p}=y_{'} ye=yp=y. We can compute the capture point for such case by reverse engineering the traditional formula.
\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.6]{3.JPG}
\caption{Distance Deviation}\label{Saturation}
\end{center}
\end{figure}

Here in fig.3 we know that when evader is at ( x e , y e ) (x_{e},y_{e}) (xe,ye) and pursuer is at ( x p , y p ) (x_{p},y^{p}) (xp,yp) then we need to get the value of x c x_{c} xc in the graph and after that we will get the hypothetical starting position, which in turn can be used to calculate the capture point.
\begin{equation}\label{xx}
\begin{split}
y_{p}& = y_{c} + (n/(1-n^{2})) * (x_{e}-x_{c}) + [1/2 * (x_{e}-x_{c}-x_{p})]*\
& [(1-(x_{p}-x_{c})/(x_{e}-x_{c}))^{n}/(1+n) - \
& (1-(x_{p}-x_{c})/(x_{e}-x_{c}))^{-n}/(1-n)]\
\end{split}
\end{equation}
here ( x c , y c ) (x_{c},y_{c}) (xc,yc) can be estimated, after which we can calculate the capture point for such case.

\subsubsection{Angular Deviation}
Apart from linear variation, there might be some angular deviation followed by merchant ship.

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.6]{4.JPG}
\caption{Angular Deviation}\label{Saturation}
\end{center}
\end{figure}
As shown in the fig.4 there is a variation of θ \theta θ. This situation can be solved by using the rotation of the axis w.r.t (0,0). The co-ordinates for any point P(x,y) will be
\begin{equation}\label{xx}
\begin{split}
x^{’}& = x * \cos\theta + y * \sin\theta \
y^{’}& = -x * \sin\theta + y * \cos\theta \
\end{split}
\end{equation}

Then we will use the same equations (1 and 2) to get the capture point, and then convert the co-ordinates back to the original axis.

\subsection{Modern Approach}
In this, the chaser is aware of the speed of target, with certain accuracy. In the traditional example of pirate ship analysis, the pursuers will always be aware of the speed of merchant ship v e v_{e} ve with inaccuracy of δ \delta δ\
Using the above information, the pursuer can calculate the nearest capture point and move towards it in linear shortest path motion.
\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.6]{5.JPG}
\caption{Modern Approach}\label{Saturation}
\end{center}
\end{figure}

Here in fig.5, ( x e , y s ) (x_{e},y_{s}) (xe,ys) is the capture point which can be generated as,\
Case-1. δ \delta δ = 0\
In this case δ \delta δ = 0, means the pursuer is able to measure the speed accurately.
\begin{equation}\label{xx}
\begin{split}
(y_{s}-y_{e})/v_{e}& = ((x_{e} - x_{p})^{2} + (y_{s} - y_{p}){2}){1/2}/v_{p}\
\end{split}
\end{equation}
The only unknown in the above equation is y s y_{s} ys, and it can be solved as a quadratic equation. Out of which one solution will be ( < y p ) (<y_{p}) (<yp) which can be ignored.\

Case-2. δ i \delta_{i} δi is positive\
In such case, the measured speed will be more than the actual speed of merchant ship. So the pirate ship will reach the capture point earlier than the merchant ship and it has to move towards merchant ship for some time.\
Here the measured speed of merchant ship = v e v_{e} ve\
and actual speed is v e − δ i ∗ v e v_{e} - \delta_{i}*v_{e} veδive\
So the total time here,\
\begin{equation}\label{xx}
\begin{split}
(y_{s}-y_{e})/v_{e} + ((y_{s}-y_{e})/v_{e})* \delta_{i}*v_{e} * (v_{p} + v_{e} - \delta_{i}*v_{e})\
\end{split}
\end{equation}

Case-3. δ i \delta_{i} δi is negative\
Similarly as above case, after reaching the capture point, the pirate ship has to trail behind merchant ship.
\
Here the measured speed of merchant ship = v e v_{e} ve\
and actual speed is v e + δ i ∗ v e v_{e} + \delta_{i}*v_{e} ve+δive\
So the total time here,\
\begin{equation}\label{xx}
\begin{split}
(y_{s}-y_{e})/v_{e} + ((y_{s}-y_{p})/v_{e})* \delta_{i}*v_{e} * (v_{p} - v_{e} - \delta_{i}*v_{e})\
\end{split}
\end{equation}

\textit{Distance Deviation} in this approach won’t require any special calculation, similarly \textit{Angular Deviation} can be handled by the same axis rotation method.

\section{Model}

\subsection{Basic Algorithm}
A basic algorithm, is the one that follows any one of the two approaches throughout the scenario. Which means that if it is set for the traditional approach then it will keep on following that until we have reached the capture point. Another assumption that is taken into consideration is that in the case of such basic algorithm, we are taking “delta” as zero when following the modern method. Which means that pursuer is accurately able to determine the speed of evader.\

\subsubsection*{Inputs} ( x p , y p ) , ( x e , y e ) , v p , v e , θ (x_{p},y_{p}), (x_{e},y_{e}), v_{p}, v_{e}, \theta (xp,yp),(xe,ye),vp,ve,θ at t=0 (Starting Values)\

\subsubsection*{Stack} The stack is something which is going to play a pivotal role, it is going to reflect the changes in evader’s speed and angle over the period of time. Each entry in the stack can be considered as t d t_{d} td (Time when the deviation occurs), a n g d ang_{d} angd (angular deviation), v e l d vel_{d} veld (velocity deviation). The stack can be considered as the part of the input, if there is a smart algorithm which is written by the perspective of evader then there is going to be no need to keep the stack values as they will be automatically generated from the evader algorithm.\

\subsubsection*{Output} ( x s , y s ) , T (x_{s},y_{s}), T (xs,ys),T (Total time taken in the chase).\

\begin{algorithm}
\caption{Basic Algorithm}\label{basic}
\begin{algorithmic}[1]
\State\textit{Initialize θ \theta θ and } t ← 0 t \gets 0 t0
\While{\textit{ ( x p , y p ) ! = ( x e , y e ) (x_{p},y_{p}) != (x_{e},y_{e}) (xp,yp)!=(xe,ye) }}
\If { y p = y e y_{p} = y_{e} yp=ye}
\State e q ← N O D E V e_{q} \gets NO DEV eqNODEV
\Else
\State e q ← D E V e_{q} \gets DEV eqDEV
\EndIf
\If{\textit{Stack.top = null}}
\State c a p t u r e ( e q , ( x p , y p ) , ( x e , y e ) , θ , t , v p , v e ) capture(e_{q}, (x_{p},y_{p}), (x_{e},y_{e}), \theta, t, v_{p}, v_{e}) capture(eq,(xp,yp),(xe,ye),θ,t,vp,ve)
\State r e t u r n ( t , ( x p , y p ) ) return(t,(x_{p},y_{p})) return(t,(xp,yp))
\Else
\If{$Stack.top(t_{d}) = t $}
\State m o v e ( e q , ( x p , y p ) , ( x e , y e ) , θ , t , v p , v e , a n g d , v e l d ) move(e_{q}, (x_{p},y_{p}), (x_{e},y_{e}), \theta, t, v_{p}, v_{e}, ang_{d}, vel_{d}) move(eq,(xp,yp),(xe,ye),θ,t,vp,ve,angd,veld)
\State S t a c k . p o p ( ) Stack.pop() Stack.pop()
\Else
\State m o v e ( e q , ( x p , y p ) , ( x e , y e ) , θ , t , v p , v e , 0 , 0 ) move(e_{q}, (x_{p},y_{p}), (x_{e},y_{e}), \theta, t, v_{p}, v_{e}, 0, 0) move(eq,(xp,yp),(xe,ye),θ,t,vp,ve,0,0)
\EndIf
\EndIf
\State t + + t++ t++
\EndWhile
\State \Return ( x p , y p ) , t (x_{p},y_{p}), t (xp,yp),t
\end{algorithmic}
\end{algorithm}

Here, once we have provided the valid inputs to the above algorithm, it runs the while loop until both evader and pursuer have not met. In the loop we are using a variable e q e_{q} eq which determines whether there is any distance deviation or not. It simply acts as a flag.\

There are two different functions used in the above algorithm,\
\subsubsection*{1.Move} Used to move both the pursuer and evader in their direction at a distance of unit time quantum.\
\subsubsection*{2.Capture} Used to finish the algorithm, if there are no more runtime deviations and returns the capture point as well as total time taken.\
\
Algorithm 3, details about the capture function, it applies the previous equations, based upon the requirement. Move function follows the same conditions, with a little change that instead of finishing the whole chase, it return the values of ( x p , y p ) , ( x e , y e ) (x_{p},y_{p}), (x_{e},y_{e}) (xp,yp),(xe,ye) after one time quantum only.\
\begin{algorithm}
\caption{Move ( e q , ( x p , y p ) , ( x e , y e ) , θ , t , v p , v e , a n g d , v e l d ) (e_{q}, (x_{p},y_{p}), (x_{e},y_{e}), \theta, t, v_{p}, v_{e}, ang_{d}, vel_{d}) (eq,(xp,yp),(xe,ye),θ,t,vp,ve,angd,veld)}
\begin{algorithmic}[1]
\State\textit{Update v e ← v e + v e l d v_{e} \gets v_{e} + vel_{d} veve+veld}
\State\textit{ θ ← θ + a n g d \theta \gets \theta + ang_{d} θθ+angd}
\State\textit{return ( x p , y p ) , ( x e , y e ) (x_{p},y_{p}), (x_{e},y_{e}) (xp,yp),(xe,ye) with single quantam movement.}

\end{algorithmic}
\end{algorithm}
\

\begin{algorithm}
\caption{Capture ( e q , ( x p , y p ) , ( x e , y e ) , θ , t , v p , v e ) (e_{q}, (x_{p},y_{p}), (x_{e},y_{e}), \theta, t, v_{p}, v_{e}) (eq,(xp,yp),(xe,ye),θ,t,vp,ve)}
\begin{algorithmic}[1]
\If { θ = 0 \theta = 0 θ=0}
\State\textit{No angular deviation}
\If{$ e_{q} = 0 $}
\State\textit{No distance deviation either.}
\State\textit{Use eq.2 and return ( x p , y p ) (x_{p},y_{p}) (xp,yp)}
\Else
\State\textit{Distance deviation exists.}
\State\textit{Use eq.3 and return ( x p , y p ) (x_{p},y_{p}) (xp,yp)}
\EndIf
\Else
\State\textit{Angular deviation exists}
\State\textit{Use eq.4 to rotate axis over θ \theta θ}
\If{$ e_{q} = 0 $}
\State\textit{No distance deviation either.}
\State\textit{Use eq.2 and rotate axis back.}
\State\textit{return ( x p , y p ) (x_{p},y_{p}) (xp,yp)}
\Else
\State\textit{Distance deviation exists.}
\State\textit{Use eq.3 and rotate axis back.}
\State\textit{return ( x p , y p ) (x_{p},y_{p}) (xp,yp)}
\EndIf

\EndIf    

\end{algorithmic}
\end{algorithm}

The difference between these two functions is that, if there are no more deviations in the speed or angle of evader in future then it is better to finish the algorithm. Whereas on the other hand if there are some future deviations then we must only move towards the next coordinates.\
\ Now using above functions, algorithm first checks which one of the previous equations is applicable in existing situation broadly basic or deviation the rest of the classification is taken care inside move and capture functions. Once equation type is determined, it checks if the stack is empty. If true that means, there are no further deviations in the future and we can simply call the capture function and finish algorithm. Else it checks whether the current time is same as the time on which deviation is supposed to happen and depending upon that it calls the move function with certain parameters.

\subsection{Delta}
As discussed earlier, if pursuer is able to determine the speed of evader accurately then all we need is basic algorithm only which is going to run on modern approach. But that can’t be normal case, there must always be some inaccuracy, it has been observed that even in latest radar speed estimations there is some inaccuracies.\cite{tunaley2003estimation}\cite{shang2010low}\
Here we will be using two different values of delta-\
\subsubsection{ δ p \delta_{p} δp} This value is calculated with time and is known to the pursuer as his existing inaccuracy.\

\subsubsection{ δ i \delta_{i} δi} Inaccuracy associated with ith iteration in stack.\
\begin{equation}
\delta_{p} = \delta_{p} + |\delta_{i}|/(i+1)
\end{equation}

\subsection{Hybrid Algorithm}
For these reason, there is a requirement of a hybrid algorithm which incorporates best of both methods. This algorithm compares both methods at each iteration and then pick the one which is best suitable for current values. It also keep on updating δ p \delta_{p} δp with each iteration.\
This algorithm is almost similar to basic algorithm with a few changes-\\

  1. There is a δ i \delta_{i} δi associated with each iteration of stack, which is unknown to pursuer until t < = t d t<=t_{d} t<=td\\
  2. There is a new function named compare, which actually takes both derivations of basic algorithms and runs them on the input. After which it provides which algorithm is better suited for current case.\\
  3. There is a new variable called algo, which is used to hold the information or output of compare function.\\

\begin{algorithm}
\caption{Hybrid Algorithm}\label{hybrid}
\begin{algorithmic}[1]
\State\textit{Initialize θ \theta θ, δ p \delta_{p} δp and } t ← 0 t \gets 0 t0
\While{\textit{ ( x p , y p ) ! = ( x e , y e ) (x_{p},y_{p}) != (x_{e},y_{e}) (xp,yp)!=(xe,ye) }}
\If { y p = y e y_{p} = y_{e} yp=ye}
\State e q = B A S I C e_{q} = BASIC eq=BASIC
\Else
\State e q = D E V e_{q} = DEV eq=DEV
\EndIf
\State c o m p a r e ( e q , ( x p , y p ) , ( x e , y e ) , θ , t , v p , v e , 0 , 0 ) compare(e_{q}, (x_{p},y_{p}), (x_{e},y_{e}), \theta, t, v_{p}, v_{e}, 0, 0) compare(eq,(xp,yp),(xe,ye),θ,t,vp,ve,0,0)
\State\textit{Set algo}
\If{\textit{Stack.top = null}}
\State c a p t u r e ( a l g o , e q , ( x p , y p ) , ( x e , y e ) , θ , t , v p , v e ) capture(algo, e_{q}, (x_{p},y_{p}), (x_{e},y_{e}), \theta, t, v_{p}, v_{e}) capture(algo,eq,(xp,yp),(xe,ye),θ,t,vp,ve)
\State r e t u r n ( t , ( x p , y p ) ) return(t,(x_{p},y_{p})) return(t,(xp,yp))
\Else
\If{$Stack.top(t_{d}) = t $}
\State c o m p a r e ( e q , ( x p , y p ) , ( x e , y e ) , θ , t , v p , v e , compare(e_{q}, (x_{p},y_{p}), (x_{e},y_{e}), \theta,t, v_{p}, v_{e}, compare(eq,(xp,yp),(xe,ye),θ,t,vp,ve, \State $ ang_{d}, vel_{d})$
\State\textit{Set algo}
\State m o v e ( a l g o , e q , ( x p , y p ) , ( x e , y e ) , θ , t , v p , v e , move(algo, e_{q}, (x_{p},y_{p}), (x_{e},y_{e}), \theta, t, v_{p}, v_{e}, move(algo,eq,(xp,yp),(xe,ye),θ,t,vp,ve, \State $ ang_{d}, vel_{d})$
\State S t a c k . p o p ( ) Stack.pop() Stack.pop()
\State\textit{Update δ p \delta_{p} δp}
\Else
\State m o v e ( a l g o , e q , ( x p , y p ) , ( x e , y e ) , θ , t , v p , v e , 0 , 0 ) move(algo, e_{q}, (x_{p},y_{p}), (x_{e},y_{e}), \theta, t, v_{p}, v_{e}, 0, 0) move(algo,eq,(xp,yp),(xe,ye),θ,t,vp,ve,0,0)
\EndIf
\EndIf
\State t + + t++ t++
\EndWhile
\State \Return ( x p , y p ) , t (x_{p},y_{p}), t (xp,yp),t
\end{algorithmic}
\end{algorithm}

\subsection*{Complexity}
The complexity of both hybrid and basic algorithm, depends upon the iterations stored in the stack. If the input stack is empty, i.e. the speed and angle of evader is going to stay same through out the chase then capture point and total time can be calculated by using previous derived equations in a single step.\
On the other hand, when there are some entries in stack, then the algorithm is going to run one time quantum at a time until the stack is empty.

\begin{itemize}
\item Best Case- O(1), Stack is empty.
\item Worst case- O(MAX( t d t_{d} td)), where MAX( t d t_{d} td) is the time associated with the last iteration stored in stack.
\end{itemize}

Here as similar to the basic algorithm, we can see that first the equation type is determined in current situation. Once done, a compare function is called and value of a l g o algo algo variable is set. This value is going to change only if there is some iteration on the top of stack for t = t d t=t_{d} t=td. In such case compare function is called again, this time with the values of stack as well and accordingly a l g o algo algo is set again.\
After which move or capture functions are called, depending upon the situation.\

\section{Future work}
Both the algorithms have been implemented in C++ and are working perfectly.

  1. As suggested, I am trying to implement these algorithms in higher dimensions.\

  2. I am also working upon creating an android chase game which will use the hybrid algorithm.\

  3. Obstacles can also be introduced with following types-
    \subsubsection{•} Avoidable- These obstacles will only change the speeds of pursuers and evaders without changing their paths.\
    \subsubsection{•} Unavoidable- These obstacles will effect both speed and directions of agents.\
    \subsubsection{•} Application in mobile gaming as an intelligent chase algorithm.\

猜你喜欢

转载自blog.csdn.net/weixin_38396940/article/details/121594903