Package: lpfgopt
Leapfrog Optimizer PackageAuthor  : Mark ReddEmail   :redddogjr@gmail.comGitHub  :https://github.com/flythereddflaggWebsite :http://www.r3eda.com/AboutThis package is based theLeapfrogging Optimization Algorithmpublished byDr. R. Russell Rhinehart. The following publications explain the technique:Rhinehart, R. R., M. Su, and U. Manimegalai-Sridhar, “Leapfrogging and Synoptic Leapfrogging: a new optimization approach”, Computers & Chemical Engineering, Vol. 40, 11 May 2012, pp. 67-81.Manimegalai-Sridhar, U., A. Govindarajan, and R. R. Rhinehart, “Improved Initialization of Players in Leapfrogging Optimization”, Computers & Chemical Engineering, Vol. 60, 2014, 426-429.Rhinehart, R. R., “Convergence Criterion in Optimilsation of Stochastic Processes”, Computers & Chemical Engineering, Vol. 68, 4 Sept 2014, pp 1-6.InstallationYou can install via pip or using the setup.py script in the source code. Instructions are shown below.Minimum system Requirements for InstallationPython >= 3.6Recommended System Requirements for InstallationWindows or Linuxx86 processor with a 64-bit architectureAdditional Python Packages:scipynumpypytestVia pipThelpfgoptpackage may be installed withpipusing the following command:$pipinstalllpfgopt# You may need root privileges or the --user tagIf you wish to install locally withpipyou may do the following:Download and unzip the archive or clone it with git.Open the main directory wheresetup.pyis located and run the following command:$pipinstall.Via setup.pyDownload the master branch and unzip the archive or clone it with git.Open the main directory where "setup.py" is located and run the following command:$pythonsetup.pyinstall# You may need root priviliges or use the --user tagTest the InstallationThe software should be installed correctly. You may validate the installation by executing the following commands in a terminal:$python>>>importlpfgopt>>>lpfgopt.__version__'X.X.X'>>>lpfgopt.minimize(lambdax:x[0]**2+10,[[-10,10]])['x'][<approximately0.0>]>>>If the above commands produce the output congratulations! You have successfully installed the package!UsageUse thelpfgopt.minimizefunction to solve optimization problems of the form:$minimize$ $f(x)$
$s.t.:$$g(x) \le 0$$bound_{1,1} \le x[1] \le bound_{1,2}$$bound_{2,1} \le x[2] \le bound_{2,2}$$...$$bound_{n,1} \le x[n] \le bound_{n,2}$where $n$ is the number of decision variables and $bound$ is an array-like with shape $(n, 2)$. $bound$ may be a list of lists or anumpyndarray.Example UsageThe following is a simple optimization where the minimum value of the following equation is found:$f(x) = x^2+y^2$Subject to:$g(x) = -x^2 - y + 10 \le 0$org(x) = -x^2 - y + 10 <= 0$$x, y \in [-5, 5]$$# test_lpfgopt.pyfromlpfgoptimportminimizeimportmatplotlib.pyplotasplt# set up the objective funciton,# constraint fuction and boundsf=lambdax:sum([i**2foriinx])g=lambdax:-x[0]**2+10-x[1]bounds=[[-5,5]foriinrange(2)]# run the optimizationsol=minimize(f,bounds,fconstraint=g)['x']print(f"Solution is:{sol}")# plot the results on a contour plotgg=lambdax:-x**2+10# for plotting purposesplt.figure(figsize=(8,8))x,y=np.linspace(-5,5,1000),np.linspace(-5,5,1000)X,Y=np.meshgrid(x,y)Z=f([X,Y])plt.contourf(X,Y,Z)plt.plot(x,gg(x),"r",label="constraint")plt.plot(*sol,'x',markersize=14,markeredgewidth=4,color="lime",label="optimum")plt.ylim(-5,5)plt.xlim(-5,5)plt.legend()plt.show()This code will produce the following output:Solutionis:[-3.0958051486911997,0.4159905027317925]As well as a plot that should look similar to the following image: