views:

309

answers:

5

Given:

-A set of items that each have costs for being placed into a given container type.

-A set of container types that each have a number of available containers.

Example:

Amount*Container-Type : 5 * A, 3 * B, 2 * C

Items(Costs) :

3 * X (A=2, B=3, C=1)

2 * Y (A=5, B=2, C=2)

1 * Z (A=3, B=3, C=1)

Problem:

Find the best placement of the items into the containers so that the costs are minimal. For simplicity, only place an item into a single type of container.

I tried the hungarian method to solve the problem, but with a runtime of O(n³), it's quite prohibitive for large problems (e.g., 100000 items).

My current solution is a greedy approach, that just orders the item-container combinations by costs (asc) and assigns the first container with a sufficient amount left in O(n log n).

Is there a better solution?

A: 

Nahively I would go for a genetic aproach, given that genomes are easy to generate, mutate and cross-breed. but there may be an optimal non-combinatory solution.

krusty.ar
Well, the poster wasn't specific in the nature of the answer he wanted, granted, but I imagine he'd want something provably minimal, which he should specify. Not sure this really fits the bill.
cletus
Agreed, but some problems (and it seems this one is NOT the case) are well known to be hard to solve using just mathematics, and in those cases a genetic algorithm surely classifies as simple.
krusty.ar
A: 

If I understood your problem right, you only need some maths:

http://en.wikipedia.org/wiki/Optimization_%28mathematics%29

Chris
+5  A: 

This problem is a variant of the Knapsack problem, start at the Wikipedia page and read on from there.

The greedy algorithm is known to be a reasonably good appoximation, so you are probably good enough.

Nick Fortescue
A: 

Have you tried writing the assignment problem as a linear program and solving it using the simplex algorithm?

Zach Scrivena
The trouble with this is he's in the integer domain, which turns it into Integer Linear Programming which can't use the simplex algorithm. Otherwise it's the right solution.
Nick Fortescue
A: 

greed is good ;-)

Steven A. Lowe