Skip to main content

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.

Latest Version on PyPI Build Status Documentation Status Coverage Status Built with PyPi Template

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:

  1. Graph Structure: Finite, connected, undirected multigraphs without loop edges
  2. Divisors: Elements of the free abelian group on vertices
  3. Laplacian Matrix: Matrix representation of lending moves
  4. Linear Equivalence: Equivalence relation on divisors
  5. Effective Divisors: Divisors with non-negative values
  6. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chipfiring-1.1.3.tar.gz (106.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chipfiring-1.1.3-py3-none-any.whl (118.2 kB view details)

Uploaded Python 3

File details

Details for the file chipfiring-1.1.3.tar.gz.

File metadata

  • Download URL: chipfiring-1.1.3.tar.gz
  • Upload date:
  • Size: 106.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for chipfiring-1.1.3.tar.gz
Algorithm Hash digest
SHA256 e2c5b50fb7f0a29a3ccd593e9bfbe53b4567ec7b7a80b308a709cb8ea24b1647
MD5 9ffab9aa61794b5ccfd64dd64f32b597
BLAKE2b-256 6136c18c380ae33d698aae897960ae460c57d0421571c74f5191065c918f7d19

See more details on using hashes here.

Provenance

The following attestation bundles were made for chipfiring-1.1.3.tar.gz:

Publisher: publish.yml on DhyeyMavani2003/chipfiring

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chipfiring-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: chipfiring-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 118.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for chipfiring-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 36432bca40ad3824f08c662834cd6de35e2c6b19607d5cb3881e24c3faef94f0
MD5 387f10c856f8641e6f06049e79d36241
BLAKE2b-256 48e5a3bd41337b08bbcb523b84c924650308263868aa99c7ae5d71f3a16ad34a

See more details on using hashes here.

Provenance

The following attestation bundles were made for chipfiring-1.1.3-py3-none-any.whl:

Publisher: publish.yml on DhyeyMavani2003/chipfiring

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page