A Python library implementing the Carousel Greedy Algorithm.
Project description
Py Carousel Greedy
A modular and user-friendly Python implementation of the Carousel Greedy algorithm.
py-carouselgreedy is the first open-source Python library designed specifically for the Carousel Greedy algorithm, a flexible metaheuristic for solving a wide variety of combinatorial optimization problems. The library was developed with a focus on ease of use, modularity, and integration into experimental pipelines.
📄 Introduced in the Conference Paper:
Carousel Greedy: From Drone Photogrammetry to Social Network Analysis, A Systematic Survey and the First Open-Source Python Library
Raffaele Dragone, Carmine Cerrone, Bruce L. Golden
Presented at ODS 2025
✨ Features
- Easy to use: define only a feasibility function and a greedy function.
- Modular and lightweight: no external dependencies.
- Adaptable to any discrete optimization problem (e.g. vertex cover, knapsack, influence maximization).
- Includes ready-to-use examples for common problems.
- Fully documented and tested.
🚀 Installation
Install from PyPI:
pip install py_carouselgreedy
🔧 Usage Example
from py_carouselgreedy import carousel_greedy
def my_feasibility(cg_instance, solution):
# Return True if solution is feasible
return ...
def my_greedy(cg_instance, solution, candidate):
# Return a score for the candidate
return ...
cg = carousel_greedy(
candidate_elements=[...],
test_feasibility=my_feasibility,
greedy_function=my_greedy
)
best_solution = cg.minimize(alpha=10, beta=0.2)
📂 Examples
You can find full working examples in the examples/ folder:
minimum_vertex_cover.pyminimum_label_spanning_tree.py
Each example shows how to define a problem-specific greedy function and feasibility check using NetworkX or standard Python structures.
🛠️ Function Parameters and Customization
When creating a CarouselGreedy instance, two user-defined functions must be provided:
test_feasibility(cg_instance, solution)greedy_function(cg_instance, solution, candidate)
These functions encapsulate the problem-specific logic and allow the algorithm to be used for a wide range of optimization problems.
🔁 cg_instance: Passing Problem Data
You can optionally pass a custom data object when instantiating the carousel_greedy class:
cg = carousel_greedy(
candidate_elements=...,
test_feasibility=my_feasibility,
greedy_function=my_greedy,
data=your_custom_data # optional
)
This data object can store any useful information (e.g., a graph, cost matrix, etc.) and is accessible inside the two functions through cg_instance.data.
✅ Feasibility Function
def my_feasibility(cg_instance, solution):
...
cg_instance: instance ofcarousel_greedyclass (with access to.data).solution: the current set of selected elements.- Returns:
Trueif the current solution is feasible,Falseotherwise.
🔍 Greedy Function
def my_greedy(cg_instance, solution, candidate):
...
cg_instance: instance ofCarouselGreedy.solution: the current partial solution.candidate: the element under evaluation.- Returns: a real-valued score (higher = more promising).
The feasibility function must return a boolean, and the greedy function must return a real number, which is used to guide the greedy selection. The candidate with the highest score is selected at each step.
📖 Algorithm Overview
The Carousel Greedy algorithm is composed of four phases:
- Greedy Construction – builds an initial solution.
- Removal Phase – removes a portion of it (based on β).
- Iterative Phase – removes and adds elements (based on α).
- Completion Phase – restores feasibility if necessary.
Users only need to define two functions:
greedy_function(cg_instance, solution, candidate)test_feasibility(cg_instance, solution)
🧑🔬 Citation
If you use this library in your research, please cite:
@inproceedings{dragone2025carousel,
title={Carousel Greedy: From Drone Photogrammetry to Social Network Analysis, A Systematic Survey and the First Open-Source Python Library},
author={Dragone, Raffaele and Cerrone, Carmine and Golden, Bruce L.},
booktitle={Optimization and Decision Science (ODS)},
year={2025}
}
📬 Contact & Contributions
Pull requests are welcome. For major changes, please open an issue first.
Questions? Suggestions? Reach out to:
raffaele.dragone@edu.unige.it
📄 License
This project is licensed under the BSD 3-Clause License.
See the LICENSE file for details.
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
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 py_carouselgreedy-0.0.6.tar.gz.
File metadata
- Download URL: py_carouselgreedy-0.0.6.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecf9af073a7886f48fd9857f701f9120100dac62db3449d6b8b9b14a788c1954
|
|
| MD5 |
e9c5ac859f3a9edb5fe5cecd59c534e5
|
|
| BLAKE2b-256 |
4cda04b4ef248f9e6ae751f4039fd817ce221cd1cde3dcca741cde7283de65cb
|
File details
Details for the file py_carouselgreedy-0.0.6-py3-none-any.whl.
File metadata
- Download URL: py_carouselgreedy-0.0.6-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffd9be5ffe78d17aee38ffaa8f5c8aa14e85d604310268b7ee2cb5f05c8938fb
|
|
| MD5 |
178ebba5e647864357f098e337254502
|
|
| BLAKE2b-256 |
5e456aab7143cfc87500fbb0929d357741010fed35226b2a4f7e29413c5bb2ba
|