% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nsga.R
\name{nsga}
\alias{nsga}
\title{Non-Dominated Sorting in Genetic Algorithms}
\usage{
nsga(
  type = c("binary", "real-valued", "permutation"),
  fitness,
  ...,
  lower,
  upper,
  nBits,
  population = rmooControl(type)$population,
  selection = rmooControl(type)$selection,
  crossover = rmooControl(type)$crossover,
  mutation = rmooControl(type)$mutation,
  popSize = 50,
  nObj = NULL,
  dshare,
  pcrossover = 0.8,
  pmutation = 0.1,
  maxiter = 100,
  run = maxiter,
  maxFitness = Inf,
  names = NULL,
  suggestions = NULL,
  monitor = if (interactive()) rmooMonitor else FALSE,
  summary = FALSE,
  seed = NULL
)
}
\arguments{
\item{type}{the type of genetic algorithm to be run depending on the nature
of decision variables. Possible values are:
\describe{
\item{\code{"binary"}}{for binary representations of decision variables.}
\item{\code{"real-valued"}}{for optimization problems where the decision
variables are floating-point representations of real numbers.}
\item{\code{"permutation"}}{for problems that involves reordering of a list
of objects.}
}}

\item{fitness}{the fitness function, any allowable R function which takes as
input an individual string representing a potential solution, and returns a
numerical value describing its “fitness”.}

\item{...}{additional arguments to be passed to the fitness function. This
allows to write fitness functions that keep some variables fixed during the
search.}

\item{lower}{a vector of length equal to the decision variables providing the
lower bounds of the search space in case of real-valued or permutation
encoded optimizations.}

\item{upper}{a vector of length equal to the decision variables providing the
upper bounds of the search space in case of real-valued or permutation
encoded optimizations.}

\item{nBits}{a value specifying the number of bits to be used in binary
encoded optimizations.}

\item{population}{an R function for randomly generating an initial population.
See \code{\link[=rmoo_Population]{rmoo_Population()}} for available functions.}

\item{selection}{an R function performing selection, i.e. a function which
generates a new population of individuals from the current population
probabilistically according to individual fitness.}

\item{crossover}{an R function performing crossover, i.e. a function which
forms offsprings by combining part of the genetic information from
their parents. See \code{\link[=rmoo_Crossover]{rmoo_Crossover()}} for available functions.}

\item{mutation}{an R function performing mutation, i.e. a function which
randomly alters the values of some genes in a parent chromosome.
See \code{\link[=rmoo_Mutation]{rmoo_Mutation()}} for available functions.}

\item{popSize}{the population size.}

\item{nObj}{number of objective in the fitness function.}

\item{dshare}{the maximun phenotypic distance allowed between any two
individuals to become members of a niche.}

\item{pcrossover}{the probability of crossover between pairs of chromosomes.
Typically this is a large value and by default is set to 0.8.}

\item{pmutation}{the probability of mutation in a parent chromosome. Usually
mutation occurs with a small probability, and by default is set to 0.1.}

\item{maxiter}{the maximum number of iterations to run before the NSGA search
is halted.}

\item{run}{the number of consecutive generations without any improvement in
the best fitness value before the NSGA is stopped.}

\item{maxFitness}{the upper bound on the fitness function after that the NSGA
search is interrupted.}

\item{names}{a vector of character strings providing the names of decision
variables.}

\item{suggestions}{a matrix of solutions strings to be included in the
initial population. If provided the number of columns must match the number
of decision variables.}

\item{monitor}{a logical or an R function which takes as input the current
state of the nsga-class object and show the evolution of the search. By
default, for interactive sessions the function rmooMonitor prints the average
and best fitness values at each iteration. If set to plot these information
are plotted on a graphical device. Other functions can be written by the user
and supplied as argument. In non interactive sessions, by default
monitor = FALSE so any output is suppressed.}

\item{summary}{If there will be a summary generation after generation.}

\item{seed}{an integer value containing the random number generator state.
This argument can be used to replicate the results of a NSGA search. Note
that if parallel computing is required, the doRNG package must be installed.}
}
\value{
Returns an object of class nsga1-class. See \linkS4class{nsga1} for a
description of available slots information.
}
\description{
Minimization of a fitness function using Non-Dominated Genetic algorithms
(NSGA). Local search using general-purpose optimisation algorithms can be
applied stochastically to exploit interesting regions.
}
\details{
The Non-dominated genetic algorithms is a meta-heuristic proposed by
N. Srinivas and K. Deb in 1994. The purpose of the algorithms is to find an
efficient way to optimize multi-objectives functions (two or more).
}
\examples{
#Example
#Two Objectives - Real Valued
zdt1 <- function (x) {
 if (is.null(dim(x))) {
   x <- matrix(x, nrow = 1)
 }
 n <- ncol(x)
 g <- 1 + rowSums(x[, 2:n, drop = FALSE]) * 9/(n - 1)
 return(cbind(x[, 1], g * (1 - sqrt(x[, 1]/g))))
}

#Not run:
\dontrun{
result <- nsga(type = "real-valued",
               fitness = zdt1,
               lower = c(0,0),
               upper = c(1,1),
               popSize = 100,
               nObj = 2,
               dshare = 1,
               monitor = FALSE,
               maxiter = 500)
}

}
\references{
N. Srinivas and K. Deb, "Multiobjective Optimization Using
Nondominated Sorting in Genetic Algorithms, in Evolutionary Computation,
vol. 2, no. 3, pp. 221-248, Sept. 1994, doi: 10.1162/evco.1994.2.3.221.

Scrucca, L. (2017) On some extensions to 'GA' package: hybrid optimisation,
parallelisation and islands evolution. The R Journal, 9/1, 187-206.
doi: 10.32614/RJ-2017-008
}
\seealso{
\code{\link[=nsga2]{nsga2()}}, \code{\link[=nsga3]{nsga3()}}
}
\author{
Francisco Benitez
\email{benitezfj94@gmail.com}
}
