Encode and decode variable-sized 0/1 Knapsack Problem instances (from 50 to 1000 items) using a state-of-the-art Autoencoder served via FastAPI.
This project combines the flexibility of a custom-trained Keras Autoencoder, built with exhaustive keras_tuner optimization and learning rate scheduling, with the speed and simplicity of a FastAPI backend. It even supports reading problem instances directly from the file system.
-
Autoencoder:
- 🧠 Variable Size Autoencoder trained for knapsack instances with 50–1000 items.
- 🔍 Exhaustive hyperparameter tuning via
keras_tunerfor optimal architecture. - 📉 Dynamic learning rate scheduling for better convergence.
-
⚡ FastAPI-powered API for quick encode/decode operations.
-
📁 Filesystem support to read and process instance files on the fly.
-
🧪 Ready for integration into optimization pipelines or benchmarking tools.
-
Docker container available
Encode a collection of knapsack instances to its latent representation.
{
"collection": {
"instances": []
},
"encodings": [
[
9.996188163757324,
14.908147811889648
]
]
}Decode from a latent vector back to an approximate knapsack instance.
Upload a file (e.g., .kp) containing the knapsack instance. The expected structure of the file is:
N Q
w0 p0
w1 p1
...
wN-1 pN-1
git clone https://github.com/yourusername/knapsack-autoencoder-api.git
cd knapsack-ae-apiuv run fastapi run app/app.pydocker run -d -p 8000:80 amarrerd/knapsack_ae_api:0.0.1- Encoder/decoder trained using Keras Functional API.
- Latent vector size 2d.
- Trained dataset includes 100,000+ synthetic knapsack instances.
Use the /test folder for sample knapsack problem files in supported formats.
Feel free to open an issue or PR! Contributions and suggestions are welcome.