Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
# C++SIM

## Python Port Now Available

**PySim** brings C++SIM's battle-tested discrete event simulation to Python 3.12+, preserving the API that has served researchers and engineers since 1990 while leveraging modern Python tooling.

### What You Get

- **SIMULA-style process-based simulation** - The same programming model, now with Python generators instead of OS threads
- **Validated accuracy** - 77 tests verify numerical equivalence with C++SIM output
- **Complete feature set**:
- Process scheduling (activate, hold, passivate, interrupt)
- Entity synchronization (Semaphore, TriggerQueue)
- Random streams (Uniform, Exponential, Normal, Erlang, HyperExponential, Triangular)
- Statistics collection (Mean, Variance, Histogram, Quantile)
- SimSet linked lists
- **Type hints throughout** for IDE support and static analysis
- **SimPy integration** - Built on a proven simulation engine

### Quick Start

```bash
cd pysim && pip install -e .
```

```python
from pysim import Process, Scheduler
import simpy

class Job(Process):
def body(self):
print(f"Job started at {self.current_time()}")
yield from self.hold(10.0)
print(f"Job finished at {self.current_time()}")

env = simpy.Environment()
Scheduler.scheduler(env)
Job(env).activate()
env.run()
```

See [pysim/README.md](pysim/README.md) for full documentation, API reference, and migration guide.

---

## C++SIM (Original)

C++SIM is an object-oriented simulation package which has been under development and available since 1990. It provides discrete event process-based simulation similar to SIMULA's simulation class and libraries. A complete list of the facilities provided follows:

- the core of the system gives SIMULA-like simulation routines, random number generators, queueing algorithms, and thread package interfaces.
Expand Down
45 changes: 45 additions & 0 deletions pysim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual environments
.venv/
venv/
ENV/

# IDE
.idea/
.vscode/
*.swp
*.swo

# Testing
.pytest_cache/
.coverage
htmlcov/
.tox/
.nox/

# mypy
.mypy_cache/

# uv
uv.lock
28 changes: 28 additions & 0 deletions pysim/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2026-01-19

### Added
- Initial Python port of C++SIM discrete event simulation library
- Core classes: Process, Scheduler
- Entity/Event classes: Entity, Semaphore, TriggerQueue
- Random streams: UniformStream, ExponentialStream, NormalStream, ErlangStream, HyperExponentialStream, TriangularStream, Draw
- Statistics: Mean, Variance, Histogram, PrecisionHistogram, SimpleHistogram, Quantile, TimeVariance, Pareto
- SimSet linked lists: Head, Link, Linkage (SIMULA SIMSET equivalents)
- 77 validation tests against C++ expected_output files
- Example scripts: producer_consumer.py, machine_shop.py, stats_demo.py

### Changed
- Uses SimPy as underlying simulation engine instead of pthreads
- Generator-based coroutines instead of OS threads
- Python 3.12+ required

### Notes
- PRNG produces identical sequences to C++SIM with same seeds
- API mirrors C++SIM where possible, adapted for Python idioms
- All `hold()`, `wait()`, and semaphore operations require `yield from`
Loading