2

I'm creating a model to optimize purchase orders.

The amount to be ordered must be greater than 500 or equal to zero.

How do I define such a constraint in Solver?

I tried a binary constraint and I also tried several different formulas but nothing seems to work.

Basically I need to be able to express OR in Solver, how do I do that?

EDIT: in the following link you may see the excel file I'm using: Click here

Delete my account
  • 155
  • 2
  • 2
  • 7
  • The file you link to raises a warning flag that it may be deleted soon and requires signing in. SU is a knowledge base and the basic concept is that people contribute Q&As that will be enduring and help others with similar problems. If the linked file is important to your question, the essential elements should be incorporated into the question in a permanent way that any reader can access. – fixer1234 Jan 28 '16 at 18:32

2 Answers2

2

So 0 is allowed, 1 is not allowed, 499 is not allowed, and 501 is allowed? Looks like a non-contiguous area. So it's not a pure optimization problem but also a kind of combinatorial problem. I'm afraid Solver can't handle this.

You should analyze two use cases separately:

  • The amount is zero (fixed value, simple calculation);
  • The amount is 500 or greater (optimize in Solver using constraint >=500);

and then compare these two cases using an IF formula.


EDIT:

I tried to use "binary" and "integer" constraints as Karl suggested but they did not work.

  • Create a binary variable 0-1 and a continuous variable >=500, and then use IF to either copy the continuous variable or write 0 to the purchases value
  • Create a binary variable 0-1 and a continuous variable >=500, and then calculate purchases as their product
  • Create an integer variable >=499, and then use IF to replace 499 by 0 for the purchases value

In all cases, the result was often wrong and depended on initial conditions. Apparently Solver doesn't like such things.

Then I thought about applying my above proposal to all six purchase values, and optimizing them independently, for example, by optimizing the sum of costs for all months. But it turns out that they are not independent: the opening inventory depends on the previous month, and the optimal purchase for a month depends on whether a purchase was made in the previous month. So it't not possible to add a simple IF to each month.

The best I could do is the following.

I added a binary variable 0-1 and a continuous variable >=500, and calculated each month's purchases using IF. But I optimized only the continuous variables using Solver. The binary variables are a parameter. That is, we select the months when a purchase will be made, then use the Solver to calculate the values of these purchases, and then note the resulting total cost.

This should be repeated for all combinations of purchases and non-purchases. The number of these combinations is 26=64. But actually, if you don't purchase anything in January, you end up with a negative closing inventory which is not allowed. So there are only 32 valid combinations. I added formulae to calculate the binary values from the combination index, iterated the index 32 times, launched the Solver each time by hand and copied the results "as values only" for each combination.

The result is that minimum cost is 4 625,00 € and there are two combinations to reach this value.

Here is the file uploaded to Google Docs, with a Solver screenshot.

Launching Solver multiple times by hand is tedious, I believe it can be automated using macros.

  • Thanks, this is such a common problem in many companies, I can't believe solver can't handle it: the supplier requests a minimum purchase quantity, that's all. If you have the time, please have a look at my edited question above, where I posted the link to the file I'm using. Thank you. – Delete my account Jan 27 '16 at 15:32
  • @NunoNogueira, please see my edit. Apparently the correct answer is 4 625,00 € – Goblin Alchemist Jan 28 '16 at 14:58
  • Thanks a lot, this is such a complicated solution to a common problem, I'm looking for an alternative to solver. Anyway, you seemed to get it right so I'm accepting your answer. – Delete my account Jan 28 '16 at 18:41
1

Create a binary variable by adding a constraint stating that the value of the variable (in the objective function) is binary. The coefficient of this variable in the objective function must be 0. then you add the following constraints as you would normally do:

-500B+X>=0 (never go under 500)

-MB+X<=0 (combined with previous constraint forces 0 when B is 0)

B= Binary variable1

M=Very large positive number (Greater than X can ever be)

X= continuous variable

[Edit]

I understand you want to do something like this (I also made some changes in your sheets file, but I cant share the excel file I worked on here):

enter image description here

Karl
  • 63
  • 1
  • 11
  • Thanks, that sounds like a logical explanation, although I can't implement it. In my question above, I added the file I'm using, if you have the time, can you please have look? Thank you so much! – Delete my account Jan 27 '16 at 15:30
  • Hi, thanks a lot for your effort in helping me! This is making more sense now, although the problem isn't solved yet: the minimum 500 requirement per order is not satisfied. – Delete my account Jan 27 '16 at 16:43
  • I think I got it: the restrictions C5<=C14*C16 should be: C5<=C14*C16+C15. The same for the following. – Delete my account Jan 27 '16 at 16:47
  • I got the following feasible (and I believe optimal) results without changing the restrictions as you say: Opening inventory 450 50 100 425 50 Purchases 800 0 500 725 0 500 Sales 350 400 450 400 375 250 Closing inventory 450 50 100 425 50 300 Holding cost 1250 500 650 1250 475 850 Total cost 4975 – Karl Jan 27 '16 at 19:06
  • Actually, I found a simpler solution, "inspired" by yours. Have a look: https://docs.google.com/spreadsheets/d/1vGB7cHkiz5TZrcufECA2EpOfo9mFgxn6nF9gdBl-rrE/edit?usp=sharing – Delete my account Jan 27 '16 at 19:56
  • 1
    @NunoNogueira, please beware that this solution may not work. I did some experiments on a simple problem with obvious solution, and such nonlinear formula gives incorrect results that depend on initial conditions. Adding an additional variable with a "binary" constraint and multiplying by it, or adding an "IF" comparison, also doesn't work properly. Apparently Solver doesn't like discontinuities, and also mixing binary and continuous variables... – Goblin Alchemist Jan 28 '16 at 10:32
  • That's correct, I had to fix the solution solver found mannualy. – Delete my account Jan 28 '16 at 18:35