###################################################################
## an array and its counting vector
## arrays (starting the coding with 1)
## and their counting vectors can be used interchangeably
myarr <- cbind(c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2),
c(1,1,1,1,2,2,2,2,1,1,1,1,2,2,2,2),
c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4),
c(1,5,3,7,2,6,4,8,8,4,6,2,7,3,5,1))
## we want to see it w.r.t. a 2,2,4,8 level full factorial
## determine the counting vector representation of this array
## nlevels is needed,
## because the third column of myarr has only 2 levels
(myarr_cv <- dToCount(myarr, nlevels=c(2,2,4,8), startfrom1=TRUE))
###################################################################
## demo: counting vector represents the array runs
###################################################################
## full factorial in lexicographic order
fullfac <- ff(2,2,4,8) + 1 ### ff levels start with 0
##
## pick the selected runs from fullfac
selfac <- fullfac[which(myarr_cv==1),]
##
## order both variants in the same way and compare them
## (in this case, they are equal without reordering)
ord1 <- DoE.base::ord(selfac) ## order them
ord2 <- DoE.base::ord(myarr) ## order them
selfac[ord1,] == myarr[ord2,]
#######################################################
#######################################################
## We go for an array in 16 runs with four factors in
## 2,2,4,8 levels.
## Is a strength 2 oa feasible?
##
oa_feasible(16, c(2,2,4,8), 2) ## FALSE
##
## consequence: use resolution 2 (=strength 1),
## minimize number of words of length 2
problemlist <- create_ILPlist(16, nlevels = c(2,2,4,8), resolution = 2)
length(problemlist) ## 12 distinct search orders
names(problemlist[[3]])
problemlist[[3]][-2] ## ILP is too long for printing
problemlist1 <- create_ILPlist(16, nlevels = c(2,2,4,8),
resolution = 2, search.orders = FALSE)
## only the pre-specified search order
problemlist2 <- create_ILPlist(16, nlevels = c(2,2,4,8),
resolution = 2, orders = list(c(2,2,4,8),
c(8,2,4,2)))
## the two specified search orders
if (FALSE) {
write_MPSILPlist(prefix="miniprob", problemlist)
## writes miniprob01.mps, ..., miniprob12.mps and miniprob_toc.txt
write_MPSILPlist(prefix="miniprob", problemlist1, toc=FALSE)
## writes miniprob1.mps
}
## The MPS files can be read by various optimizers.
## The ILP problems aim for a feasible solution.
## Start values are possible, but usually not useful.
## The best solution (lowest target value) can be imported into R.
## the solution a counting vector
## its format depends on the optimizer
## import it into R and calculated array from it
importedsol <- myarr_cv # for demo only
solarray <- countToDmixed(myarr_cv, nlevels=c(2,2,4,8))
##
## it is crucial to use the order of the levels
## that corresponds to the problem that the solver solved
GWLP(solarray)
#######################################################
## providing a lower bound for the number of
## length 2 words in a strength 1 (resolution 2) array
#######################################################
##
lowerbound_AR(nruns = 16, nlevels = c(2,2,4,8), R = 2) # 1
##
## In this example, we have immediately hit on a solution
## with optimum A2-value (see GWLP)
#######################################################
## using a quadratic problem for optimizing A2
##
if (FALSE) {
write_MPSMIQP("quadprob", 16, c(2,2,4,8), resolution=2)
## writes quadprob.mps
}
## Run time for solving the quadratic problem exported by write_MPSMIQP
## may substantially (!) benefit from providing the lower bound of the
## objective function, if that bound is attained.
##
## The lower bound for the minimum of the quadratic problem
## created by write_MPSMIQP
## is the lower bound for the word length, multiplied with n^2,
## here 16 ^ 2 * 1 = 256,
## or half that value,
## depending on how the optimizer handles quadratic objectives.
#######################################################
## Depending on the optimizer, it is useful or even crucial to provide a
## starting value to write_MPSMIQP. This starting value can be obtained
## as the solution to a linear problem (that was exported using functions
## create_ILPlist and write_MPSILPlist).
Run the code above in your browser using DataLab