Skip to main content

Python bindings for SIMILAR2Logo multi-agent simulation framework

Project description

SIMILAR & JamFree: High-Performance Agent-Based Simulation Framework

License Python C++

SIMILAR is a powerful agent-based modeling framework with a Python DSL backed by a high-performance C++ engine. JamFree is a traffic simulation framework built on SIMILAR, featuring microscopic and macroscopic models with real-time data integration.

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/gildasmorvan/similar
cd similar

# Build C++ engine (recommended for 10-100x performance boost)
./build_cpp_engine.sh

# Install Python dependencies
pip install -r requirements.txt

๐Ÿ“– New to SIMILAR? See Getting Started Guide for a complete walkthrough!

โšก Quick Commands? Check Quick Reference for a command cheat sheet!

Your First Simulation (SIMILAR2Logo)

Create my_first_sim.py:

from similar2logo.dsl import *
import random

class RandomWalker(Turtle):
    def decide(self, perception):
        influences = []
        if random.random() < 0.3:
            influences.append(self.influence_turn(random.uniform(-0.5, 0.5)))
        influences.append(self.influence_move_forward(1.0))
        return influences

# Create environment and simulation
env = Environment(100, 100, toroidal=True)
sim = Simulation(environment=env, title="Random Walk")

# Add 50 agents
for _ in range(50):
    sim.add_agent(RandomWalker(
        position=env.random_position(),
        heading=env.random_heading()
    ))

# Run with web interface
sim.run_web(port=8080)

Run it:

python3 my_first_sim.py
# Open http://localhost:8080

Your First Traffic Simulation (JamFree)

cd cpp/jamfree

# Build JamFree
./build.sh

# Run web interface
./run_web_ui.sh
# Open http://localhost:5001

๐Ÿ“š What's Included

SIMILAR2Logo - Agent-Based Modeling

A Python DSL for creating agent-based simulations with:

  • ๐Ÿข Turtle Agents: Logo-style agents with perception and decision-making
  • ๐ŸŒ Environments: Toroidal/bounded worlds with pheromones and obstacles
  • ๐Ÿง  Influences: Clean action system (move, turn, emit signals)
  • โšก C++ Engine: Automatic 10-100x speedup when available
  • ๐ŸŒ Web UI: Real-time visualization in browser
  • ๐Ÿ“Š 18+ Examples: From flocking to epidemiology

Examples: Boids, Ant Foraging, Virus Spread, Segregation, Predator-Prey, and more!

JamFree - Traffic Simulation

A comprehensive traffic simulation framework featuring:

  • ๐Ÿš— Microscopic Models: IDM car-following, MOBIL lane-changing
  • ๐ŸŒŠ Macroscopic Models: LWR, CTM continuum flow
  • ๐Ÿ”„ Hybrid Simulation: Automatic micro/macro switching
  • ๐Ÿ—บ๏ธ OSM Integration: Real-world road networks
  • ๐Ÿ“ก Real-Time Data: TomTom, HERE, OpenTraffic integration
  • ๐ŸŽฏ Routing: A* pathfinding with turn-by-turn navigation
  • โšก GPU Acceleration: Metal GPU support (macOS)
  • ๐ŸŒ Web Interface: Interactive visualization

๐ŸŽฏ Key Features

Performance

  • C++ Engine: Core simulation logic in optimized C++
  • Python DSL: Easy-to-use Python interface
  • Parallel Processing: Multi-threaded simulation
  • GPU Support: Metal acceleration for large-scale traffic sims
  • Adaptive Hybrid: Automatic micro/macro switching for optimal speed

Flexibility

  • Multiple Paradigms: Microscopic, macroscopic, hybrid
  • Real Data: OSM maps, traffic APIs, real-time integration
  • Extensible: Easy to add new models and behaviors
  • Cross-Platform: Linux, macOS, Windows

Usability

  • Clean DSL: Intuitive Python API
  • Web Visualization: No GUI installation needed
  • Rich Examples: 18+ SIMILAR2Logo + traffic examples
  • Documentation: Comprehensive guides and tutorials

๐Ÿ“– Documentation

๐Ÿ“š Complete Documentation Index - Find any document quickly!

SIMILAR2Logo

JamFree

๐ŸŽจ Examples

SIMILAR2Logo Examples

All located in examples/python/:

Basic

  • simple_random_walk.py - Basic movement
  • circle.py - Formation patterns
  • passive_turtle.py - Physics simulation

Flocking & Collective

  • boids_dsl.py - Classic flocking behavior
  • boids_obstacles.py - Flocking with obstacle avoidance
  • ant_foraging_dsl.py - Pheromone-based foraging

Biological

  • virus_spread.py - Epidemiology (SIR model)
  • predator_prey.py - Lotka-Volterra dynamics
  • heatbugs.py - Temperature-seeking agents

Social & Urban

  • segregation_model.py - Schelling's model
  • transport.py - Traffic simulation

Patterns & Emergence

  • turmite.py - Langton's Ant
  • multiturmite.py - Multiple ants
  • forest_fire.py - Cellular automaton

And more! See examples/python/README.md for the complete list.

JamFree Examples

Located in cpp/jamfree/examples/:

  • Basic Simulation - Simple traffic flow
  • OSM Integration - Real-world maps
  • Hybrid Simulation - Micro/macro switching
  • GPU Acceleration - Metal-accelerated simulation
  • Routing - Path planning and navigation

๐Ÿƒ Running Examples

SIMILAR2Logo

# Run any example
python3 examples/python/boids_dsl.py

# With C++ engine verification
SIMILAR_VERBOSE=1 python3 examples/python/virus_spread.py

# Run all examples (testing)
python3 examples/python/run_examples.py

JamFree

cd cpp/jamfree

# Web interface (recommended)
./run_web_ui.sh
# Then open http://localhost:5001

# Command-line simulation
python3 examples/basic_simulation.py

# With performance stats
python3 examples/hybrid_simulation.py

๐Ÿ”ง Building from Source

SIMILAR2Logo C++ Engine

# Build C++ engine
./build_cpp_engine.sh

# Verify it works
SIMILAR_VERBOSE=1 python3 examples/python/boids_dsl.py
# Should see: โœ“ Using C++ reaction engine

JamFree

cd cpp/jamfree

# Build core library
./build.sh

# Build with Python bindings
./build_python.sh

# Build with GPU support (macOS only)
./build_metal.sh

๐ŸŒ Web Interfaces

SIMILAR2Logo Web UI

Most examples include a built-in web interface:

# In your simulation
sim.run_web(port=8080, steps_per_frame=1)

Then open http://localhost:8080

JamFree Web UI

Full-featured traffic simulation interface:

cd cpp/jamfree
./run_web_ui.sh

Features:

  • ๐Ÿ—บ๏ธ Load OSM maps (upload or download)
  • ๐Ÿš— Configure vehicles and parameters
  • โšก Enable/disable optimizations
  • ๐Ÿ“Š Real-time performance metrics
  • ๐ŸŽจ Lane mode visualization (micro/macro)

๐Ÿ“Š Performance

SIMILAR2Logo

With C++ engine enabled:

  • 10-100x faster than pure Python
  • Handles 1000+ agents in real-time
  • Efficient spatial indexing
  • Optimized influence resolution

JamFree

Performance optimizations:

  • IDM Lookup Tables: 30-40% faster car-following
  • Spatial Indexing: O(log N) neighbor queries
  • Adaptive Hybrid: Auto micro/macro switching
  • GPU Acceleration: Metal support for macOS
  • Multithreading: Parallel vehicle updates

Example: 1000 vehicles on real OSM map at 10+ FPS

๐Ÿ”ฌ Research & Education

Perfect for:

  • Agent-Based Modeling courses
  • Complex Systems research
  • Traffic Engineering studies
  • Artificial Life experiments
  • Swarm Intelligence research
  • Computational Biology teaching

๐Ÿค Contributing

We welcome contributions! To contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests and documentation
  5. Submit a pull request

See individual component READMEs for specific guidelines.

๐Ÿ“„ License

This project is licensed under the CeCILL-B license - see LICENSE.txt for details.

CeCILL-B is a BSD-like license compatible with international and French law.

๐Ÿ‘ฅ Authors

  • Gildas Morvan - Original SIMILAR framework
  • Contributors - See AUTHORS.txt

๐Ÿ”— Resources

Documentation

Academic References

  • Traffic Flow Dynamics - Treiber & Kesting (2013)
  • MOBIL Model - Kesting et al. (2007)
  • Agent-Based Modeling - Wilensky & Rand (2015)

Related Projects

  • SUMO - Traffic simulation
  • MATSim - Multi-agent transport
  • NetLogo - Agent-based modeling

๐ŸŽฏ Project Structure

similar/
โ”œโ”€โ”€ cpp/
โ”‚   โ”œโ”€โ”€ similar2logo/          # C++ engine for SIMILAR2Logo
โ”‚   โ””โ”€โ”€ jamfree/               # JamFree traffic simulation
โ”‚       โ”œโ”€โ”€ kernel/            # Core models (Vehicle, Lane, Road)
โ”‚       โ”œโ”€โ”€ microscopic/       # IDM, MOBIL
โ”‚       โ”œโ”€โ”€ macroscopic/       # LWR, CTM
โ”‚       โ”œโ”€โ”€ hybrid/            # Adaptive simulation
โ”‚       โ”œโ”€โ”€ gpu/               # Metal GPU acceleration
โ”‚       โ”œโ”€โ”€ realdata/          # OSM parser, traffic APIs
โ”‚       โ”œโ”€โ”€ python/            # Python bindings
โ”‚       โ””โ”€โ”€ examples/          # Example simulations
โ”œโ”€โ”€ python/
โ”‚   โ””โ”€โ”€ similar2logo/          # Python DSL
โ”‚       โ”œโ”€โ”€ dsl/               # High-level API
โ”‚       โ”œโ”€โ”€ model.py           # Core classes
โ”‚       โ””โ”€โ”€ parallel.py        # Parallel engine
โ”œโ”€โ”€ examples/
โ”‚   โ””โ”€โ”€ python/                # 18+ example simulations
โ””โ”€โ”€ docs/                      # Additional documentation

๐Ÿšฆ Status

SIMILAR2Logo

โœ… Complete - All Java examples ported to Python DSL with C++ engine

JamFree

โœ… Production Ready

  • Microscopic simulation (IDM, MOBIL)
  • Macroscopic models (LWR, CTM)
  • Hybrid adaptive simulation
  • OSM integration
  • Web UI with visualization
  • GPU acceleration (macOS)
  • Real-time traffic data integration

๐ŸŽ‰ Getting Help

  • Issues: GitHub Issues
  • Examples: Check examples/python/ for working code
  • Documentation: See individual README files
  • Verbose Mode: Use SIMILAR_VERBOSE=1 to see what's happening

๐Ÿ’ก Tips

  • Start simple: Try simple_random_walk.py first
  • Use C++ engine: Build it for major speedup
  • Check examples: 18+ working examples to learn from
  • Web UI: Great for visualization and debugging
  • Read docs: Each component has detailed documentation

Happy Simulating! ๐Ÿš€

For more information, see:

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

similar2logo-1.0.0.tar.gz (35.0 MB view details)

Uploaded Source

Built Distribution

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

similar2logo-1.0.0-py3-none-any.whl (635.7 kB view details)

Uploaded Python 3

File details

Details for the file similar2logo-1.0.0.tar.gz.

File metadata

  • Download URL: similar2logo-1.0.0.tar.gz
  • Upload date:
  • Size: 35.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for similar2logo-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5771ee5ffc612edb498c4a27afb187119b132b0682173cb757a37cf196af96a0
MD5 028251d6fce8cfc48a708eaaaa02c81f
BLAKE2b-256 8e375d163ddd6d0decae11e77c360f70a8edc9f750c5283bb12f3e2daa728f3c

See more details on using hashes here.

File details

Details for the file similar2logo-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: similar2logo-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 635.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for similar2logo-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eaffecffa84fed9b69aa567eb9d97bf9d541b661cd6506abe18adefdae217a06
MD5 f86119407c5200e2289de8b7b8e970d8
BLAKE2b-256 f5d079c4716bac2ba7d0e385ca6342ac205bfb93f664e9d731ac4a3b405a7d77

See more details on using hashes here.

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