Skip to main content

various profit allocation methods from cooperative game theory

Project description

pyCoopGame

Profit Allocation Methods

license last-commit repo-top-language repo-language-count

Developed with the software and tools below.

Jupyter Python


Quick Links


Overview

pyCoopGame is a powerful cooperative game theory library that provides various functionalities for building, solving, and analyzing cooperative games. It allows users to create random n-player TU games, validate the game structures, and calculate important measures such as the Shapley value, Nucleolus, Cost Gap, and epsilon-Core. The library includes modules for defining the game model, constraints, objective functions, and methods for checking the existence and calculating the least core and minmax core of a game. With its comprehensive set of features, pyCoopGame simplifies the process of studying and understanding cooperative games, making it an essential tool for researchers and practitioners in the field of cooperative game theory.


Features

Feature Description
⚙️ Architecture The project follows a modular architecture, with separate modules for building and solving utility exchange networks, calculating the Shapley value, Nucleolus, Cost Gap, and epsilon-Core. The architecture promotes code reusability and easy maintenance.
🔩 Code Quality The code follows PEP8 style guidelines and maintains good readability. It demonstrates good code organization and uses meaningful function and variable names.
📄 Documentation The project includes moderate documentation, with explanations of each module and their functionality. However, it could benefit from more detailed usage examples and comprehensive API documentation.
🔌 Integrations The project does not have any notable external integrations or dependencies besides standard Python libraries such as NumPy and Pandas for data manipulation.
🧩 Modularity The codebase exhibits good modularity. Each functionality is encapsulated in separate modules, allowing for easy expansion and reuse in other projects.
🧪 Testing The project lacks unit tests or testing frameworks, which could be improved to enhance code reliability and maintainability.
⚡️ Performance The performance of the project should be acceptable for most use cases. However, without specific benchmarks or optimizations, it may not scale well for large-coalition games.
🛡️ Security The project does not involve sensitive data or user access, so security measures are not a concern in this context.
📦 Dependencies The project has no external dependencies beyond standard Python libraries.

Repository Structure

└── pyCoopGame/
    ├── LICENSE
    ├── notebooks
       └── Testing.ipynb
    ├── pyCoopGame
       ├── __init__.py
       ├── Core.py
       ├── CostGap.py
       ├── Create_game.py
       ├── Nucleolus.py
       ├── Shapley.py
       └── Validate_game.py
    ├── README.md
    └── setup.cfg

Modules

notebooks
File Summary
Testing.ipynb This code snippet in the Testing.ipynb notebook is used to test and validate the functionality of the pyCoopGame library. It creates a random 3-player game, validates the game, checks if the core is empty, and calculates the Shapley value, Nucleolus, Cost Gap, and epsilon-Core. The results are stored in a dataframe.
pyCoopGame
File Summary
Core.py The Core.py file in the pyCoopGame repository contains functions related to building and solving an abstract model of a utility exchange network. It defines the model structure, constraints, objective functions, and provides methods for checking the existence and calculating the least core and minmax core of a game.
CostGap.py The code snippet in CostGap.py is a function tauvalue(game) that calculates the tau value in cooperative game theory. It takes a game as input and performs calculations to determine the tau value for each player. The code extracts the set of players, changes the data type of coalitions, finds the grand coalition, determines marginal profits, calculates the minimum claim, determines alpha, and finally computes the tau value for each player. The function then returns the tau values.
Create_game.py This code snippet Create_game.py is part of the pyCoopGame repository. It contains a function that creates a random n-player TU game and returns it as a DataFrame. The function generates all possible coalitions and assigns random benefits to each coalition. It also sets a random seed if provided.
Nucleolus.py The code snippet in pyCoopGame/Nucleolus.py defines functions for creating and solving an optimization model to calculate the nucleolus of a cooperative game. The functions build and instantiate the model, solve it using a specified solver, and return the nucleolus values. There are also functions for comparing nucleolus values and ranking them based on a set of deltas.
Shapley.py The Shapley.py code in the pyCoopGame repository calculates the Shapley value for each player in a cooperative game. It uses a difference in gains approach to determine the contribution of each player to every possible coalition. The result is returned as a dictionary.
Validate_game.py The code in Validate_game.py validates the style of a passed dataframe for a cooperative game. It checks the format, data types, number of players, and other properties to ensure the dataframe is correctly structured. The code outputs messages indicating the correctness of the dataframe based on the validation checks performed.

Installation

It is recommended to install the package via

pip install git+https://github.com/flechtenberg/pyCoopGame

It is also possible to install a version using

pip install pycoopgame

But there are some known issues with that version. Soon a new package release will replace this obsolete version.

Running pyCoopGame

Contributing

Contributions are welcome! Here are several ways you can contribute:

Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your github account.
  2. Clone Locally: Clone the forked repository to your local machine using a git client.
    git clone https://github.com/flechtenberg/pyCoopGame
    
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b new-feature-x
    
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message describing your updates.
    git commit -m 'Implemented new feature x.'
    
  6. Push to GitHub: Push the changes to your forked repository.
    git push origin new-feature-x
    
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.

Once your PR is reviewed and approved, it will be merged into the main branch.


License

This project is licensed under the ℹ️ BSD 3-Clause License. See the LICENSE file for additional info. Copyright (c) 2024, Fabian Lechtenberg. All rights reserved.


Acknowledgments

...

Return


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

pycoopgame-0.0.6.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

pyCoopGame-0.0.6-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file pycoopgame-0.0.6.tar.gz.

File metadata

  • Download URL: pycoopgame-0.0.6.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for pycoopgame-0.0.6.tar.gz
Algorithm Hash digest
SHA256 cbc77aa176640eabb49609ac020392e525a8f87ada5468d11c348d862bb56433
MD5 277d5f19f280a87f1e0a695973dade67
BLAKE2b-256 644ff44ecbd1211468c0b8a2714b680a5acde5554cb614ba904a3fdd2e0f92e4

See more details on using hashes here.

File details

Details for the file pyCoopGame-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: pyCoopGame-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for pyCoopGame-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a81a8f2632e99dee739b93373b0db3a3179752ffa7c2cfe5dece2b241cfa4162
MD5 78311b32592a3e0ef45c8d5617c5a974
BLAKE2b-256 4a6998a0572983b25b5994d8237082d46d3f1334421241cbc5ac9e86a78d7711

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