I have created an optimization model in Excel using the standard Solver and now would like to make a similar model in R as this will allow me to make larger models like this. Unfortunately, I have a bit of a hard time finding good examples that I can model my concept on. Therefore, I would like to ask you whether anybody is able to give me some hints on how to make a similar model in R.
I have uploaded my Excel sheet to http://dl.dropbox.com/u/9641130/R/Positioning%20Optimization%20R.xlsx
The basic idea is that cell B3 is maximized by changing max 8 cells in range E10:L19 to one. The B3 cell includes a sumproduct() of the range E10:L19 and a number of similar ranges.
I am looking forward to see some hints on how to build a similar model in R.
Thanks! Jochem
========
Update following Chase's suggestion
I would like to clarify my question a bit with some repoducable R code. This is roughly the same model as you will find in the Excel code above.
The initial set of matrices:
A <- as.matrix(structure(list(X0 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), X0.1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), X0.2 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), X0.3 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), X0.4 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), X0.5 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), X0.6 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), X0.7 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("X0", "X0.1", "X0.2", "X0.3", "X0.4", "X0.5", "X0.6", "X0.7"), class = "data.frame", row.names = c(NA, -9L)))
B <- as.matrix(structure(list(X1 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), X1.1 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), X1.2 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), X1.3 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), X.100000 = c(-100000L, -100000L, -100000L, -100000L, 1L, 1L, 1L, 1L, 1L), X.100000.1 = c(-100000L, -100000L, -100000L, -100000L, 1L, 1L, 1L, 1L, 1L), X.100000.2 = c(-100000L, -100000L, -100000L, -100000L, 1L, 1L, 1L, 1L, 1L), X.100000.3 = c(-100000L, -100000L, -100000L, -100000L, 1L, 1L, 1L, 1L, 1L)), .Names = c("X1", "X1.1", "X1.2", "X1.3", "X.100000", "X.100000.1", "X.100000.2", "X.100000.3"), class = "data.frame", row.names = c(NA, -9L)))
C <- as.matrix(structure(list(X1 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), X1.1 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), X1.2 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), X1.3 = c(1L, 1L, 1L, 1L, 1L, -100000L, 1L, 1L, 1L), X1.4 = c(1L, 1L, 1L, 1L, 1L, -100000L, 1L, 1L, 1L), X1.5 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), X1.6 = c(1L, 1L, 1L, 1L, 1L, -100000L, 1L, 1L, -100000L), X1.7 = c(1L, 1L, 1L, 1L, -100000L, -100000L, 1L, 1L, -100000L)), .Names = c("X1", "X1.1", "X1.2", "X1.3", "X1.4", "X1.5", "X1.6", "X1.7"), class = "data.frame", row.names = c(NA, -9L)))
D <- as.matrix(structure(list(X775 = c(385L, 1233L, 1067L, 5L, 730L, 1123L, 837L, 5L, 3087L), X704 = c(625L, 1338L, 804L, 110L, 659L, 1363L, 942L, -165L, 3350L), X704.1 = c(625L, 1338L, 804L, 110L, 659L, 1363L, 942L, -165L, 3350L), X944 = c(625L, 1263L, 898L, 35L, 899L, 1363L, 867L, -65L, 3110L), X775.1 = c(385L, 1233L, 1067L, 5L, 730L, 1123L, 837L, 5L, 3087L), X775.2 = c(385L, 1233L, 1067L, 5L, 730L, 1123L, 837L, 5L, 3087L), X944.1 = c(625L, 1263L, 898L, 35L, 899L, 1363L, 867L, -65L, 3110L), X944.2 = c(625L, 1263L, 898L, 35L, 899L, 1363L, 867L, -65L, 3110L)), .Names = c("X775", "X704", "X704.1", "X944", "X775.1", "X775.2", "X944.1", "X944.2"), class = "data.frame", row.names = c(NA, -9L)))
The result of the function sum(A*B*C*D) is currently 0. This is logical since in matrix A all cells have a value of 0. However, I would like to know with what formula I can maximize the value of the function sum(A*B*C*D).
sum(A*B*C*D)
[1] 0
I want to do this by changing the values in Matrix A from 0 to 1. Moreover, the following constrains should be taken in consideration. 1. Each row can only include one cell with the value 1. 2. Each column can only include one cell with the value 1; this means that we can place a maximum of eight times the value 1 in Matrix A.
Does anybody have a suggestion on how to accomplis this?