simopt.models.mm1queue

Simulate an M/M/1 queue.

Module Contents

class simopt.models.mm1queue.MM1QueueConfig

Bases: pydantic.BaseModel

Configuration model for MM1 Queue simulation.

A model that simulates an M/M/1 queue with an Exponential(lambda) interarrival time distribution and an Exponential(x) service time distribution. Returns: - the average sojourn time - the average waiting time - the fraction of customers who wait for customers after a warmup period.

lambda_: Annotated[float, Field(default=1.5, description='rate parameter of interarrival time distribution', gt=0, alias='lambda')]
mu: Annotated[float, Field(default=3.0, description='rate parameter of service time distribution', gt=0)]
epsilon: Annotated[float, Field(default=0.001, description='the minimum value of mu', gt=0)]
warmup: Annotated[int, Field(default=20, description='number of people as warmup before collecting statistics', ge=0)]
people: Annotated[int, Field(default=50, description='number of people from which to calculate the average sojourn time', ge=1)]
class simopt.models.mm1queue.MM1MinMeanSojournTimeConfig

Bases: pydantic.BaseModel

Configuration model for MM1 Min Mean Sojourn Time Problem.

Min Mean Sojourn Time for MM1 Queue simulation-optimization problem.

initial_solution: Annotated[tuple[float, Ellipsis], Field(default=5, description='initial solution from which solvers start')]
budget: Annotated[int, Field(default=1000, description='max # of replications for a solver to take', gt=0, json_schema_extra={'isDatafarmable': False})]
cost: Annotated[float, Field(default=0.1, description='cost for increasing service rate', gt=0)]
class simopt.models.mm1queue.MM1Queue(fixed_factors: dict | None = None)

Bases: simopt.base.Model

MM1 Queue Simulation Model.

A model that simulates an M/M/1 queue with an Exponential(lambda) interarrival time distribution and an Exponential(x) service time distribution. Returns: - the average sojourn time - the average waiting time - the fraction of customers who wait for customers after a warmup period.

Initialize the MM1Queue model.

Parameters:

fixed_factors (dict, optional) – fixed factors of the simulation model. Defaults to None.

class_name_abbr: ClassVar[str] = 'MM1'

Short name of the model class.

class_name: ClassVar[str] = 'MM1 Queue'

Long name of the model class.

config_class: ClassVar[type[pydantic.BaseModel]]

Configuration class for the model.

n_rngs: ClassVar[int] = 2

Number of RNGs used to run a simulation replication.

n_responses: ClassVar[int] = 3

Number of responses (performance measures).

arrival_model
service_model
before_replicate(rng_list: list[mrg32k3a.mrg32k3a.MRG32k3a]) None

Prepare the model just before generating a replication.

Parameters:

rng_list (list[MRG32k3a]) – RNGs used to drive the simulation.

Raises:

NotImplementedError – If the subclass does not implement this hook.

replicate() tuple[dict, dict]

Simulate a single replication for the current model factors.

Parameters:

rng_list (list[MRG32k3a]) – Random number generators used to simulate the replication.

Returns:

A tuple containing:
  • responses (dict): Performance measures of interest, including:
    • ”avg_sojourn_time”: Average sojourn time.

    • ”avg_waiting_time”: Average waiting time.

    • ”frac_cust_wait”: Fraction of customers who wait.

  • gradients (dict): A dictionary of gradient estimates for

    each response.

Return type:

tuple[dict, dict]

class simopt.models.mm1queue.MM1MinMeanSojournTime(name: str = '', fixed_factors: dict | None = None, model_fixed_factors: dict | None = None)

Bases: simopt.base.Problem

Base class to implement simulation-optimization problems.

Initialize a problem object.

Parameters:
  • name (str) – Name of the problem.

  • fixed_factors (dict | None) – Dictionary of user-specified problem factors.

  • model_fixed_factors (dict | None) – Subset of user-specified non-decision factors passed to the model.

class_name_abbr: ClassVar[str] = 'MM1-1'

Short name of the problem class.

class_name: ClassVar[str] = 'Min Mean Sojourn Time for MM1 Queue'

Long name of the problem class.

config_class: ClassVar[type[pydantic.BaseModel]]

Configuration class for problem.

model_class: ClassVar[type[simopt.base.Model]]

Simulation model class for problem.

n_objectives: ClassVar[int] = 1

Number of objectives.

n_stochastic_constraints: ClassVar[int] = 0

Number of stochastic constraints.

minmax: ClassVar[tuple[int, Ellipsis]]

Indicators of maximization (+1) or minimization (-1) for each objective.

constraint_type: ClassVar[simopt.base.ConstraintType]

Description of constraints types.

variable_type: ClassVar[simopt.base.VariableType]

Description of variable types.

gradient_available: ClassVar[bool] = True

Indicates whether the solver provides direct gradient information.

optimal_value: ClassVar[float | None] = None

Optimal objective function value (if known).

optimal_solution: tuple | None = None

Optimal solution if known; defaults to None.

model_default_factors: ClassVar[dict]

Default values for overriding model-level default factors.

model_decision_factors: ClassVar[set[str]]

Set of keys for factors that are decision variables.

property dim: int

Number of decision variables.

property lower_bounds: tuple

Lower bound for each decision variable.

property upper_bounds: tuple

Upper bound for each decision variable.

vector_to_factor_dict(vector: tuple) dict

Convert a vector of variables to a dictionary with factor keys.

Parameters:

vector (tuple) – A vector of values associated with decision variables.

Returns:

Dictionary with factor keys and associated values.

Return type:

dict

factor_dict_to_vector(factor_dict: dict) tuple

Convert a dictionary with factor keys to a vector of variables.

Parameters:

factor_dict (dict) – Dictionary with factor keys and associated values.

Returns:

Vector of values associated with decision variables.

Return type:

tuple

replicate(x: tuple) simopt.base.RepResult

Replicate the problem for a given solution.

Parameters:

x (tuple) – The solution to evaluate.

get_random_solution(rand_sol_rng: mrg32k3a.mrg32k3a.MRG32k3a) tuple

Generate a random solution for starting or restarting solvers.

Parameters:

rand_sol_rng (MRG32k3a) – Random number generator used to sample the solution.

Returns:

A tuple representing a randomly generated vector of decision

variables.

Return type:

tuple