News for hackers. Stuff that matters.
Re:Linear Programming: How Does It Work? by blahi on Monday June 06, 2016 @05:01AM (#11845446)
The OP and the discussion is sround technical implementation, but I am interesred in the analysis part of LP.

I wanted to use LP to optimize a budget but my senior coleague said that LP is just too damn hard in the real world. Is this true? Is there a textbook that goes over practical applications of LP?

Re:Linear Programming: How Does It Work? by merraksh on Monday June 06, 2016 @09:03AM (#11846438)
It could be that the current method (i.e. human solves it by making a decision for each item) could be proved to give an optimal solution. However, if that is not the case, the hardest part will be to get the right model.

There are very competitive open source solvers for LP with 10ˆ5 or even 10ˆ6 variables/constraints (https://projects.coin-or.org/Clp), so the true limit here is formulating the model correctly. There are various optimization modeling languages out there, also in the open-source arena.

As for getting the model right, some trial-and-error approach should work: 1) if the solution violates a constraint you hadn't thought of, just add it to the formulation and re-solve; 2) if the solution is too conservative, then there might be a constraint that's too restrictive (you can check which constraints are active, i.e. restricting, at the optimal solution you found), so just eliminate it or relax it.

Re:Linear Programming: How Does It Work? by ColinWright on Monday June 06, 2016 @07:04AM (#11845827)
I am surprised that your senior colleague says it's "too damn hard." Are they referring to the conversion of your data into the right format, or are they referring to getting an implementation running? The latter is fairly straight-forward, the former depends on how clean and convertible your existing data are.

If your data are currently messy, you need to clean it up anyway. There will be political issues with doing work your senior colleague says is not possible, but if you can solve - or avoid - the political problems, learning how to do this, and then doing it, will be good for your personal development.

Warning: I suspect the political problems will actually be the most difficult part.

Re:Linear Programming: How Does It Work? by blahi on Monday June 06, 2016 @07:24AM (#11845904)
The data is squeaky clean, accounting-like data. Getting it to right format is a few lines of R. What he says is too difficult is putting in place all the right constraints. He says that it is very easy to miss a necessary constraint and this will obviously blow up your solution. How can I examine the solution to make sure it would be valid? The data consists of tens/hundreds of thousands of line items which compete for the same budget and need to meet some (fairly simple) metrics. Line items have a hidden dependency between them, so presumably the solver can scrap some items which will in turn make others (possibly the ones with the best metrics) tank too.
Re:Linear Programming: How Does It Work? by garethrees on Monday June 06, 2016 @07:43AM (#11846000)
The concern about missing necessary constraints seems reasonable, but then how does the current budgeting process avoid the same concern? Perhaps it does so by changing in small steps, so that each period's budget is similar enough to the previous period's budget (which was known to have worked reasonably well) that the differences can be analyzed and the consequences understood.

So something you might try, is to locate the current budget in your linear system and then find a nearby point that improves the objective function. It should then be simple to explain the proposed improvement ("move $A from B to C and $D from E to F and the objective function goes up by $G") and not too complex to examine it for missing constraints ("hang on, you can't reduce B by $A because the supplier has a minimum order").

The idea is that instead of using linear optimization to replace the current budgeting process (which is risky), to use it to generate proposals for submission to the current budgeting process, and to capture the constraints that are revealed when proposals are rejected.

(But note also that it's quite likely that a real objective function will be nonlinear due to economies of scale, in which case linear optimization methods won't suffice.)

Re:Linear Programming: How Does It Work? by blahi on Monday June 06, 2016 @08:01AM (#11846098)
Things like minimum orders are obvious enough that I will manage to figure them out.

My colleague's concern (and I see his point) is about what happens when the solver says "stop selling coffee machines", but when we stop, consumables drop off a cliff and consumables is where we make the profit.

Re:Linear Programming: How Does It Work? by ColinWright on Monday June 06, 2016 @08:13AM (#11846171)
So there's a missing constraint that M >= S/1000 or similar, where M=machines and S=supplies. And yes, that is an issue that needs to be considered. Over 10s or 100s of thousands of items that becomes difficult, but it's still the case that the system you describe now is not really under control.

But perhaps your senior colleague is right, and that's just the way it has to be. However, one person's time spent investigating this properly might be money well spent.

Re:Linear Programming: How Does It Work? by blahi on Monday June 06, 2016 @09:32AM (#11846607)
Yeah, but that's the problem. There is no way to know all the relationships. This was an obvious one, there are a lot more subtle ones. In any case, the comments have been very helpful. A gradual implementation is the only sane way to go. Politics are not too big of an issue, if I can make a concise case and what's a better way to do it than a small project.
Re:Linear Programming: How Does It Work? by ColinWright on Monday June 06, 2016 @09:56AM (#11846759)
Documenting these relationships would potentially be a really, really valuable thing to do "going forward". It helps to make explicit things that are currently implicit, and possibly unknown. It then opens up the possibilities of making optimisations like using Linear Programming, but at the very least it reduces risk and helps to share knowledge.

Good luck!

Re:Linear Programming: How Does It Work? by ColinWright on Monday June 06, 2016 @07:40AM (#11845976)
Now I'm less surprised. If you don't know all the constraints, explicitly and up front as part of your data, then it will be difficult.

How is it being done now? How close to optimal is the current version/solution?

The constraints form part of your data, and it sounds like they are not squeaky clean. With all computer optimisation, you need to make your data clean, clear, and complete. This can sometimes be done by simply trying it and seeing what the obvious flaws are in the proposed solutions, sometimes that's infeasible.

Re:Linear Programming: How Does It Work? by blahi on Monday June 06, 2016 @07:49AM (#11846033)
People examine data manually in reports currently. If an item turns a profit, leave it, no yield optimization. If it's in the red, stop it. If it's around break-even, schedule it for examination to see if you can turn it green. No idea how close to optimal it is. I'd imagine not at all.
Re:Linear Programming: How Does It Work? by ColinWright on Monday June 06, 2016 @08:05AM (#11846123)
OK, I'm looking in from the outside, and I know all too well how these sorts of situations arise. However, it sounds to me a lot like the managers have largely lost control of the situation, and they are limping along doing the best they can with a system that has evolved from something system into a monster.

That happens. The challenge is how to make it better.

Thinking of it like software, there are no unit tests, and touching anything runs the risk of breaking everything. The usual way to proceed is to find a small section that you can write tests for, and then gradually transform into something you understand. The equivalent here might be to find a small collection of items that are largely independent of the rest of the product line, and see if you can bring that under control.

However, I don't know your context, and I do appreciate that wholesale changes might well be risky. The question is, can you even make a start on a small section? If not, all is lost and the system will limp along as is. But if progress is desirable, maybe there is a way to start.

Given that your senior colleague has actually spoken with you about this, maybe you can open that conversation, proposing it as a gradual way to make the system more efficient, profitable, and to reduce the existing risks.

Again, on the political side, make sure they don't feel threatened, bring them on board as a partner, make it clear that you want to learn from them, and couch it all in terms of reducing risk to the company in return for a small outlay in time and effort. See it as an opportunity for you to learn, them to gain credit, and the company to become stronger.

These are my thoughts - you must adapt them to your context.

Re:Linear Programming: How Does It Work? by Pamar on Monday June 06, 2016 @07:43AM (#11845995)
Well, you will have to actually write code to create the constraints starting from the line items. This may optionally require a DSL to represents the line items and their relationships.

One question: assuming you manage to write an LP-backed solution, this will replace what? Manual inspection of the budget? Nothing at all? Some other kind of cross-reporting?

Re:Linear Programming: How Does It Work? by blahi on Monday June 06, 2016 @07:53AM (#11846053)
A ton of reporting and manual inspection. I imagine it would increase the ROI significantly too. Currently if it's green, it's good. I think there are spots which would be better for us if more budget is allocated there.

DSLs are WAY over my head though.

Re:Linear Programming: How Does It Work? by Pamar on Monday June 06, 2016 @10:06AM (#11846828)
What if you started by "zooming out" so that the variables (and constraints) are limited and manageable in a semi-manual way (i.e. you can put together a high-level model with http://scpsolver.org/) and try to understand if there is anything that stands out and then try to decompose that?

(Note: this is not how LP is supposed to work - you do not "optimize" the whole by iteratively optimize subsets, but it could give you a better understanding of the process, and maybe also get some low-hanging fruit to motivate you and your colleagues to go forward).

Re:Linear Programming: How Does It Work? by arethuza on Monday June 06, 2016 @07:25AM (#11845906)
I remember watching an Open University maths program on the practical application of linear programming when I was a high school - it was for blending food ingredients to meet the required nutritional requirements.

That was probably the late 70s!

Re:Linear Programming: How Does It Work? by Pamar on Monday June 06, 2016 @06:49AM (#11845771)
I am not sure what your colleague means with "too damn hard" - I used it once in production code to optimize distribution of lots on an assembly line, for example. That was a COBOL program dynamically preparing the equations and then calling a C routine (copied straight out of the "Numerical Recipes in C") and that was all.

Of course you have to get a bit of practice about how to represent your problem in terms of equation and objective function, and yes, there are cases where it can become quite complicated and/or become intractable due to variable explosion... but it is not necessarily so.

(I cannot suggest a book, sorry, but if you want to contact me in email we can go over your problem in general terms and see if I can provide some general advice, maybe?)

Re:Linear Programming: How Does It Work? by thanatropism on Monday June 06, 2016 @11:53AM (#11847677)
This is pretty good, although not business-oriented necessarily.

http://www.springer.com/us/book/9783540306979