A time performance comparison of particle swarm optimization in mobile devices

This paper deals with the comparison of three implementations of Particle Swarm Optimization (PSO), which is a powerful algorithm utilized for optimization purposes. Xamarin, a cross-platform development software, was used to build a single C# application capable of being executed on three different mobile operating systems (OS) devices, namely Android, iOS, and Windows Mobile 10, with native level performance. Seven thousand tests comprising PSO evaluations of seven benchmark functions were carried out per mobile OS. A statistical evaluation of time performance of the test set running on three similar devices –each running a different mobile OS– is presented and discussed. Our findings show that PSO running on Windows Mobile 10 and iOS devices have a better performance in computation time than in Android.


Introduction
The aim of this paper is to compare the performance of three implementations of a single C# mobile application which examines the Particle Swarm Optimization (PSO) algorithm running on three mobile devices, each with a different mobile operating system installed, specifically Android, iOS, and Windows Mobile 10. One thousand simulations of PSO evaluating seven benchmark functions were carried out per mobile OS, thus 21, 000 tests were performed in total. Xamarin platform made it possible to develop a single application in C# and deploy it to different mobile OS devices.
Smartphones are multitasking mobile devices in which installed applications should have an efficient use of resources, including CPU, memory, and sensors, in order to increase performance and maximize their battery life. Most of the time, if a mobile application is slow or consumes too many resources, e.g. mobile data, battery, or storage, it is either uninstalled from the mobile device or scored with a low review by the user in the mobile app store. Moreover, decision-making applications, such as travel destination recommenders and games, are may require intensive computing in order to get the best choice, or at least an optimal one. Even though most of the time a more powerful device, e.g., a server, deals with this task -giving the mobile device the assignment of only presenting the results to the user-, sometimes the mobile device requires to process information on its own, with no aid of external server. In other words, dealing with data and finding the best choice among different options are problems which mobile applications are not excluded to solve.
PSO is an optimization technique developed by Kennedy and Eberhart [1] inspired by the collective behaviour of animal groups, such as swarms of insects, in order to build a swarm of particles, i.e., a set of candidate solutions which flow through the parameter space generating trajectories driven by the best individuals. The initial population (swarm) consists of random solutions (particles) for the problem and is considered as a population of homogeneous agents which interact locally with other individuals without any central control. As a result, collective behaviour is generated, thus evolution relies on cooperation and competition among individuals through the different epochs (generations). Each particle defines trajectories in the parameter space according to a motion function which is affected by velocity, inertia, cognitive coefficient and social coefficient. The objective is to find the global best solutions by stochastic weighting of the aforementioned elements. The process is iterative until a stopping criterion is met.
Xamarin Platform is a mobile application development tool used to build native and cross-platform applications which can be deployed to Android, iOS, and Windows Mobile devices with native-level performance, native user interface, and a full access to the APIs of each platform. These applications are written once in C# language, sharing the same code across multiple mobile operating systems. Not only the business logic can be shared when building a mobile application with Xamarin, but also the user interface can be distributed by writing it either in C# or in eXtensible Application Markup Language (XAML). When deployed and tested into a specific platform, the application presents a native user interface, e.g., a Xamarin.Forms.Button is depicted as a UIButton on iOS, as an Android.Widget.Button on Android, and as a System.Windows.Controls.Button on Windows Mobile devices. This paper is organized as follows. In the first section, a theoretical background on smartphones, particle swarm optimization, and Xamarin platform is presented. Afterwards, the methods and methodology that was used for this comparison are described. Then, evaluation results, statistical comparison and discussion are presented together. Finally, conclusions are shown at the end of the paper.

Background information
Smartphones are an important lifestyle device. There are almost 3.5 billion of smartphone subscriptions worldwide [2], and the trend is expected to double in size in the next lustrum. People use their smartphones on a daily basis in order to make their lives easier anytime and anywhere, for example, online purchases can be done while commuting thanks to a mobile application, thus it is not necessary to wait until a destination is reached and then use a PC. Another example of the advantages given by a smartphone is that it allows people to be communicated all the time.
Despite of the fact that smartphones are limited devices, they offer a PC user-experience, that is, they provide capabilities such as multitasking, video streaming, audio streaming, and web browsing, among others [3]. Therefore, they can be used intensively through the day while requiring a substantial usage of resources in order to work. When there are many applications working in the background, available memory can be significantly reduced. As a consequence, the smartphone's usability isn't user-friendly. In order to overcome this problem, the dispatcher, which is a privileged component of the operating system, terminates low-priority applications and frees resources until it determines that the available memory is enough to continue working. Moreover, battery life can be drained faster if there are too many programs running concurrently or if an application does not perform optimally. If a mobile app is killed by the dispatcher, it is not guaranteed that it would be properly closed as it didn't complete its lifecycle, so non-stored information will be lost and unrecoverable.
Artificial Intelligence (AI) algorithms, methods and techniques can be applied to build smart applications which delivers valid results to a user's request [4]. For instance, a geospatial analysis can be obtained by combining the use of geometric design with sensors and components from a smartphone, such as GPS, accelerometer, and camera [5]. Moreover, a deep learning neural network can perform effective human activity recognition with the aid of smartphone sensors [6]. Furthermore, Genetic Programming (GP) has been used to create a customized smartphone user-experience [7].
As can be seen, AI methods provide solutions for today's mobile world challenges.

Particle Swarm Optimization
Particle Swarm Optimization (PSO) is an example of stochastic optimization inspired by the social behaviour of animal groups [8]. Initially developed by Kennedy and Eberhart in 1995 [1], this technique has proven to be effective for neural networks weight calculation [9], business optimization [10], and parameter estimations [11]. Both behaviour and efficiency of the algorithm rely on the parameters shown in Table 1 [1]. Metaoptimization of the parameters has been used to tune them and find the best values which benefit PSO's performance in particular scenarios [12][13][14][15]. The algorithm works as follows: First, a population of random N candidate solutions {x1, x2,…, xN} is generated. Each individual is an N-dimensional vector (N > 1) with values within the problem bounds. Moreover, each particle contains a velocity vector vi, which is also randomly initialized. By performing fitness evaluation, the best position at the moment, bi, is obtained for each individual along with the best global position hi. The iterative process starts by generating two random values, r1, r2, which are used to update each particle's velocity and position according to equations (1) and (2), respectively: Fitness evaluation is performed again in order to determine both the best position for each particle and the best global particle. The iterative process is repeated until a stopping criterion, such as a predetermined number of generations, is met. There are several variants of the PSO algorithm [16]. For instance, vi in (1) is not affected by Z in the original version of the algorithm. Another variation consider the initialization of the particles as the most important element in order to improve the performance of the algorithm [17]. Opposition-based learning, a term that describes an individual's exact contrary, has also been considered as an enhanced variant of PSO which accelerates convergence [18][19][20] by replacing individuals which are far to the optimal solution by their opposite, which is closer in distance to the solution.

Xamarin Platform
Xamarin is a novel cross-platform mobile application development tool which can be used to build native Android, iOS and Windows applications that rely on a shared C# codebase. One of the main advantages of Xamarin is that allows developers to write an application once and deploy it to different mobile OS platforms without having to rewrite it in an completely different programming language, operating system or application programming interface (API) [21]. Even though all the platforms share similarities, such as graphical user interface (GUI) presentation, device sensors, and gestures interaction, each of them incorporates many differences, including navigation, user-experience, and fragmentation [22]. Xamarin's development of cross-platform solutions is possible mainly because of the  [24]-plus another project which contains the common code that will be compiled and used at runtime by each specific platform together with the code contained in the project platform. Both the user-interface (UI) and the business logic (BL) can be developed in C# language, while eXtensible Application Markup Language (XAML) can also be used for the UI. On the one hand, the UI refers to the views or controls that will be shown on the device screen. On the other hand, the BL includes all the functionality of the application. It is also worth mentioning that platform-specific code can be added to the project to address key platform differences, such as screen sizes, navigation issues and push notifications, and device differences, for instance, sensors functionality, social networks interaction, and geo-location support.

Methods and methodology
The objective of this experiment is to evaluate the performance of an implementation of the Particle Swarm Optimization algorithm running on 3 smartphones with different mobile OS each (Android, iOS, and Windows Mobile) which evaluates 7 well-known benchmark functions for optimization (Ackley [25], Goldstein-Price [26], Rastrigin [27], Rosenbrock [28], Rotated Hyper-Ellipsoid [29], Sphere [30] and Sum Squares [31]). Table  2 provides a brief overview of the tested benchmark functions, while Table 3 outlines the relevant specifications of the 3 mobile devices [32] used for the analysis. Except for the Goldstein-Price function, which by definition operates only in a 2-dimensional space, all benchmarks were evaluated in a 10-dimensionall space A C# version of the PSO algorithm was programmed and included in a mobile application developed with Xamarin platform using the Visual Studio Community 2015 IDE. Figure 1 shows the structure of the solution. Four projects were included in the solution. The first one, PSO, contains all the shared code. The other three, PSO.Droid, PSO.iOS, and PSOUWP represent the specific projects that were deployed to the particular mobile OS, namely Android, iOS, and Windows 10, respectively. It is worth mentioning that no code was added to the three projects due to Xamarin's code-sharing leveraging technique.
In all cases, Z = 0.729, N = 40, c1 = 1.49445, c2 = 1.49445 values were used. For the benchmark functions, the search domain was set for the range indicated in Table 2. Finally, during the experiment, each mobile had neither processes working in the background nor background services and sensors active, except for the PSO mobile application developed in Xamarin and the Wi-Fi signal because the computation times were sent to an Azure SQL cloud database for further analysis.
One thousand simulations of the Particle Swarm Optimization full algorithm per benchmark function evaluation and per mobile OS were carried out, i.e., each time a new random initial population was generated and evolved in order to solve a benchmark function. Figure 2 depicts the process of a single run of the app in each device, while Figures 3 and 4 show the application being executed on Windows Mobile 10 and Android devices, respectively.

Results and discussion
The findings of the analysis are summarised in Table 4. A comparison of the average running time of 1000 simulations of PSO evaluating one benchmark function at a time on a mobile device is presented. The best (fastest) results in each case are marked in bold, while the worst ones are shown in italics. On the one hand, it is clearly seen that the Android device was far outperformed by both iOS and Windows Mobile 10 devices approximately two times, except for Rosenbrock and Rotated functions, in which average times are closer. On the other hand, the iOS and Windows Mobile 10 devices had similar performances in terms of time, with the latter being the fastest in 4 out of the 7 benchmark evaluations.
As iOS and Windows Mobile 10 computation times look similar, a statistical analysis can be performed to determine if there are significant differences between them. Firstly, an extended Shapiro-Wilk test [33] was conducted in order to assess the normal distribution of both samples. Table 5 and Table 6 show the findings of this test at the significance level of 0.05. The null hypothesis, H0, in each case is set as "the computation times of a given benchmark-function evaluation on a mobile device are normally distributed".  W* stands for the observed test statistic value. As can be seen, the statistical test clearly indicates that all benchmark-function evaluations on both mobile OS follow a normal distribution because our proposed null hypothesis is accepted, as p(W*) > 0.05 in all cases.
Secondly, a Bartlett's test for variances homogeneity [34] can be performed. In this case, our null hypothesis, H0, is set as "The variances of two samples of given benchmark-function evaluations running on different mobile OS devices are homogeneous".      In other words, only the variances of the Rotated-function comparison between iOS and Windows Mobile 10 are homogeneous.  [35] can be used to detect differences between our samples. Table 8 outlines the results of the Friedman test at the 0.05 significance level with one degree of freedom (k -1 = 1, where k is the number of samples, in this case, 2). This test also relies on the chi-square critical value, i.e., F0.95, 1 = 3.8414. Our null hypothesis, H0, for each case is set as "there is no significant difference between Windows Mobile 10 and iOS evaluations of a given benchmark function". As shown in the previous table, the null hypothesis is certainly accepted in all evaluations, meaning that there is no significant difference between the computation times of the benchmark-function evaluations in both mobile OS.

Conclusion
Smartphone applications require a careful management of resources in order to provide a proper user-experience. Despite of the fact that huge workloads are often assigned to servers, mobile devices are also capable of accepting time-consuming tasks which most of the time run in the background as the response time of a mobile app should be fast. In this study, we implemented Particle Swarm Optimization algorithm in order to test and compare their performance when being executed on three devices with different mobile OS, namely Android, iOS and Windows Mobile 10. Our findings show that Android got the worst performance, while a statistical analysis of iOS and Windows Mobile 10 computation times revealed that there was no significant difference between them. Future research will be focused on implementing PSO in Java and Swift, which are Android and iOS programming languages used for developing native apps respectively. Further, another statistical comparison of both the native and the C#-cross-platform current implementation in Xamarin that was shown in this paper can be done in terms of computation time and performance.