simopt.models.dualsourcing

Simulate periods of ordering and sales for a dual sourcing inventory problem.

Module Contents

class simopt.models.dualsourcing.DualSourcingConfig

Bases: pydantic.BaseModel

Configuration model for Dual Sourcing Inventory simulation.

A model that simulates multiple periods of ordering and sales for a single-staged, dual sourcing inventory problem with stochastic demand. Returns average holding cost, average penalty cost, and average ordering cost per period.

n_days: Annotated[int, Field(default=1000, description='number of days to simulate', ge=1, json_schema_extra={'isDatafarmable': False})]
initial_inv: Annotated[int, Field(default=40, description='initial inventory', ge=0)]
cost_reg: Annotated[float, Field(default=100.0, description='regular ordering cost per unit', gt=0)]
cost_exp: Annotated[float, Field(default=110.0, description='expedited ordering cost per unit', gt=0)]
lead_reg: Annotated[int, Field(default=2, description='lead time for regular orders in days', ge=0)]
lead_exp: Annotated[int, Field(default=0, description='lead time for expedited orders in days', ge=0)]
holding_cost: Annotated[float, Field(default=5.0, description='holding cost per unit per period', gt=0)]
penalty_cost: Annotated[float, Field(default=495.0, description='penalty cost per unit per period for backlogging', gt=0)]
st_dev: Annotated[float, Field(default=10.0, description='standard deviation of demand distribution', gt=0)]
mu: Annotated[float, Field(default=30.0, description='mean of demand distribution', gt=0)]
order_level_reg: Annotated[int, Field(default=80, description='order-up-to level for regular orders', ge=0)]
order_level_exp: Annotated[int, Field(default=50, description='order-up-to level for expedited orders', ge=0)]
class simopt.models.dualsourcing.DualSourcingMinCostConfig

Bases: pydantic.BaseModel

Configuration model for Dual Sourcing Min Cost Problem.

A problem configuration that minimizes total cost for dual sourcing inventory by optimizing order levels for regular and expedited orders.

initial_solution: Annotated[tuple[int, int], Field(default=50, 80, description='initial solution')]
budget: Annotated[int, Field(default=1000, description='max # of replications for a solver to take', gt=0, json_schema_extra={'isDatafarmable': False})]
class simopt.models.dualsourcing.DemandInputModel

Bases: simopt.input_models.InputModel

Input model for daily demand.

rng: random.Random | None = None
random(mu: float, sigma: float) int

Generate a random variate from the input model.

Returns:

A random variate from the input model.

Return type:

T

class simopt.models.dualsourcing.DualSourcing(fixed_factors: dict | None = None)

Bases: simopt.base.Model

Dual Sourcing Inventory Model.

A model that simulates multiple periods of ordering and sales for a single-staged, dual sourcing inventory problem with stochastic demand. Returns average holding cost, average penalty cost, and average ordering cost per period.

Initialize the DualSourcing model.

Parameters:

fixed_factors (dict, optional) – Fixed factors for the model. Defaults to None.

class_name_abbr: ClassVar[str] = 'DUALSOURCING'

Short name of the model class.

class_name: ClassVar[str] = 'Dual Sourcing'

Long name of the model class.

config_class: ClassVar[type[pydantic.BaseModel]]

Configuration class for the model.

n_rngs: ClassVar[int] = 1

Number of RNGs used to run a simulation replication.

n_responses: ClassVar[int] = 3

Number of responses (performance measures).

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

Set the random number generator for the demand input model.

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:
    • ”average_holding_cost”: The average holding cost over the

      time period.

    • ”average_penalty_cost”: The average penalty cost over the

      time period.

    • ”average_ordering_cost”: The average ordering cost over the

      time period.

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

    each response.

Return type:

tuple[dict, dict]

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

Bases: simopt.base.Problem

Class to make dual-sourcing inventory 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] = 'DUALSOURCING-1'

Short name of the problem class.

class_name: ClassVar[str] = 'Min Cost for Dual Sourcing'

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] = False

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.

check_deterministic_constraints(x: tuple) bool

Check if a solution x satisfies the problem’s deterministic constraints.

Parameters:

x (tuple) – A vector of decision variables.

Returns:

True if the solution satisfies all deterministic constraints;

False otherwise.

Return type:

bool

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