Skip to main content

Python Package of Event-Oriented Simulation for visible light communication

Project description

VLCSim is an Event-Oriented simulator package for Visible Light Communication.

Features

  • Dynamic Environment with in/out connections
  • Flexible resource allocation algorithm
  • Flexible VLC/room parameters

Events

The simulator has 5 Type of events:

  • ARRIVE: Every time when a connection arrives to the system
  • RESUME: When a connection begin the transmission
  • PAUSE: When a Connection PAUSES the transmission
  • DEPARTURE: When a connectin ends its transmission
  • RETRYING: WHen a connection is not allocated, and uses a WAIT status, it makes a new attepmt to connect.

Code example

Next example could be used to start coding with the package:

from vlcsim import *
import math


def alloc(receiver, connection: Connection, scenario: Scenario, controller: Controller):
    vleds = scenario.vleds
    capacities = []
    for vled in vleds:
        capacities.append(scenario.capacityVled(receiver, vled))
    posBestCapacity = capacities.index(max(capacities))
    numberOfSlices = 0
    if (
        controller.numberOfActiveConnections(vleds[posBestCapacity]) > 5
        or capacities[posBestCapacity] == 0
    ):
        connection.AP = scenario.rfs[0]
        connection.receiver.capacityFromAP = scenario.capacityRf(
            receiver, connection.AP
        )
        numberOfSlices = connection.numberOfSlicesNeeded(
            connection.capacityRequired, connection.receiver.capacityFromAP
        )
    else:
        connection.AP = vleds[posBestCapacity]
        connection.receiver.capacityFromAP = capacities[posBestCapacity]
        numberOfSlices = connection.numberOfSlicesNeeded(
            connection.capacityRequired, capacities[posBestCapacity]
        )

    actualSlice = connection.nextSliceInAPWhenArriving(connection.AP)
    aux = 0
    auxFrame = 0

    # Actual frame
    for slice in range(actualSlice, connection.AP.slicesInFrame):
        if (
            len(controller.framesState(connection.AP)) == 0
            or controller.framesState(connection.AP)[0][slice] == False
        ):
            connection.assignFrameSlice(0, slice)
            aux += 1
            break

    # next frames
    for frameIndex in range(1, len(controller.framesState(connection.AP))):
        for slice in range(connection.AP.slicesInFrame):
            if controller.framesState(connection.AP)[frameIndex][slice] == False:
                connection.assignFrameSlice(frameIndex, slice)
                aux += 1
                auxFrame = frameIndex
                break

        if aux == numberOfSlices:
            break

    frameIndex = auxFrame + 1
    while aux < numberOfSlices:
        connection.assignFrameSlice(frameIndex, 0)
        frameIndex += 1
        aux += 1
    return Controller.status.ALLOCATED, connection


if __name__ == "__main__":
    # Simulator Constructor: size of the room, with the numbrer of grids and the rho parameter

    sim = Simulator(20.0, 20.0, 2.15, 10, 0.8)

    # Adding Vleds to the room
    vled = VLed(-7.5, -7.5, 2.15, 60, 60, 20, 70)
    vled.sliceTime = 0.2
    vled.slicesInFrame = 10
    vled.B = 0.5e5
    sim.scenario.addVLed(vled)
    vled = VLed(-7.5, 7.5, 2.15, 60, 60, 20, 70)
    vled.sliceTime = 0.2
    vled.slicesInFrame = 10
    vled.B = 0.5e5
    sim.scenario.addVLed(vled)
    vled = VLed(7.5, -7.5, 2.15, 60, 60, 20, 70)
    vled.sliceTime = 0.2
    vled.slicesInFrame = 10
    vled.B = 0.5e5
    sim.scenario.addVLed(vled)
    vled = VLed(7.5, 7.5, 2.15, 60, 60, 20, 70)
    vled.sliceTime = 0.2
    vled.slicesInFrame = 10
    vled.B = 0.5e5
    sim.scenario.addVLed(vled)

    # Adding rf
    rf = RF(0, 0, 0.85)
    rf.sliceTime = 0.2
    rf.slicesInFrame = 10
    rf.B = 0.5e5
    sim.scenario.addRF(rf)

    # setting algorithm and number of connections
    sim.set_allocation_algorithm(alloc)
    sim.goalConnections = 60

    # changing Dynamic
    sim.lambdaS = 1
    sim.mu = 30

    # changing random wait limits

    sim.upper_random_wait = 20
    sim.lower_random_wait = 2

    sim.lower_capacity_required = 1e5
    sim.upper_capacity_required = 5e5

    # initialize and run
    sim.init()
    sim.run()

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

vlcSim-0.3.4.tar.gz (19.8 kB view details)

Uploaded Source

File details

Details for the file vlcSim-0.3.4.tar.gz.

File metadata

  • Download URL: vlcSim-0.3.4.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for vlcSim-0.3.4.tar.gz
Algorithm Hash digest
SHA256 f9eb8a99f49f6ed89d27b5f9595dffac31ff29e452ccda1ff7768eab836facee
MD5 522c32100f7d589edcde491fb655fb2f
BLAKE2b-256 d64cfc11a62295f4ce0ccad4df32b280e1ddf3158f240220436cd68446f03d77

See more details on using hashes here.

Supported by

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