https://github.com/coloquinte/1dtransport
Efficient algorithm for the 1D transportation problem
https://github.com/coloquinte/1dtransport
Last synced: about 1 year ago
JSON representation
Efficient algorithm for the 1D transportation problem
- Host: GitHub
- URL: https://github.com/coloquinte/1dtransport
- Owner: Coloquinte
- License: mit
- Created: 2023-03-14T10:24:14.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-27T13:38:55.000Z (over 2 years ago)
- Last Synced: 2025-04-04T16:14:04.197Z (about 1 year ago)
- Language: C++
- Size: 47.9 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
This repository implements an algorithm for the unidimensional transportation problem.
# 1D transportation problem
In the 1D transportation problem, we need to allocate supply from n sources to m sinks, with limits on supply and demand. The total supply may be smaller than the demand.
Each sink and source has a position (an integer). The cost of allocating one unit of supply is the distance between the source and the sink.
With n sources and m sinks, the traditional algorithm runs in time larger than O(n²m²), with some approximation algorithms running in time O(mn).
The algorithm presented here runs in only O(n log n + m log m).
# Using the solver
To use the code, copy the files transportation\_1d.hpp and transportation\_1d.cpp in your sources.
Other files are only used for testing.
```cpp
Transportation1d pb(sourcePos, sinkPos, sourceSupply, sinkDemand);
vector solution = pb.solve();
```