vlcSim 0.3.4__tar.gz → 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
vlcsim-0.4.1/PKG-INFO ADDED
@@ -0,0 +1,424 @@
1
+ Metadata-Version: 2.4
2
+ Name: vlcSim
3
+ Version: 0.4.1
4
+ Summary: Python Package of Event-Oriented Simulation for visible light communication
5
+ License: MIT
6
+ License-File: LICENSE.md
7
+ Keywords: vlc,visible light communication,simulation,event-oriented
8
+ Author: Danilo Bórquez-Paredes
9
+ Author-email: danilo.borquez.p@uai.cl
10
+ Requires-Python: >=3.9,<4.0
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Requires-Dist: numpy (>=1.24.0,<2.0.0)
21
+ Project-URL: Homepage, https://gitlab.com/DaniloBorquez/simvlc/
22
+ Project-URL: Repository, https://gitlab.com/DaniloBorquez/simvlc/
23
+ Description-Content-Type: text/markdown
24
+
25
+ # VLCSim - Visible Light Communication Simulator
26
+
27
+ ![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)
28
+ ![Coverage](https://img.shields.io/badge/coverage-72%25-brightgreen.svg)
29
+ ![Tests](https://img.shields.io/badge/tests-166%20passing-brightgreen.svg)
30
+ ![License](https://img.shields.io/badge/license-MIT-blue.svg)
31
+ ![GitLab](https://img.shields.io/badge/gitlab-VLCSim-orange.svg)
32
+
33
+ VLCSim is an **Event-Oriented simulator** package for **Visible Light Communication (VLC)** systems. It provides a comprehensive framework for simulating dynamic VLC environments with support for resource allocation algorithms, RF fallback, and flexible room configurations.
34
+
35
+ ## Features
36
+
37
+ - **Dynamic Environment**: Simulate real-time connections with arrivals and departures
38
+ - **Hybrid Communication**: VLC with RF fallback support
39
+ - **Flexible Resource Allocation**: Implement custom allocation algorithms
40
+ - **TDM Frame Management**: Time-Division Multiplexing with configurable slices
41
+ - **Configurable Parameters**: Customize VLC/room parameters for different scenarios
42
+ - **Event-Driven Simulation**: Efficient discrete event simulation engine
43
+ - **Performance Metrics**: Built-in SNR and capacity calculations
44
+
45
+ ## Installation
46
+
47
+ ### From Source
48
+
49
+ ```bash
50
+ git clone https://gitlab.com/DaniloBorquez/vlcsim.git
51
+ cd vlcsim
52
+ pip install -e .
53
+ ```
54
+
55
+ ### Dependencies
56
+
57
+ ```bash
58
+ pip install -r requirements.txt
59
+ ```
60
+
61
+ Main dependencies:
62
+ - `numpy`: Numerical computations and random number generation
63
+ - `pytest`: Testing framework (development)
64
+ - `pytest-cov`: Coverage reporting (development)
65
+
66
+ ## Quick Start
67
+
68
+ ```python
69
+ from vlcsim import Simulator, VLed, RF
70
+
71
+ # Create a 10x10x3m room with 20 grids and 0.8 reflection coefficient
72
+ sim = Simulator(10.0, 10.0, 3.0, 20, 0.8)
73
+
74
+ # Add VLed access points
75
+ vled = VLed(5.0, 5.0, 3.0, 2, 2, 20, 60) # x, y, z, nLedsX, nLedsY, power, theta
76
+ vled.sliceTime = 0.1
77
+ vled.slicesInFrame = 10
78
+ sim.scenario.addVLed(vled)
79
+
80
+ # Add RF access point as fallback
81
+ rf = RF(5.0, 5.0, 1.0)
82
+ rf.sliceTime = 0.1
83
+ rf.slicesInFrame = 10
84
+ sim.scenario.addRF(rf)
85
+
86
+ # Configure simulation parameters
87
+ sim.lambdaS = 3 # Arrival rate
88
+ sim.mu = 10 # Service rate
89
+ sim.goalConnections = 1000
90
+
91
+ # Initialize and run
92
+ sim.init()
93
+ sim.run()
94
+ ```
95
+
96
+ ## Core Concepts
97
+
98
+ ### Events
99
+
100
+ The simulator uses 5 types of events:
101
+
102
+ | Event | Description |
103
+ |-------|-------------|
104
+ | **ARRIVE** | New connection arrives to the system |
105
+ | **RESUME** | Connection begins transmission |
106
+ | **PAUSE** | Connection pauses transmission |
107
+ | **DEPARTURE** | Connection ends transmission |
108
+ | **RETRYING** | Unallocated connection attempts to reconnect |
109
+
110
+ ### Scenario Components
111
+
112
+ - **VLed**: Visible Light LED access points with configurable power and beam angle
113
+ - **RF**: Radio Frequency access points for fallback communication
114
+ - **Receiver**: Mobile devices with photodetector capabilities
115
+ - **Connection**: Represents a data transmission session with capacity requirements
116
+
117
+ ### Resource Allocation
118
+
119
+ VLCSim supports custom resource allocation algorithms. Implement your own strategy by defining a function that assigns connections to access points and frame slices.
120
+
121
+ ## Advanced Example
122
+
123
+ ```python
124
+ from vlcsim import *
125
+
126
+ def custom_allocation_algorithm(receiver, connection: Connection,
127
+ scenario: Scenario, controller: Controller):
128
+ """Custom allocation: best VLed or RF fallback if overloaded"""
129
+ vleds = scenario.vleds
130
+ capacities = [scenario.capacityVled(receiver, vled) for vled in vleds]
131
+ best_idx = capacities.index(max(capacities))
132
+
133
+ # Use RF if VLed overloaded or no capacity
134
+ if (controller.numberOfActiveConnections(vleds[best_idx]) > 5
135
+ or capacities[best_idx] == 0):
136
+ connection.AP = scenario.rfs[0]
137
+ connection.receiver.capacityFromAP = scenario.capacityRf(receiver, connection.AP)
138
+ else:
139
+ connection.AP = vleds[best_idx]
140
+ connection.receiver.capacityFromAP = capacities[best_idx]
141
+
142
+ # Calculate required slices
143
+ numberOfSlices = connection.numberOfSlicesNeeded(
144
+ connection.capacityRequired, connection.receiver.capacityFromAP
145
+ )
146
+
147
+ # Assign slices in frames
148
+ actualSlice = connection.nextSliceInAPWhenArriving(connection.AP)
149
+ assigned = 0
150
+
151
+ # Try current frame
152
+ for slice in range(actualSlice, connection.AP.slicesInFrame):
153
+ if (not controller.framesState(connection.AP)
154
+ or not controller.framesState(connection.AP)[0][slice]):
155
+ connection.assignFrameSlice(0, slice)
156
+ assigned += 1
157
+ if assigned == numberOfSlices:
158
+ break
159
+
160
+ # Assign remaining slices in future frames
161
+ frameIndex = 1
162
+ while assigned < numberOfSlices:
163
+ if frameIndex >= len(controller.framesState(connection.AP)):
164
+ connection.assignFrameSlice(frameIndex, 0)
165
+ else:
166
+ for slice in range(connection.AP.slicesInFrame):
167
+ if not controller.framesState(connection.AP)[frameIndex][slice]:
168
+ connection.assignFrameSlice(frameIndex, slice)
169
+ break
170
+ assigned += 1
171
+ frameIndex += 1
172
+
173
+ return Controller.status.ALLOCATED, connection
174
+
175
+ # Setup simulation with 20x20x2.15m room
176
+ sim = Simulator(20.0, 20.0, 2.15, 10, 0.8)
177
+
178
+ # Add 4 VLeds in a grid pattern
179
+ for x, y in [(-7.5, -7.5), (-7.5, 7.5), (7.5, -7.5), (7.5, 7.5)]:
180
+ vled = VLed(x, y, 2.15, 60, 60, 20, 70)
181
+ vled.sliceTime = 0.2
182
+ vled.slicesInFrame = 10
183
+ vled.B = 0.5e5
184
+ sim.scenario.addVLed(vled)
185
+
186
+ # Add RF fallback
187
+ rf = RF(0, 0, 0.85)
188
+ rf.sliceTime = 0.2
189
+ rf.slicesInFrame = 10
190
+ rf.B = 0.5e5
191
+ sim.scenario.addRF(rf)
192
+
193
+ # Configure simulation parameters
194
+ sim.set_allocation_algorithm(custom_allocation_algorithm)
195
+ sim.goalConnections = 60
196
+ sim.lambdaS = 1 # 1 arrival per time unit
197
+ sim.mu = 30 # Average service time
198
+ sim.upper_random_wait = 20
199
+ sim.lower_random_wait = 2
200
+ sim.lower_capacity_required = 1e5
201
+ sim.upper_capacity_required = 5e5
202
+
203
+ # Run simulation
204
+ sim.init()
205
+ sim.run()
206
+ ```
207
+
208
+ ## Testing
209
+
210
+ VLCSim has comprehensive test coverage (72%) with 166 tests.
211
+
212
+ ### Run Tests
213
+
214
+ ```bash
215
+ # All tests
216
+ pytest tests/
217
+
218
+ # With coverage
219
+ pytest tests/ --cov=vlcsim --cov-report=term
220
+
221
+ # Specific module
222
+ pytest tests/test_controller.py -v
223
+ pytest tests/test_simulator.py -v
224
+ pytest tests/test_scenario.py -v
225
+ ```
226
+
227
+ ### Coverage by Module
228
+
229
+ | Module | Coverage |
230
+ |--------|----------|
231
+ | `vlcsim/__init__.py` | 100% |
232
+ | `vlcsim/scene.py` | 88% |
233
+ | `vlcsim/controller.py` | 71% |
234
+ | `vlcsim/simulator.py` | 49% |
235
+ | **Total** | **72%** |
236
+
237
+ ## API Reference
238
+
239
+ ### Simulator Class
240
+
241
+ Main simulation engine for event-driven VLC simulations.
242
+
243
+ ```python
244
+ sim = Simulator(length, width, height, nGrids, rho)
245
+ sim.init() # Initialize simulation
246
+ sim.run() # Execute simulation
247
+ sim.set_allocation_algorithm(func) # Set custom allocator
248
+ sim.print_initial_info() # Display scenario configuration
249
+ ```
250
+
251
+ **Key Parameters:**
252
+ - `lambdaS`: Arrival rate (connections per time unit)
253
+ - `mu`: Service rate parameter
254
+ - `goalConnections`: Total connections to simulate
255
+ - `seedX, seedY, seedZ`: Random seeds for position generation
256
+ - `upper_random_wait, lower_random_wait`: Retry delay bounds (seconds)
257
+ - `upper_capacity_required, lower_capacity_required`: Capacity bounds (bps)
258
+
259
+ ### Scenario Class
260
+
261
+ Room configuration with access points.
262
+
263
+ ```python
264
+ scenario.addVLed(vled) # Add VLC access point
265
+ scenario.addRF(rf) # Add RF access point
266
+ scenario.capacityVled(receiver, vled) # Calculate VLC capacity
267
+ scenario.capacityRf(receiver, rf) # Calculate RF capacity
268
+ ```
269
+
270
+ ### Controller Class
271
+
272
+ Manages connections and resource allocation.
273
+
274
+ ```python
275
+ controller.assignConnection(connection, time)
276
+ controller.numberOfActiveConnections(ap)
277
+ controller.framesState(ap)
278
+ controller.APPosition(ap)
279
+ controller.init() # Initialize controller with APs
280
+ ```
281
+
282
+ ### Connection Class
283
+
284
+ Represents a data transmission session.
285
+
286
+ ```python
287
+ connection.assignFrameSlice(frame, slice)
288
+ connection.numberOfSlicesNeeded(capacity, rate)
289
+ connection.nextSliceInAPWhenArriving(ap)
290
+ ```
291
+
292
+ **Key Properties:**
293
+ - `id`: Connection identifier
294
+ - `receiver`: Receiver object
295
+ - `AP`: Assigned access point (VLed or RF)
296
+ - `allocated`: Allocation status (boolean)
297
+ - `capacityRequired`: Required data rate (bps)
298
+ - `frameSlice`: Assigned TDM slices
299
+
300
+ ## Configuration Parameters
301
+
302
+ ### VLed Parameters
303
+
304
+ ```python
305
+ vled = VLed(x, y, z, nLedsX, nLedsY, ledPower, theta)
306
+ ```
307
+
308
+ - `x, y, z`: Position coordinates (meters)
309
+ - `nLedsX, nLedsY`: LED array dimensions (rows x columns)
310
+ - `ledPower`: LED power (mW)
311
+ - `theta`: Semi-angle at half illumination (degrees)
312
+ - `sliceTime`: Time slice duration (seconds)
313
+ - `slicesInFrame`: Number of slices per frame
314
+ - `B`: Bandwidth (Hz)
315
+
316
+ ### RF Parameters
317
+
318
+ ```python
319
+ rf = RF(x, y, z, bf=5e6, pf=40, BERf=10e-5)
320
+ ```
321
+
322
+ - `x, y, z`: Position coordinates (meters)
323
+ - `bf`: Bandwidth (Hz)
324
+ - `pf`: Transmission power (dBm)
325
+ - `BERf`: Bit Error Rate target
326
+ - `sliceTime`: Time slice duration (seconds)
327
+ - `slicesInFrame`: Number of slices per frame
328
+
329
+ ### Receiver Parameters
330
+
331
+ ```python
332
+ receiver = Receiver(x, y, z, aDet, ts, index, fov)
333
+ ```
334
+
335
+ - `x, y, z`: Position coordinates (meters)
336
+ - `aDet`: Detector area (m²)
337
+ - `ts`: Optical filter transmittance
338
+ - `index`: Refractive index
339
+ - `fov`: Field of view (degrees)
340
+
341
+ ## Contributing
342
+
343
+ Contributions are welcome! Please follow these steps:
344
+
345
+ 1. Fork the repository
346
+ 2. Create feature branch (`git flow feature start feature-name`)
347
+ 3. Make your changes
348
+ 4. Run tests (`pytest tests/`)
349
+ 5. Commit changes (`git commit -m 'Add feature'`)
350
+ 6. Push branch (`git push origin feature/feature-name`)
351
+ 7. Open Pull Request
352
+
353
+ ## Development
354
+
355
+ ### Project Structure
356
+
357
+ ```
358
+ vlcsim/
359
+ ├── vlcsim/
360
+ │ ├── __init__.py # Package initialization
361
+ │ ├── controller.py # Connection management and allocation
362
+ │ ├── scene.py # Scenario, VLed, RF, Receiver classes
363
+ │ └── simulator.py # Event-driven simulation engine
364
+ ├── tests/
365
+ │ ├── test_controller.py # Controller tests (42 tests)
366
+ │ ├── test_simulator.py # Simulator tests (40 tests)
367
+ │ ├── test_connection.py # Connection tests (29 tests)
368
+ │ ├── test_scenario.py # Scenario tests
369
+ │ ├── test_vled.py # VLed tests
370
+ │ ├── test_rf.py # RF tests
371
+ │ └── test_receiver.py # Receiver tests
372
+ ├── docs/ # Documentation
373
+ ├── CHANGELOG.md # Version history
374
+ ├── README.md # This file
375
+ └── requirements.txt # Dependencies
376
+ ```
377
+
378
+ ### Running Development Environment
379
+
380
+ ```bash
381
+ # Install in development mode
382
+ pip install -e .
383
+
384
+ # Install development dependencies
385
+ pip install -r requirements.txt
386
+
387
+ # Run tests with coverage
388
+ pytest tests/ --cov=vlcsim --cov-report=html
389
+
390
+ # View coverage report
391
+ open htmlcov/index.html
392
+ ```
393
+
394
+ ## License
395
+
396
+ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
397
+
398
+ ## Project Statistics
399
+
400
+ - **Lines of Code**: ~2,500
401
+ - **Test Coverage**: 72%
402
+ - **Number of Tests**: 166 passing
403
+ - **Python Version**: 3.8+
404
+ - **Modules**: 3 main modules (controller, scene, simulator)
405
+ - **Last Updated**: November 27, 2025
406
+
407
+ ## Acknowledgments
408
+
409
+ - Based on research in Visible Light Communication systems
410
+ - Event-driven simulation methodology
411
+ - TDM resource allocation strategies
412
+ - Hybrid VLC/RF communication systems
413
+
414
+ ## Contact
415
+
416
+ For questions, issues, or contributions, please:
417
+ - Open an issue on GitLab: https://gitlab.com/DaniloBorquez/vlcsim/-/issues
418
+ - Submit a merge request
419
+ - Contact the maintainers
420
+
421
+ ---
422
+
423
+ **Made with dedication for VLC research and simulation**
424
+