Hi everyone π
Over the past few months Iβve been working on a small optimization engine for the classic 0/1 Knapsack Problem. Itβs now live and completely free to use.
You can try it here:
https://psi-knapsack-api.onrender.com/solve
What it supports
The API has three modes:
-
exactβ classic dynamic programming -
fastβ a new heuristic I developed -
autoβ automatically chooses between them based on estimated runtime and the time budget you provide
Quick Python example
import requests
url = "https://psi-knapsack-api.onrender.com/solve"
payload = {
"capacity": 50,
"items": [
{"id": "laptop", "weight": 10, "value": 60},
{"id": "book", "weight": 20, "value": 100},
{"id": "camera", "weight": 30, "value": 120}
],
"mode": "auto", # "auto", "fast" or "exact"
"time_budget_sec": 5.0
}
response = requests.post(url, json=payload)
print(response.json())
Example response:
{
"selected_ids": ["camera", "book"],
"metrics": {
"total_value": 220,
"total_weight": 50,
"latency_ms": 1.24,
"fractional_bound_gap": 0.0
},
"decision": {
"candidate_chosen": "dp",
"mode_requested": "auto",
"time_budget_sec": 5.0
},
"reason": "AUTO selected DP due to low ETA (0.0001s Β± 0.0s)."
}
Limits
Max items per request: 20,000
Rate limit: 20 requests per minute per IP
Time budget: 0.1s β 30s per request
Note: Itβs running on a free-tier instance on Render, so the first request may take ~30 seconds (cold start). Subsequent requests respond in milliseconds.
Iβd love to hear any feedback, especially about:
The quality of the new heuristic
Whether the auto mode makes good decisions
The overall API design
Feel free to test it with your own instances and let me know what you think!
Thanks for reading π
Top comments (0)