Price bundling using Genetic Algorithm in R

Data set: Values that customers assigned for different products
Flow chart of GA
Result of experiment 1
Result of experiment 2
#Load Customer data
Customer <- read.csv(file.csv, sep = ",", header = T)
#Price <- c(35.0,75.0,64.0,75.0,82.0,92.0,100.0)
attach(Customer)
library(matrixStats)
Func <- function(x)
{
MarketSur <- cbind(Internet-x[1],TV-x[2],Cell.Phone-x[3],
Internet+TV-x[4], Internet+Cell.Phone-x[5],
TV+Cell.Phone-x[6], Internet+TV+Cell.Phone-x[7])
MaxSur <- rowMaxs(MarketSur)
Prod <- function(MarketSur)
{
s <- dim(MarketSur)
Mt <- vector("numeric", s[1])
for(i in 1:s[1]){
if(max(MarketSur[i,])<0)
{
Mt[i] <- 0
}
else
{
Mt[i] <- which.max(MarketSur[i,])
}

}
return(Mt)
}
Bt <- Prod(MarketSur)
Rev <- vector("numeric",77)
#Rev <- x[Bt]
for(i in 1:77){
if(Bt[i] == 0)
{
Rev[i] = 0
}
else{
Rev[i] = x[Bt[i]]
}
}
Pen <-vector("numeric",12)
Pen[1] <- x[1]-x[4]
Pen[2] <- x[1]-x[5]
Pen[3] <- x[1]-x[7]
Pen[4] <- x[2]-x[4]
Pen[5] <- x[2]-x[6]
Pen[6] <- x[2]-x[7]
Pen[7] <- x[3]-x[5]
Pen[8] <- x[3]-x[6]
Pen[9] <- x[3]-x[7]
Pen[10] <- x[4]-x[7]
Pen[11] <- x[5]-x[7]
Pen[12] <- x[6]-x[7]
for(i in 1:12)
{
if(Pen[i]>0)
{
Pen[i] <- Pen[i]
}
else
{
Pen[i] <- 0
}
}
TotalRev <- sum(Rev) - 500*sum(Pen,na.rm=F)
return(TotalRev)
}

#GAmodel <- rbga.bin(size = 7, popSize = 200, iters = 100, mutationChance = 0.01,
#elitism = T, evalFunc = EvalFunc)
## calculate the optimum solution using Genetic Algorithm
#numvar <- 7
#resultGA <- GA(EvalFunc, optimType="MAX", numVar, numPopulation=20,
#maxIter=100, rangeVar, Pm, Pc)
L <- c(30,30,30,30,30,30,30)
U <- c(100,100,100,100,100,100,100)
suggestedValue <-c(50,35,65,71,71,71,85)
GA <- ga(type = "real-valued", fitness = Func,
lower = L, upper = U,
popSize = 2000, maxiter = 500)
summary(GA)
plot(GA)

--

--

--

MBA, IIM Shillong

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Recipe Of Deep learning

Still Image 0 Video 1

How to Deploy Machine Learning Models to the Cloud Quickly and Easily

Audio classification of Dogs and Cats using CNN and RNN

Combining Bayesian Neural Networks and Ensemble techniques

PROBABILISTIC ALGORITHMS

Scripting for Linux: Image Finder

From Research to Practice

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Himanshu Bhardwaj

Himanshu Bhardwaj

MBA, IIM Shillong

More from Medium

‘Visualizing Emissions and Energy Mix Data’ Final Report

K-Means Clustering Key Points

Examining the relevance of various predictors for Jewelry spent

YouTube Analytics in R: Bringing Insights to Your Fingertips