A fast algorithm for online packing.
Project description
Fast Online Packing
An implementation of Agrawal & Devanur's Online Stochastic Packing Algorithm, described in "Fast Algorithms for Online Stochastic Convex Programming".
Explore the docs »
About The Project
This is an implementation of the Online Packing algorithm presented by Agrawal & Devanur on "Fast Algorithms for Online Stochastic Convex Programming" (Algorithm 6.1), published in SODA'15. This algorithm tries to solve the Online Packing problem in the random-order model. You can learn more about it in the docs.
This project aims to provide a clear understanding of the algorithm, enlighten possible implementation dificulties and be used in fast prototyping scenarios. It was not designed for runtime performance nor for use in production environments.
In addition, this library provides a Packing Problem module that describes and enforces the Online Packing problem. This module can be used independently to assist the development of other algorithms for this same problem.
External Usage Dependencies
Installation
First, check that you have Python 3.9+:
python3 --version
Then, you can install the library with the following command:
pip install fast-online-packing
Usage
from fast_online_packing import instance_generator as generator
from fast_online_packing.online_solver import OnlineSolver
n_instants = 400
cost_dim = 5
delta = 0.3
values, costs, cap, e = generator.generate_valid_instance(
delta, n_instants, cost_dim, items_per_instant=3)
# instantiate the solver
s = OnlineSolver(cost_dim, n_instants, cap, e)
for v, c in zip(values, costs):
# ask the solver which item should we pack
chosen_idx = s.pack_one(v, c)
if chosen_idx == -1:
print("No item chosen this round.")
else:
print("Algorithm picked item with index ", chosen_idx)
item_value = v[chosen_idx]
item_cost_vector = c[chosen_idx]
For more examples, please refer to the Documentation
Further Development / Contributing
Clone the repo somewhere inside your project:
git clone https://github.com/dbeyda/fast-online-packing
Install development dependencies:
pip install -r fast-online-learning/requirements.txt
Install the cloned repo using the --editable option:
pip install -e <path/to/fast-online-packing>
Develop, develop, develop. When you're finished, make to update and run the tests, and update and generate new docs.
Tests
Tests were developed using PyTest. There is one test for each module, all located under the tests/ folder.
To run all tests, use the following command:
pytest .
If you want to output the test log to a file, you can do:
pytest . > testlog.txt
Generating New Documentation
Documentation is provided in the HTML format and was generated with Sphinx. API reference was generated automatically with autodoc from docstrings. Documentation source files are found in the docs_src folder, and generated HTML docs are in the docs/ folder. This arrangement facilitates deploying the docs to GitHub Pages.
To generate new documentation:
cd docs_src
make github
Sphinx will read the .rst files in docs_src/ to generate new HTML files in the docs/ folder.
License
Distributed under the MIT License. See LICENSE.txt for more information.
Contact
David Beyda - dbeyda@poli.ufrj.br
Project Link: https://github.com/dbeyda/fast-online-packing
Disclaimer
This package was implemented as the Final Programming Assignment of my Msc. in PUC-Rio. It was developed only by me. This project is an independent work. It is not the original / official implementation of Agrawal & Devanur's paper.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast-online-packing-1.0.0.tar.gz.
File metadata
- Download URL: fast-online-packing-1.0.0.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49d598d79268179900cd91fd07b0a23bc2eb720fcfd0a1618823a2a18800d76f
|
|
| MD5 |
ddf69279cbef25893f33ef48fa5042c4
|
|
| BLAKE2b-256 |
3766eeb8da9e9e2d48f5e37efa22f99d0a15a626d749f749fb80e131fea7e7c3
|
File details
Details for the file fast_online_packing-1.0.0-py3-none-any.whl.
File metadata
- Download URL: fast_online_packing-1.0.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5736222afb762f22af5376aa07e4279699d6e6a71ccc8d2eda47615d6adaf042
|
|
| MD5 |
c23a207d5c2a8e148b82649be7f5cab7
|
|
| BLAKE2b-256 |
b2bccc0e7074381e7c50f2ee3a488d854f11764cb35fa5e65ea5f4259a4f169a
|