base module¶
Summary¶
Provide base classes for solvers, problems, and models.
- class base.Model(fixed_factors)¶
Bases:
object
Base class to implement simulation models (models) featured in simulation-optimization problems.
- Parameters
fixed_factors (dict) – Dictionary of user-specified model factors.
- check_factor_datatype(factor_name)¶
Determine if a factor’s data type matches its specification.
- Returns
is_right_type – True if factor is of specified data type, otherwise False.
- Return type
- check_simulatable_factor(factor_name)¶
Determine if a simulation replication can be run with the given factor.
- check_simulatable_factors()¶
Determine if a simulation replication can be run with the given factors.
Notes
Each subclass of
base.Model
has its own customcheck_simulatable_factors
method.- Returns
is_simulatable – True if model specified by factors is simulatable, otherwise False.
- Return type
- replicate(rng_list)¶
Simulate a single replication for the current model factors.
- Parameters
rng_list (list [
mrg32k3a.mrg32k3a.MRG32k3a
]) – RNGs for model to use when simulating a replication.- Returns
responses (dict) – Performance measures of interest.
gradients (dict [dict]) – Gradient estimate for each response.
- class base.Problem(fixed_factors, model_fixed_factors)¶
Bases:
object
Base class to implement simulation-optimization problems.
- constraint_type¶
Description of constraints types: “unconstrained”, “box”, “deterministic”, “stochastic”.
- Type
- gradient_available¶
True if direct gradient of objective function is available, otherwise False.
- Type
- model¶
Associated simulation model that generates replications.
- Type
base.Model
- rng_list¶
List of RNGs used to generate a random initial solution or a random problem instance.
- Type
list [
mrg32k3a.mrg32k3a.MRG32k3a
]
- factors¶
- Changeable factors of the problem:
- initial_solutiontuple
Default initial solution from which solvers start.
- budgetint
Max number of replications (fn evals) for a solver to take.
- Type
- Parameters
- attach_rngs(rng_list)¶
Attach a list of random-number generators to the problem.
- Parameters
rng_list (list [
mrg32k3a.mrg32k3a.MRG32k3a
]) – List of random-number generators used to generate a random initial solution or a random problem instance.
- check_budget()¶
Check if budget is strictly positive.
- Returns
True if budget is strictly positive, otherwise False.
- Return type
- check_deterministic_constraints(x)¶
Check if a solution x satisfies the problem’s deterministic constraints.
- check_factor_datatype(factor_name)¶
Determine if a factor’s data type matches its specification.
- check_initial_solution()¶
Check if initial solution is feasible and of correct dimension.
- Returns
True if initial solution is feasible and of correct dimension, otherwise False.
- Return type
- check_problem_factor(factor_name)¶
Determine if the setting of a problem factor is permissible.
- check_problem_factors()¶
Determine if the joint settings of problem factors are permissible.
Notes
Each subclass of
base.Problem
has its own customcheck_problem_factors
method.- Returns
is_simulatable – True if problem factors are permissible, otherwise False.
- Return type
- deterministic_objectives_and_gradients(x)¶
Compute deterministic components of objectives for a solution x.
- Parameters
x (tuple) – Vector of decision variables.
- Returns
det_objectives (tuple) – Vector of deterministic components of objectives.
det_objectives_gradients (tuple) – Vector of gradients of deterministic components of objectives.
- deterministic_stochastic_constraints_and_gradients(x)¶
Compute deterministic components of stochastic constraints for a solution x.
- Parameters
x (tuple) – Vector of decision variables.
- Returns
det_stoch_constraints (tuple) – Vector of deterministic components of stochastic constraints.
det_stoch_constraints_gradients (tuple) – Vector of gradients of deterministic components of stochastic constraints.
- factor_dict_to_vector(factor_dict)¶
Convert a dictionary with factor keys to a vector of variables.
Notes
Each subclass of
base.Problem
has its own customfactor_dict_to_vector
method.
- factor_dict_to_vector_gradients(factor_dict)¶
Convert a dictionary with factor keys to a gradient vector.
Notes
A subclass of
base.Problem
can have its own customfactor_dict_to_vector_gradients
method if the objective is deterministic.
- get_random_solution(rand_sol_rng)¶
Generate a random solution for starting or restarting solvers.
- Parameters
rand_sol_rng (
mrg32k3a.mrg32k3a.MRG32k3a
) – Random-number generator used to sample a new random solution.- Returns
x – vector of decision variables
- Return type
- response_dict_to_objectives(response_dict)¶
Convert a dictionary with response keys to a vector of objectives.
Notes
Each subclass of
base.Problem
has its own customresponse_dict_to_objectives
method.
- response_dict_to_objectives_gradients(response_dict)¶
Convert a dictionary with response keys to a vector of gradients.
Notes
A subclass of
base.Problem
can have its own customresponse_dict_to_objectives_gradients
method if the objective is deterministic.
- response_dict_to_stoch_constraints(response_dict)¶
Convert a dictionary with response keys to a vector of left-hand sides of stochastic constraints: E[Y] <= 0.
Notes
Each subclass of
base.Problem
has its own customresponse_dict_to_stoch_constraints
method.
- simulate(solution, m=1)¶
Simulate m i.i.d. replications at solution x.
Notes
Gradients of objective function and stochastic constraint LHSs are temporarily commented out. Under development.
- Parameters
solution (
base.Solution
) – Solution to evalaute.m (int) – Number of replications to simulate at x.
- simulate_up_to(solutions, n_reps)¶
Simulate a set of solutions up to a given number of replications.
- Parameters
solutions (set [
base.Solution
]) – A set ofbase.Solution
objects.n_reps (int) – Common number of replications to simulate each solution up to.
- vector_to_factor_dict(vector)¶
Convert a vector of variables to a dictionary with factor keys.
Notes
Each subclass of
base.Problem
has its own customvector_to_factor_dict
method.
- class base.Solution(x, problem)¶
Bases:
object
Base class for solutions represented as vectors of decision variables and dictionaries of decision factors.
- rng_list¶
RNGs for model to use when running replications at the solution.
- Type
list [
mrg32k3a.mrg32k3a.MRG32k3a
]
- det_objectives_gradients¶
Gradients of deterministic components added to objectives; # objectives x dimension.
- det_stoch_constraints_gradients¶
Gradients of deterministics components added to LHS stochastic constraints; # stochastic constraints x dimension.
- objectives¶
Objective(s) estimates from each replication; # replications x # objectives.
- Type
numpy array
- objectives_gradients¶
Gradient estimates of objective(s) from each replication; # replications x # objectives x dimension.
- Type
numpy array
- stochastic_constraints¶
Stochastic constraint estimates from each replication; # replications x # stochastic constraints.
- Type
numpy array
- stochastic_constraints_gradients¶
Gradient estimates of stochastic constraints from each replication; # replications x # stochastic constraints x dimension.
- Type
numpy array
- Parameters
x (tuple) – Vector of decision variables.
problem (
base.Problem
) – Problem to which x is a solution.
- attach_rngs(rng_list, copy=True)¶
Attach a list of random-number generators to the solution.
- Parameters
rng_list (list [
mrg32k3a.mrg32k3a.MRG32k3a
]) – List of random-number generators used to run simulation replications.copy (bool, default=True) – True if we want to copy the
mrg32k3a.mrg32k3a.MRG32k3a
objects, otherwise False.
- pad_storage(m)¶
Append zeros to numpy arrays for summary statistics.
- Parameters
m (int) – Number of replications to simulate.
- recompute_summary_statistics()¶
Recompute summary statistics of the solution.
Notes
Statistics for gradients of objectives and stochastic constraint LHSs are temporarily commented out. Under development.
- class base.Solver(fixed_factors)¶
Bases:
object
Base class to implement simulation-optimization solvers.
- constraint_type¶
Description of constraints types: “unconstrained”, “box”, “deterministic”, “stochastic”.
- Type
- rng_list¶
List of RNGs used for the solver’s internal purposes.
- Type
list [
mrg32k3a.mrg32k3a.MRG32k3a
]
- solution_progenitor_rngs¶
List of RNGs used as a baseline for simulating solutions.
- Type
list [
mrg32k3a.mrg32k3a.MRG32k3a
]
- Parameters
fixed_factors (dict) – Dictionary of user-specified solver factors.
- attach_rngs(rng_list)¶
Attach a list of random-number generators to the solver.
- Parameters
rng_list (list [
mrg32k3a.mrg32k3a.MRG32k3a
]) – List of random-number generators used for the solver’s internal purposes.
- check_crn_across_solns()¶
Check solver factor crn_across_solns.
Notes
Currently implemented to always return True. This factor must be a bool.
- check_factor_datatype(factor_name)¶
Determine if a factor’s data type matches its specification.
- check_solver_factor(factor_name)¶
Determine if the setting of a solver factor is permissible.
- check_solver_factors()¶
Determine if the joint settings of solver factors are permissible.
Notes
Each subclass of
base.Solver
has its own customcheck_solver_factors
method.- Returns
is_simulatable – True if the solver factors are permissible, otherwise False.
- Return type
- create_new_solution(x, problem)¶
Create a new solution object with attached RNGs primed to simulate replications.
- Parameters
x (tuple) – Vector of decision variables.
problem (
base.Problem
) – Problem being solved by the solvers.
- Returns
new_solution – New solution.
- Return type
base.Solution
- rebase(n_reps)¶
Rebase the progenitor rngs to start at a later subsubstream index.
- Parameters
n_reps (int) – Substream index to skip to.
- solve(problem)¶
Run a single macroreplication of a solver on a problem.
Notes
Each subclass of
base.Solver
has its own customsolve
method.- Parameters
problem (
base.Problem
) – Simulation-optimization problem to solve.- Returns
recommended_solns (list [
Solution
]) – List of solutions recommended throughout the budget.intermediate_budgets (list [int]) – List of intermediate budgets when recommended solutions changes.