top of page

In what kind of models does using the list() variable makes the most sense(performance-wise)? For example if you already have a working model, in what cases can it's performance be improved by rewritting the model using list() variable?


A; Lists are richer structure in the sense that they maintain an ordered collection of elements. Therefore, there is no direct equivalence between a list and the boolean variables representing the contains: in the latter case the order is missing. Lists are extremely powerful for both modelling and solving problems that need to maintain some kind of order. Very good examples are the traveling salesman problem (https://www.localsolver.com/docs/last/exampletour/tsp.html), routing problems (https://www.localsolver.com/docs/last/exampletour/vrp.html) and scheduling problems (https://www.localsolver.com/docs/last/exampletour/flowshop.html). For these kinds of problems using lists in LocalSolver is in general extremely powerful.


More generally speaking, when you want to model a complex problem, I suggest you find a similar one from our example tour (https://www.localsolver.com/docs/last/exampletour/index.html) and start from there, and then adapt it to fit your needs. It will give you nice hints to see if using lists seems relevant. Additionally, if you have any question about your specific model, feel free to reach us. We provide reactive support for our clients and we help designing their models with LocalSolver.

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