How is haversine distance used for weight optimization across trips in R

r
kaggle

#1

hello,

While trying to solve a route optimization problem for the Kaggle Competition:

santa’s stolen sleigh,I chanced upon the following code in the Kaggle forum.

base_weight <- 10
max_capacity <- 1000

positions <- lapply(c(1:nrow(gifts)), function(x) with(gifts[x,], c(Longitude, Latitude)))

single_trip <- function(current_gifts_ids){
  n <- length(current_gifts_ids)
  current_positions <- positions[current_gifts_ids]
  weights <- gifts[current_gifts_ids, Weight]
  csw <- c(rev(cumsum(rev(weights))), 0) + base_weight
  a <- append(current_positions, list(c(0, 90)), 0)
  b <- append(current_positions, list(c(0, 90)), n + 1)
  distances <- mapply(distHaversine, a, b)
  current_wrw <- sum(csw*distances)
  return(current_wrw)
}

However I am unable to understand it:
1.How are the base_weight and max_capacity initialized?
2.What is the positions capturing?
3.What is the single_trip function doing.

I understand that Haversine distance is being used here as the distance is spherical and originates at North Pole but beyond that my grey cells aren’t quite working. :smile:

Can someone please help me with this??


#2

HI

The two parameters base_weight and max_capacity are given, one is a parameter the other a constraint, check the problem definition on Kaggle it is well explained. Base weight is the wait of the sleigh.

Single_trip calculate the costs ( based on the criteria given by Kaggle) for a set of gifts. The cost id the sum of weigth per distance. After start the optimisation :slight_smile:

Alain