top of page

Is it more efficient to use list() variable over normal bool() variables?

Is it more efficient to use list() variable over normal bool() variables? And if it is more efficient, how is it so?


For example when defining a variable that is a subset of {0, 1, ..., n-1} which one of the two models below will be more efficient and why?

i. var <- list(n)

constraint count(var) == N (0 <= N < n)

constraint contains(i, var)

ii.var[0..n-1] <- bool()

constraint sum(var) == N

constraint var[i] == 1


A:There are two special kinds of variables when modelling with LocalSolver: set variables and list variables. Sets are unordered, and therefore can be used the way you described. The point of using sets instead of boolean variables appears when you use more structural expressions on them such as partition, disjoint, cover, count etc. If you use a set variable but right after you create all the boolean expressions with “contains”, there is no point in using set variables. However, if you do not need to explicitly have all boolean expressions, sets can be very powerful in both modelling and solving problems. A very good example if the bin packing problem which can be found here: https://www.localsolver.com/docs/last/exampletour/binpacking.html. You can also take a look at the capacitated facility location problem: https://www.localsolver.com/docs/last/exampletour/capacitated-facility-location-problem-cflp.html.

最新記事

すべて表示
bottom of page