pNeuma_simulator.simulate module

exception pNeuma_simulator.simulate.CollisionException(message, payload=None)[source]

Bases: Exception

Raised when agents collide

pNeuma_simulator.simulate.batch(seed: int, permutation: tuple, n_jobs: int, distributed: bool = True, stochastic: bool = True)[source]

Run a batch simulation with the given seed and permutation.

Parameters:
  • seed (int) – The seed for random number generation.

  • permutation (tuple) – A tuple containing the number of cars and motorcycles.

  • n_jobs (int) – Number of parallel jobs.

  • distributed (bool, optional) – Flag indicating if the simulation is distributed. Defaults to True.

  • stochastic (bool, optional) – Flag indicating if the simulation is stochastic. Defaults to True.

Returns:

A tuple containing the simulation results for cars and motorcycles.

Return type:

tuple

pNeuma_simulator.simulate.identify(matrix: ndarray, image_rad: ndarray, ID: int) ndarray[source]

Identifies and replaces pixels in the matrix with the given ID based on a condition.

Parameters:
  • matrix (ndarray) – The input matrix.

  • image_rad (ndarray) – The flattened array of image radii.

  • ID (int) – The ID to replace the pixels with.

Returns:

The modified matrix with replaced pixels.

Return type:

ndarray

pNeuma_simulator.simulate.infront(e_i, pos_i, pos_j)[source]

Determines if a neighbor is in front of a given position.

Parameters:
  • e_i – The direction vector of the current position.

  • pos_i – The current position.

  • pos_j – The position of the neighbor.

Returns:

A boolean indicating if the neighbor is in front of the current position. e_i_j: The unit vector from the current position to the neighbor. s_i_j: The distance from the current position to the neighbor.

Return type:

front

pNeuma_simulator.simulate.main(n_cars: int, n_moto: int, seed: int, parallel: Callable, COUNT: int = 500, distributed: bool = True, stochastic: bool = True)[source]

Simulates the main loop of a pNeuma simulator.

Parameters:
  • n_cars (int) – Number of cars.

  • n_moto (int) – Number of motorcycles.

  • seed (int) – Seed for the random number generator.

  • parallel (Callable) – Callable object for parallel execution.

  • COUNT (int, optional) – Number of iterations in the main loop. Defaults to 500.

  • distributed (bool, optional) – Flag indicating if the simulation is distributed. Defaults to True.

  • stochastic (bool, optional) – Flag indicating if the simulation is stochastic. Defaults to True.

Returns:

A tuple containing the list of serialized agents at each iteration and an empty list.

Return type:

Tuple