Introduction

RcppGO is a package designed for optimization problems. The code was originally written in Cpp. With the use of the Rcpp package by [@Eddelbuettel:2011c] it is now translated into R. Newton's laws of gravity and motion are the basis of the algorithm as described in [@Kaveh:2010b]. RcppGO is an allusion to the integration of Rcpp, the concept of Gravity at the core of the algorithm and Optimization as the purpose of the package.

Installation

RcppGO is hosted at https://github.com/peterkehlerjr/RcppGO. The installation via github requires the package devtools [@Wickham:2014]. Assuming devtools is not present in your library, the installation is done via:

install.packages("devtools")
library(devtools)
install_github('peterkehlerjr/RcppGO')

Examples

After installing the required packages, they have to be loaded into R.

library(RcppGO)

Now we can start to play around with the package. Before going into detail, I will present two examples how to use its functionality.

Example 1

Let's have a look at our first example. Say, we have a cost function defined by the following objective function: $$f(x) = (x-2)^2 + 3, x \in \mathbf{N}_{+} , x \geqq 1 $$ We assume the constraints that $x$ is greater equal 1 and discrete positive. The objective is to find the minimum costs given a quantity of our product.

Defining the objective function in R is straight forward. We will call it Fun01.

Fun01 <- function(X)
  {
   (X-3)^2 + 4
  }

Let's look at a plot of Fun01:

plot(Fun01, xlim=c(1,6), ylim = c(0,15),ylab = "cost function")
points(x = 3, y = 4, lwd=2, col="red")

Now let us

Example01 <- RcppGO(ObjectiveFunction = Fun01, 
                    Args = 1, 
                    Lower = -10, 
                    Upper = 10
                    )
str(Example01)
Example01$GMemory
plot(x=Example01, xlim = c(1,6), bestsolution = TRUE)

Example 2

to bit more complicated objective function. $$f(x,y)=\frac{1}{4} x^4 - \frac{1}{2} x^2 + \frac{1}{10}x + \frac{1}{2}y^2$$

Let's look for the minimum of the function.

# defining a benchmark function
# min at -0.352386, X in [-10,10]^2
AluffiPentiny <- function(X)
  {
    1/4*X[,1]^4 - 1/2*X[,1]^2 + 1/10*X[,1] + 1/2*X[,2]^2
  }
# call and save the optimization process in 'demo01''
Example02 <- RcppGO(ObjectiveFunction=AluffiPentiny,
                 Args=2,
                 Lower = -10,
                 Upper = 10,
                 User=FALSE,
                 Scale=0.1)

# show the best solutions found
Example02$GMemory

The two main functions

The RcppGO function

Parameters

The plot.RcppGO method

Parameters

Session Info

sessionInfo()

References



peterkehlerjr/RcppGO documentation built on Dec. 29, 2021, 11:20 p.m.