This is an Pythonic API for visualization and analysis of chip firing games and corresponding algorithms.
Project description
chipfiring
Unified interface for visualization and analysis of chip firing games and related algorithms.
A Python implementation of the chip-firing game (also known as the dollar game) on graphs. This package provides a mathematical framework for studying and experimenting with chip-firing games, with a focus on the dollar game variant.
Documentation
Visit Read the Docs for the full documentation, including overviews and several examples.
Overview
The chip-firing game is a mathematical model that can be used to study various phenomena in graph theory, algebraic geometry, and other areas of mathematics. In the dollar game variant, we consider a graph where:
- Vertices represent people
- Edges represent relationships between people
- Each vertex has an integer value representing wealth (negative values indicate debt)
- Players can perform lending/borrowing moves by sending money across edges
The goal is to find a sequence of moves that makes everyone debt-free. If such a sequence exists, the game is said to be winnable.
Installation
pip install chipfiring
Usage
Here's a simple example of how to use the package:
from chipfiring.graph import Graph, Vertex
from chipfiring.divisor import Divisor
from chipfiring.dollar_game import DollarGame
# Create vertices
alice = Vertex("Alice")
bob = Vertex("Bob")
charlie = Vertex("Charlie")
elise = Vertex("Elise")
# Create graph
G = Graph()
G.add_vertex(alice)
G.add_vertex(bob)
G.add_vertex(charlie)
G.add_vertex(elise)
# Add edges
G.add_edge(alice, bob)
G.add_edge(alice, charlie)
G.add_edge(alice, elise)
G.add_edge(bob, charlie)
G.add_edge(charlie, elise)
# Create initial wealth distribution
initial_divisor = Divisor(G, {
alice: 2,
bob: -3,
charlie: 4,
elise: -1
})
# Create and play the game
game = DollarGame(G, initial_divisor)
# Check if game is winnable
print(f"Is winnable? {game.is_winnable()}")
# Try some moves
game.fire_vertex(charlie) # Charlie lends
game.borrow_vertex(bob) # Bob borrows
game.fire_set({alice, elise, charlie}) # Set-firing move
# Check current state
print(f"Current wealth: {game.get_current_state()}")
print(f"Is effective? {game.is_effective()}")
Mathematical Background
The implementation follows the mathematical formalization described in the LaTeX writeup, which includes:
- Graph Structure: Finite, connected, undirected multigraphs without loop edges
- Divisors: Elements of the free abelian group on vertices
- Laplacian Matrix: Matrix representation of lending moves
- Linear Equivalence: Equivalence relation on divisors
- Effective Divisors: Divisors with non-negative values
- Winnability: Property of being linearly equivalent to an effective divisor
Features
- Mathematical graph implementation with support for multigraphs
- Divisor class with operations for lending and borrowing
- Laplacian matrix computations
- Linear equivalence checking
- Set-firing moves
- Comprehensive type hints and documentation
Development
To set up the development environment:
# Clone the repository
git clone https://github.com/yourusername/chipfiring.git
cd chipfiring
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -r requirements.txt
pip install -r requirements.docs.txt
# Run tests
pytest
# Build documentation
cd docs
make html
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
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 chipfiring-1.1.0.tar.gz.
File metadata
- Download URL: chipfiring-1.1.0.tar.gz
- Upload date:
- Size: 105.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
982a4db50db8a20c3133a227361ebc50dd76a15a6a9d91781070d6cf92f412d7
|
|
| MD5 |
42e8a89433ac55967ca635b6e56ba48c
|
|
| BLAKE2b-256 |
bb2f1a2dfc8b992692ee45cc098559efa2a5a865344da114677334e096d1a5d9
|
Provenance
The following attestation bundles were made for chipfiring-1.1.0.tar.gz:
Publisher:
publish.yml on DhyeyMavani2003/chipfiring
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chipfiring-1.1.0.tar.gz -
Subject digest:
982a4db50db8a20c3133a227361ebc50dd76a15a6a9d91781070d6cf92f412d7 - Sigstore transparency entry: 307506300
- Sigstore integration time:
-
Permalink:
DhyeyMavani2003/chipfiring@334b6fad7e69d3ae410f3beb53197913624c7347 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/DhyeyMavani2003
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@334b6fad7e69d3ae410f3beb53197913624c7347 -
Trigger Event:
release
-
Statement type:
File details
Details for the file chipfiring-1.1.0-py3-none-any.whl.
File metadata
- Download URL: chipfiring-1.1.0-py3-none-any.whl
- Upload date:
- Size: 117.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3054b205bc1dfc5c1e34152eb493c19fa68c916e4e074e448d10d5bd318bcef2
|
|
| MD5 |
603a693d7a873582c377af6a47426cf9
|
|
| BLAKE2b-256 |
10bd1b9877e753ed9269e8172f865a175f7477ecfcb30226cf0cc6783ddd1507
|
Provenance
The following attestation bundles were made for chipfiring-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on DhyeyMavani2003/chipfiring
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chipfiring-1.1.0-py3-none-any.whl -
Subject digest:
3054b205bc1dfc5c1e34152eb493c19fa68c916e4e074e448d10d5bd318bcef2 - Sigstore transparency entry: 307506304
- Sigstore integration time:
-
Permalink:
DhyeyMavani2003/chipfiring@334b6fad7e69d3ae410f3beb53197913624c7347 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/DhyeyMavani2003
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@334b6fad7e69d3ae410f3beb53197913624c7347 -
Trigger Event:
release
-
Statement type: