Description Usage Arguments Details Value Note Author(s) References See Also Examples
The function solve the mixed integer linear programming formulation of the variable selection problem.
1 2 3 4 |
d |
A 3-dimensional distance matrix, in which d[i,j,k] is the distance between unit i and prototype j, according to variable k. |
q |
The number of variables to selct. |
binary |
Set this value to TRUE if you wish to solve the problem with integer variables, or set it to FALSE if you just want to solve the continuous relaxation |
write |
Set this value to TRUE if you want that the optimization problem is exported in a file called qdistsel.lp |
The function solves the linear problem through the lpSolve solver available through the package lpSolveAPI. The linear programming formulation is the implementation of model F3 described in the paper below (without the median variables).
status |
The result of the optimization as output of the function solve() of library lpSolveAPI |
obj |
The value of the objective function |
x |
The value of the problem variables corresponding to the variable selection: x[j] = 1 means that variable j has been selected, 0 otherwise. If the continuous relaxation has been solved, the vector can contain fractional variables (most likely meaningless). |
The computational time to solve an integer programming problem can easily become exponential, therefore be carefull when set variable "binary" to TRUE, as you could wait days even to get the solution of a small scale problem. Even though the continuos version can contain fractional variables, comparing the objective functions of subroutines qVarSelH and qVarSelLP is a certificate of the solution quality.
Stefano Benati
S. Benati, S. Garcia Quiles, "A p-median model with distance selection", Working Paper, Universidad Carlos III de Madrid, 2012
lpSolveAPI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ## Generate random cluster
a <- rbind(cbind(rnorm(5, 0, 1), rnorm(5, 0, 3), rnorm(5, 0, 5)),
cbind(rnorm(5, 5, 1), rnorm(5, 5, 3), rnorm(5, 5, 5) ))
## calculate data prototypes using k-means
sl2 <- kmeans(a, 2, iter.max = 100, nstart = 2)
p = sl2$centers
## calculate distances between observations and prototypes
## Remark: d is a 3-dimensions matrix
d = PrtDist(a, p)
## Select 2 most representative variables, use heuristic
lsH <- qVarSelH(d, 2, maxit = 200)
## Select 2 variables, use linear relaxation
require(lpSolveAPI)
lsC <- qVarSelLP(d, 2)
## check optimality
if (abs(lsH$obj - lsC$obj) < 0.001)
message = "Heuristic Solution is Optimal"
|
Loading required package: lpSolveAPI
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.