R/RcppExports.R

Defines functions mtsp_ga mdmtspv_ga2 mdmtspv_ga

Documented in mdmtspv_ga mdmtspv_ga2 mtsp_ga

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Runs the MTSP solver
#'
#' @param xy A \code{n} by \code{2} matrix of coordinate positions. Each row has the \code{x} and \code{y} position of the n sites to be visited.
#' @param dmat A \code{n} by \code{n} matrix with the distances between the positions \code{xy}. 
#' @param depots A \code{nSales} by \code{2} matrix of coordinate positions for the starting positions / depots. This should have the same number of rows as there are salespersons.
#' @param nSalesmen An integer giving the number of salespersons (must be >= 2).
#' @param CostType Possible values are the integers 1 or 2; 1 minimises the total distance travelled and 2 minimises the maximum distance travelled across the salepersons.
#' @param popSize The population size / search space of the GA (should be divisible by 8 but this is corrected within program).
#' @param numIter is the number of desired iterations for the algorithm to run after a new best solution is found. 
#' @param Epsilon A double giving a multiplier on blancing the costs beteen total distance and minmax (only used for \code{costType} 2).
#' @param return_all Logical on whether ro return full ouput. Defaults to \code{FALSE}.
#' @return Returns the solution to the MTSP. Depending on \code{return_all} may return the inputs and \code{D0}: the distance from the depots to each site, \code{best_tour}: 
#' a matrix where each row gives the sites visited by each salesperson. The first and last values give the depot,  \code{minDist}: is the best cost found by the algorithm, 
#' and  \code{generation}: is the number of generations required by the algorithm to find the solution.
#' @examples
#' set.seed(1)
#' n = 25
#' nSalesmen = 5
#' xy = matrix(rnorm(n*2), ncol=2)
#' depots = matrix(rnorm(nSalesmen*2), ncol=2)
#' dmat = as.matrix(dist(xy))
#' mdmtspv_ga(xy, dmat, depots, nSalesmen, 1, 80, 10)
#' @export
#' @useDynLib mtsp
#' @importFrom Rcpp sourceCpp
mdmtspv_ga <- function(xy, dmat, depots, nSalesmen, CostType, popSize, numIter, Epsilon = 1e-10, return_all = FALSE) {
    .Call('_mtsp_mdmtspv_ga', PACKAGE = 'mtsp', xy, dmat, depots, nSalesmen, CostType, popSize, numIter, Epsilon, return_all)
}

#' Runs the MTSP solver
#'
#' @param xy A \code{n} by \code{2} matrix of coordinate positions. Each row has the \code{x} and \code{y} position of the n sites to be visited.
#' @param dmat A \code{n} by \code{n} matrix with the distances between the positions \code{xy}. 
#' @param nSalesmen An integer giving the number of salespersons (must be >= 2).
#' @param CostType Possible values are the integers 1 or 2; 1 minimises the total distance travelled and 2 minimises the maximum distance travelled across the salepersons.
#' @param popSize The population size / search space of the GA (should be divisible by 8 but this is corrected within program).
#' @param numIter is the number of desired iterations for the algorithm to run after a new best solution is found. 
#' @param Epsilon A double giving a multiplier on blancing the costs beteen total distance and minmax (only used for \code{costType} 2).
#' @param return_all Logical on whether ro return full ouput. Defaults to \code{FALSE}.
#' @return Returns the solution to the MTSP. Depending on \code{return_all} may return the inputs and  \code{best_tour}: 
#' a matrix where each row gives the sites visited by each salesperson,  \code{minDist}: is the best cost found by the algorithm, 
#' and  \code{generation}: is the number of generations required by the algorithm to find the solution.
#' @examples
#' set.seed(1)
#' n = 25
#' nSalesmen = 5
#' xy = matrix(rnorm(n*2), ncol=2)
#' dmat = as.matrix(dist(xy))
#' mdmtspv_ga2(xy, dmat, nSalesmen, 1, 80, 10)
#' @export
#' @useDynLib mtsp
#' @importFrom Rcpp sourceCpp
mdmtspv_ga2 <- function(xy, dmat, nSalesmen, CostType, popSize, numIter, Epsilon = 1e-10, return_all = FALSE) {
    .Call('_mtsp_mdmtspv_ga2', PACKAGE = 'mtsp', xy, dmat, nSalesmen, CostType, popSize, numIter, Epsilon, return_all)
}

#' Runs the MTSP solver
#'
#' @param xy A \code{n} by \code{2} matrix of coordinate positions. Each row has the \code{x} and \code{y} position of the n sites to be visited.
#' @param dmat A \code{n} by \code{n} matrix with the distances between the positions \code{xy}. 
#' @param nSalesmen An integer giving the number of salespersons (must be >= 2).
#' @param minTour An integer giving the minimum tour length for any of the salesmen.
#' @param CostType Possible values are the integers 1 or 2; 1 minimises the total distance travelled and 2 minimises the maximum distance travelled across the salepersons.
#' @param popSize The population size / search space of the GA (should be divisible by 8 but this is corrected within program).
#' @param numIter is the desired number of iterations for the algorithm to run.
#' @param Epsilon A double giving a multiplier on blancing the costs beteen total distance and minmax (only used for \code{costType} 2).
#' @param return_all Logical on whether ro return full ouput. Defaults to \code{FALSE}.
#' @return Returns the solution to the MTSP. Depending on \code{return_all} may return the inputs and \code{best_tour}: returns
#'  a list where each element gives the sites visited by each salesperson, \code{minDist}: is the best cost found by the algorithm,
#'  \code{minDistTotal} gives tht total distance travelled for all salespersons, and \code{minMaxTotal} gives the maximum distance travelled by any one salesperson.
#' @examples
#' set.seed(1)
#' n = 25
#' nSalesmen = 5
#' xy = matrix(rnorm(n*2), ncol=2)
#' dmat = as.matrix(dist(xy))
#' minTour = 3
#' numIter = 10
#' popSize = 8
#' CostType = 2
#' res = mtsp_ga(xy, dmat, nSalesmen, minTour, CostType, popSize, numIter, return_all = TRUE)
#' @export
#' @useDynLib mtsp
#' @importFrom Rcpp sourceCpp
mtsp_ga <- function(xy, dmat, nSalesmen, minTour, CostType, popSize, numIter, Epsilon = 1e-10, return_all = FALSE) {
    .Call('_mtsp_mtsp_ga', PACKAGE = 'mtsp', xy, dmat, nSalesmen, minTour, CostType, popSize, numIter, Epsilon, return_all)
}
daffp/mtsp documentation built on Sept. 23, 2020, 2:39 p.m.