Search code examples
vbalimitlinear-programmingsolver

Limiting chosen variables solved for in opensolver


I've got a linear system of 17 equations, 506 variables that solve for a minimum summation of the total variables. This works fine, so far, but the solution is a result of a combination of 19 variables.

But in the end I want to limit the amount of chosen variables to 10, without knowing in advance which ones are the optimal ones (The solver figures that out for me, as well as their ratio).

I figured I can set a boolean = 1 if the value becomes larger than 0: (meaning the variable is picked), and 0 if the variable is not picked for an optimal solution.

And then have the sum of the booleans be 10 at most.

However this seems a bit elaborate, and I was wondering whether there was a built in option in the opensolver, for I think it is quite a common problem to solve a large set with a subset.

So does anyone have a suggestion on:

  1. How my elaborate way drastically decreases performance? (*I have no intrinsic comprehension of the opensolver algorithms, yet.)
  2. A suggestion to more easily/within the opensolver options account for my desire of max. 10 solution variables?

Based on the information provided below, I first scaled down the size of the problem:

I have three lists of data with 18 entries in columns:

W7:W23,AC7:AD23

which manually (with: W28 = 6000, AC28=600,W29 = 1,AC29 =1), in a linear combination,equal/exceed the target list: EGM34:EG50

So what I did was put the descion variables in W28:W29, AC28:AD29 Where I added the constraint W28,AC28:AD28 = integer in the solver (both the original excel solver as in opensolver)

And I added the constraint W29,AC29:AD29 = Boolean in the solver (both the original excel solver as in opensolver)

Then I have a multiplication of the integer*boolean = the actual multiplication factor for the above lists in (W7:W23 etc)

In order to limit the nr of chosen variables I have also tried, in addition to the described constraints, to limit the cell with =sum(W29,AC29:AD29) to <= 10 (effectively reducing the amount of booleans set to true below 11, or so I thought, but the booleans aren't evaluated as booleans by the solver).

These new multiplied lists are placed in W34:W50,AC34:AD50, and the summation is situated in: EGY34:EGY50 Hence the final check is added as a constraint as:

EGY34:EGY50 =>EGM34:EGM50

And I had a question about how the linear solver evaluates these constraints, does it:

a. Think the sum of EGY34:EGY50 must be larger or equal than/to EGM34:EGM50

or

b. Does it think: "for every row x EGYx must be larger or equal than/to EGMx

So far I've noted b. but I would like to make sure.

But my main question concerns:

After using the Evolutionary algorithm as was kindly suggested in the comments below, how/why does it try values as 0.99994 for the desicion variables designated as booleans?


Solution

  • The introduction of binary variables is indeed the standard way to implement such constraints. Unfortunately, it transforms the problem from being a linear programming problem to being an integer programming problem (specifically a mixed integer linear programming problem). A standard approach to such problems is the branch and bound algorithm. This is what Excel's built-in solver seems to use, I'm not sure about the open solver that you are using. In the best case (where there is a lot of bounding) it will run fairly rapidly, even with problems of your size. In the worst case, for your problem it could be little better than what you would get by running the simplex algorithm C(506,10) = 2.8 x 10^20 times (once for each possible set of 10 decision variables). In other words, it might be infeasible. Integer programming is known to be NP-hard.

    If an exact solution is infeasible, you could always use a heuristic algorithm such as an evolutionary approach.