Resource distribution w.r.t. individual capacity - is it a Knapsack problem? - algorithm

I have a problem as follows:
I have few office locations and resources with different capabilities (integer numbers).
I want to distribute all the resources to different office locations to find the best way to divide them almost equally among the locations so that the capabilities of all the office locations are balanced as much as possible. Couple of things to keep in mind:
• Difference between number of resources in each office location should not be more than one.
• The capability of each office location (reached by adding individual capability) should be nearly equal as possible to each other.
I have researched over the internet and came to know about Knapsack algorithm and Bin-pack algorithm which sounds close to this problem.
Example:
Number of office locations = 3;
Number of people = 8;
People capability = 10, 20, 5, 150, 90, 200, 250, 140 (capabilities values of the 8 resources);
The above numbers are just sample. It can grow to 1000+ for resources and respective capabilities value. Number of office locations can be varied too.
I didn't start the programming part unless I am sure that the path that I am going to take it correct. I am requesting your help to guide me to a correct direction to solve this.
Also, if you can share a probable pseudo code for this, will be a great help.
Thanks!

This is the knapsack problem or is at least as difficult (consider an instance where there are only two offices), so obtaining the best solution will be very difficult. You may try to use some generic optimization heuristic like simulated annealing: http://en.wikipedia.org/wiki/Simulated_annealing

Related

Algorithm for picking orders from warehouses

I'll explain My Problem With an example.
Let's say we have:
An Order from a certain store for five products, We will name those products A,B,C,D, & E, with their quantities In the Order A(19),B(25),C(6),D(33),E(40).
A single Truck that can fit different amount of each product:A(30), B(40), C(25), D(50), E(30).
Ex: Transporting A & B together, I loaded the the Truck with A(19) so that's two thirds of what my Truck can handle, So that leaves one third for B, Which means i can only transport 1/3 of B's maximum Truck capacity which is (40/3 ≈ 13).
A Set of Warehouses which contains different amounts of each product.
I made an Excel spreadsheet which contains more useful info regarding those Warehouses like( Quantities, Distance from Each other, Distance from store ).
I want to Deliver this order to the store with the least amount of trips and distance traveled.
Is there an Algorithm for this kind of problem, Or something close i can modify on?
EDIT: Updated Links.
I would advise not to reinvent a wheel as a very first step of your work. Developing/adopting a custom algorithm for such a problem would be a very painful venture in my opinion. I would suggest using either a constraint satisfaction programming (CSP) toolkit or a direct mixed integer programming (MIP) solver.
My point is that it would be much easier to encode your problem using such tools. If performance/accuracy won't be enough for you - you could design a custom solution based on your preliminary results.
For CSP I would suggest Minizinc which has decent documentation and examples.
You could start your MIP research with GLPK. It's not very powerful, but it's definitely capable of dealing with some toy examples.

Seating Algorithm with Constraints

I am trying to make a program in which, over 5 days, a new seating arrangement is produced every day. There is a constraint that must be followed:
People are seated in groups of 4, and cannot be in the same group with another person more than once over the course of the 5 days. There are roughly 30-35 people in total.
I have done a bit of research already, and it seems that this is a Constraint Satisfaction Problem, but I was wondering if this kind of problem has a more specific name, or specific algorithm to be used with it.
In addition, is it possible to determine if this constraint is able to be met with a given sample size? I am new to the realm of graph theory, and do not know which algorithms are viable in this situation.
The link below is a good starting point for the Social Golpher Problem. It contains solutions for the simpler cases (including some with 4-tables) and gives pointers to some more advanced papers: http://www.mathpuzzle.com/MAA/54-Golf%20Tournaments/mathgames_08_14_07.html

Algorithms for Minimum resource requirements

I have a question for which I have made some solutions, but I am not happy with the scalability. I'm looking for input of some different approaches / algorithms to solving it.
Problem:
Software can run on electronic controllers (ECUs) and requires
different resources to run a given feature. It may require a given
amount of storage or RAM or a digital or Analog Input or Output for
instance. If we have multiple features and multiple controller options
we want to find the combination that minimizes the hardware
requirements (cost). I'll simplify the resources to letters to
simplify the understanding.
Example 1:
Feature1(A)
ECU1(A,B,C)
First a trivial example. Lets assume that a feature requires 1 unit of resource A, and ECU has 1 unit of resources A, B and C available, it is obvious that the feature will fit in the ECU with resources B & C left over.
Example 2:
Feature2(A,B)
ECU2(A|B,B,C)
In this example, Feature 2 requires resources A and B, and the ECU has 3 resources, the first of which can be A or B. In this case, you can again see that the feature will fit in the ECU, but only if check in a certain order. If you assign F(A) to E(A|B), then F(B) to E(B) it works, but if you assign F(B) to E(A|B) then there is no resource left on the ECU for F(A) so it doesn't appear to fit. This would lead one to the observation that we should prefer non-OR'd resources first to avoid such a conflict.
An example of the above could be a an analog input could also be used as a digital input for instance.
Example 3
Feature3(A,B,C)
ECU3(A|B|C, B|C, A|C)
Now things are a little bit more complicated, but it is still quite obvious to a person that the feature will fit into the ECU.
My problems are simply more scaled up versions of these examples (i.e. multiple features per ECU with more ECUs to choose from.
Algorithms
GA
My first approach to this was to use a genetic algorithm. For a given set of features i.e. F(A,B,C,D), and a list of currently available ECUs find which single or combination of ECUs fit the requirements.
ECUs would initially be randomly selected and features checked they fitted and added to them. If a feature didn't fit another ECU was added to the architecture. A population of these architectures was created and ranked based on lowest cost of housing all the features. Architectures could then be mated in successive generations with mutations and such to improve fitness.
This approached worked quite well, but tended to get stuck in local minima (not the cheapest option) based on a golden example I had worked by hand.
Combinatorial / Permutations
My next approach was to work out all of the possible permutations (the ORs from above) for an ECU to see if the features fit.
If we go back to example 2 and expand the ORs we get 2 permutations;
Feature2(A,B)
ECU2(A|B,B,C) = (A,B,C), (B,B,C)
From here it is trivial to check that the feature fits in the first permutation, but not the second.
...and for example 3 there are 12 permutations
Feature3(A,B,C)
ECU3(A|B|C, B|C, A|C) = (A,B,A), (B,B,A), (C,B,A), (A,C,A), (B,C,A), (C,C,A), (A,B,C), (B,B,C), (C,B,C), (A,C,C), (B,C,C), (C,C,C)
Again it is trivial to check that feature 3 fits in at least one of the permutations (3rd, 5th & 7th).
Based on this approach I was also able to get a solution also, but I have ECUs with so many OR'd inputs that I have millions of ECU permutations which drastically increased the run time (minutes). I can live with this, but first wanted to see if there was a better way to skin the cat, apart from Parallelizing this approach.
So that is the problem...
I have more ideas on how to approach it, but assume that there is a fancy name for such a problem or the name of the algorithm that has been around for 20+ years that I'm not familiar with and I was hoping someone could point me in that direction to either some papers or the names of relevant algorithms.
The obvious remark of simply summing the feature resource requirements and creating a new monolithic ECU is not an option. Lastly, no, this is not in any way associated with any assignment or problem given by a school or university.
Sorry for the long question, but hopefully I've sufficiently described what I am trying to do and this peaks the interest of someone out there.
Sincerely, Paul.
Looks like individual feature plug can be solved as bipartite matching.
You make bipartite graph:
left side corresponds to feature requirements
right side corresponds to ECU subnodes
edges connect each left and right side vertixes with common letters
Let me explain by example 2:
Feature2(A,B)
ECU2(A|B,B,C)
How graph looks:
2 left vertexes: L1 (A), L2 (B)
3 right vertexes: R1 (A|B), R2 (B), R3 (C)
3 edges: L1-R1 (A-A|B), L2-R1 (B-A|B), L2-R2 (B-B)
Then you find maximal matching for unordered bipartite graph. There are few well-known algorithms for it:
https://en.wikipedia.org/wiki/Matching_(graph_theory)
If maximal matching covers every feature vertex, we can use it to plug feature.
If maximal matching does not cover every feature vertex, we are short of resources.
Unfortunately, this approach works like greedy algorithms. It does not know of upcoming features and does not tweak solution to fit more features later. Partially optimization for simple cases can work like you described in question, but in general it's dead end - only algorithm that accounts for every feature in whole feature set can make overall effective solution.
You can try to add several features to one ECU simultaneously. If you want to add new feature to given ECU, you can try all already assigned features plus candidate feature. In this case local optimum solution will be found for given feature set (if it's possible to plug them all to one ECU).
I've not enough reputation to comment, so here's what i wanted to propose for your problem:
Like GA there are some other Random Based approaches too e.g. Bayesian Apporaoch , Decision Tree etc.
In my opinion Decision Tree will suit your problem as it, against some input dataset/attributes, shows a path to each class(in your case ECUs) that helps to select right class/ECU. Train your system with some sample data sets so that it can decide right ECU for your actual data set/Features.
Check Decision Trees - Machine Learning for more information. Hope it helps!

Algorithm for calculating most efficient grouping

I have quite a strange question on my hands.
I have a list (~500 entries) of lengths of wooden beams in different sizes, such as 3400mm, 1245mm, 900mm, etc.
The maximum length of a wooden beam is 5400mm and in order to reduce the amount of wood being wasted I want to find an algorithm that tries every possible way to combine the smaller sizes to fit into 5400mm beams or as close as possible.
So let's say I have five different lengths: 3000, 1000, 300, 2000, 900 I would end up with:
3000+2000+300 = 5300 // The closest combination to 5400, meaning the amount of wood being wasted is only 100mm on this beam.
1000+900 = 1900 // The rest
I'm not sure if this qualifies for the traveling salesman problem and I have only begun to imagine what the algorithm might look like. But since there are so many smart people with combinatory skills here I just wanted to throw it out there before I bang my head bloody.
To make things even worse
Let's say we do find a solution to the problem above. The guys over at the wood shop rarely delivers 5400mm beams but it can range from 3000 to 5000 in 100mm intervals.
So I'll get a list of beam lengths from them on delivery.
Would it be possible to match the list "this is the beams I got" with the list "find out the best combination of the required beam lengths"?
I'm not sure if it's worth it in the end but any help is appreciated.
Kind regards
Richard
This is the Cutting Stock Problem in 1 dimension. It's reducible to the Knapsack problem so it is in fact NP-complete, but it's generally tractable and in cases where it isn't many good approximate solutions exist, because this is an insanely important problem in industry.
It's typically solved exactly using dynamic programming, which is kind of a mindfuck, but you can find plenty of example implementations to help you out. Approximate polynomial time solutions typically call the dynamic programming code (which has pseudo-polynomial complexity) at various points, and the surrounding code is simpler. I guess the take home message here is don't try to write it yourself, find someone else's code and port it to your language and application environment.

Routing algorithm for multiple vehicles with multiple drops

I'm looking to find/create a routing algorithm that can be used to manage multiple vans performing deliveries as well as the loads of each of those vans.
Here's a rough specification of what I'm looking for..
The routes should be calculated in a fast and efficient manner
100+ vans / 1000+ packages / 1000+ dropoff points could be processed in one go
Each van could be a different size and have different weight restrictions
Each package could be a different size and weight
The packages should be organised onto the vans in a fair and economical manner, taking into account the routes, weight and size restrictions
The routes the vans should take should be economical and as short as possible (or a configurable balance between the two)
Vans could be limited to certain roads (low bridges, width, height and weight restrictions)
Some packages may be given timeslots for delivery
Has anyone seen this sort of thing before, and if so, any ideas as to what algorithm could be used to do this, or an example of how it could be done? I've seen a few university papers but they're quite old (probably fairly inefficient now) and don't handle the package management - they just presume all the vans and packages are the same size.
Any thoughts would be appreciated!
Rich
My impression is that this kind of problem routinely comes up in Operations Research, and the standard approach is to use a mixed integer programming solver. Here's an example of encoding a cargo shipping scheduling problem using MIP
Apparently 15 years of recent research in MIP made modern solvers 30,000 times faster than original ones.
If you want to make a solution from scratch, you could start by figuring out what your objective and constraints are, and then use some ideas from integer programming, like approximate branch-and-bound search.
pgRouting has a new function implementing a genetic algorithm for the Dial-a-Ride Problem: http://www.pgrouting.org/docs/1.x/darp.html
It's an extension of PostgreSQL/PostGIS and you can build an application with this. It also has functions for shortest path search, etc.
Any algorithm this specific is going to be proprietary and you will probably need to buy something. However, this sounds suspiciously like a problem that could be solved with a genetic algorithm implimentation. Here is some research I found:
http://www.ijimt.org/papers/38-M415.pdf
http://www.springerlink.com/content/w3165x33n24v8610/ (A book that looks like its focused on your problem)
http://www.computer.org/portal/web/csdl/doi/10.1109/ICCIT.2008.407
Just because an algorithm is old, doesn't mean its not efficient.

Resources