Skip to main content

A fast algorithm for online packing.

Project description

MIT License LinkedIn


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, PythonMIPSolver)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast-online-packing-0.0.1.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

fast_online_packing-0.0.1-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file fast-online-packing-0.0.1.tar.gz.

File metadata

  • Download URL: fast-online-packing-0.0.1.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

Hashes for fast-online-packing-0.0.1.tar.gz
Algorithm Hash digest
SHA256 335998e166d9cc4aee955ae9d5c491f18b7a786ff534ac8604347e7431912720
MD5 4a77c1887cfe694328037974a7fafe4c
BLAKE2b-256 3f098d1c9e60ffd97caf4d049915f52a197a9b7d7f806dc8a64faf99131bf031

See more details on using hashes here.

File details

Details for the file fast_online_packing-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: fast_online_packing-0.0.1-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

Hashes for fast_online_packing-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f469c0c94ef1e801cea58f71c57a681ad35f164b1891fc5d8604a3f1114b648
MD5 ed3b5024936f670c883b342c91b11adc
BLAKE2b-256 1973d0c388eb62daf03ed7f934e659c257ceb10870b5bb0afc9d59b2c09b74c4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page