ksumHash: Build k-sum accelerator

View source: R/RcppExports.R

ksumHashR Documentation

Build k-sum accelerator

Description

Compute k-sum lookup tables given a set.

Usage

ksumHash(
  ksumK,
  V,
  ksumTableSizeScaler = 30L,
  target = NULL,
  len = 0L,
  approxNinstance = 1000L,
  verbose = TRUE,
  maxCore = 7L
  )

Arguments

ksumK

See the same argument in arbFLSSS().

V

See the same argument in arbFLSSS().

ksumTableSizeScaler

See the same argument in arbFLSSS().

target

See the same argument in arbFLSSS(). If target != NULL, the function will (i) decompose the arbFLSSS instance of (len, target, V) into about approxNinstance subproblems, (ii) from these subproblems infer the lower and upper index bounds for the k-subsets, and then (iii) compute & hash k-sums to build the accelerator. If target = NULL, no bounds will be imposed on the k-subsets and the accelerator built can be used for any subset sum instance.

len

See the same argument in arbFLSSS(). Will be ignored if target == NULL.

approxNinstance

See the same argument in arbFLSSS().

verbose

See the same argument in arbFLSSS().

maxCore

See the same argument in arbFLSSS().

Details

k-sums are hashed using Yann Collet's xxHash that is the fastest among all non-cryptographic hash algorithms by 202204. See the benchmark <https://github.com/Cyan4973/xxHash>.

Value

Either an empty list (happens when, e.g. ksumK < 3), or a list of lists. The first list would be the 3-sum lookup table, and the last would be the ksumK-sum lookup table.

Examples

set.seed(42)
d = 5L # Set dimension.
N = 30L # Set size.
len = 10L # Subset size.
roundN = 2L # For rounding the numeric values before conversion to strings.


V = matrix(round(runif(N * d, -1e5, 1e5), roundN), nrow = N) # Make superset.
sol = sample(N, len) # Make a solution.
target = round(colSums(V[sol, ]), roundN) # Target subset sum.


optionSave = options()
options(scipen = 999) # Ensure numeric => string conversion does not
# produce strings like 2e-3.
Vstr = matrix(as.character(V), nrow = N) # String version of V.
targetStr = as.character(target)


system.time({
  theDecomposed = FLSSS::decomposeArbFLSSS(
    len = len, V = Vstr, target = targetStr, approxNinstance = 1000,
    maxCore = 2, ksumTable = NULL, ksumK = 4, verbose = TRUE)
})


# Run the objects sequentially.
rst = unlist(lapply(theDecomposed$arbFLSSSobjects, function(x)
{
  FLSSS::arbFLSSSobjRun(x, solutionNeed = 1e9, tlimit = 5, verbose = FALSE)
}), recursive = FALSE)
str(rst)


options(optionSave)

FLSSS documentation built on May 17, 2022, 5:09 p.m.

Related to ksumHash in FLSSS...