ccubes-cl/R/compare.R

91 lines
3.1 KiB
R
Raw Normal View History

2025-03-28 02:12:10 +02:00
compare <- function(
iter = 1:10,
ncols = 21:27,
nrows = 25:35,
file = "results.csv",
espresso = TRUE,
avg = 1
) {
on.exit({
suppressWarnings(sink())
})
for (nc in ncols) {
for (nr in nrows) {
for (i in iter) {
dat <- gendat(i, nc, nr)
make_infile(dat)
## $ sudo port install espresso
# lo <- system("espresso -Dexact -o eqntott infile.esp", intern = TRUE)[1]
if (espresso) {
etc <- admisc::tryCatchWEM(
es_time <- system.time(
elo <- LogicOpt::logicopt(esp_file = "infile.esp")
)
)
}
ctc <- admisc::tryCatchWEM({
cc_time <- NULL
for (ii in seq(avg)) {
cc_time <- c(
cc_time,
system.time(
cc <- .Call("CCubes", dat, PACKAGE = "IEEE")
)[3]
)
}
})
2025-03-30 00:03:42 +02:00
if (is.null(ctc) & !is.null(cc)) {
2025-03-28 02:12:10 +02:00
colnames(cc) <- colnames(dat)[-nc]
if (espresso) {
soles <- apply(
elo[[1]][, -nc], 1,
function(x) {
x <- x[x != "-"]
names(x)[x == 0] <- paste("!", names(x)[x == 0], sep = "")
return(c(paste(names(x), collapse = "&"), length(x)))
}
)
}
solcc <- apply(cc, 1, function(x) {
x <- x[x > 0] - 1
names(x)[x == 0] <- paste("!", names(x)[x == 0], sep = "")
return(c(paste(names(x), collapse = "&"), length(x)))
})
sink(file, append = TRUE)
cat(
sprintf(
"%s, %s, %s, %s, %s, %s%s, %s%s\n",
i, nc, nr,
round(es_time[3], 3),
round(min(cc_time), 3),
ifelse(
espresso,
paste0("\"(", paste(soles[1, ], collapse = ") + ("), ")\", "),
""
),
paste0("\"(", paste(solcc[1, ], collapse = ") + ("), ")\""),
ifelse(
espresso,
paste(paste(soles[2, ], collapse = ""), ", ", sep = ""),
""
),
paste(solcc[2, ], collapse = "")
)
)
sink()
} else {
cat(sprintf("i: %s, nc: %s, nr: %s\n", i, nc, nr))
}
}
}
}
}