jijzept_solver
Submodules
Package Contents
- class ALMSimulatedAnnealingOption
Bases:
BaseSolverOptionOptions for ALM Simulated Annealing algorithm.
- num_iters
Number of iterations to run the search algorithm.
- time_limit_sec_per_iter
Time limit in seconds per iteration.
- count_per_iter
Number of sweeps per iteration.
- disable_annealing
If True, the zero temperature annealing, called hill-climbing, is executed.
- allow_optimal_move
If True, allow optimal move.
- alm_search_option_number
Option number for ALM parameter search strategy. 0: Standard 1: PenaltyHybrid
- normalize_coefficients
If True, coefficients of the objective function and constraints are normalized to its maximum coefficient being 1.
- cancel_token
Token that can be used to cancel the algorithm.
- cancel_token: CancelToken | None = None
- class CBCOption
Bases:
BaseSolverOptionOptions for the CBC solver (via Python-MIP).
- time_limit_sec
Time limit in seconds.
- class JijZeptSolverOption
Options for JijZeptSolver
- processes
List of SolverOptions, which is list of SolverOption. SolverOption can be WeightedHillClimbingOption, WeightedSimulatedAnnealingOption, LocalILPOption, SCIPOption, or CBCOption.
- class LocalILPOption
Bases:
BaseSolverOptionOptions for the Local ILP algorithm.
- time_limit_sec
Time limit in seconds for the algorithm.
- terminate_if_feasible
If True, the algorithm terminates if a feasible solution is found.
- sparse
If True, the algorithm uses a sparse representation.
- zero_objective
If True, the algorithm ignore the objective function and search for feasible solutions.
- num_tabu_capacity
Number of tabu list capacity.
- cancel_token: CancelToken | None = None
- class SCIPOption
Bases:
BaseSolverOptionOptions for the SCIP solver.
- time_limit_sec
Time limit in seconds.
- class WeightedHillClimbingOption
Bases:
BaseSolverOptionOptions for the Weighted Hill Climbing algorithm.
- num_iters
Number of iterations to run the search algorithm.
- time_limit_sec_per_iter
Time limit in seconds per iteration.
- cancel_token
Token that can be used to cancel the algorithm.
- cancel_token: CancelToken | None = None
- class WeightedSimulatedAnnealingOption
Bases:
BaseSolverOptionOptions for Weighted Simulated Annealing algorithm.
- num_iters
Number of iterations to run the search algorithm.
- time_limit_sec_per_iter
Time limit in seconds per iteration.
- count_per_iter
Number of sweeps per iteration.
- disable_annealing
If True, the zero temperature annealing, called hill-climbing, is executed.
- allow_multihot_equality_move
If True, allow multihot equality move.
- allow_multihot_inequality_move
If True, allow multihot inequality move.
- allow_balance_equality_move
If True, allow multihot balance move.
- allow_balance_inequality_move
If True, allow multihot balance inequality move.
- square_linear_equality_penalty
If True, squared penalty is applied to linear equality constraints.
- square_linear_inequality_penalty
If True, squared penalty is applied to linear inequality constraints.
- square_quadratic_equality_penalty
If True, squared penalty is applied to quadratic equality constraints.
- square_quadratic_inequality_penalty
If True, squared penalty is applied to quadratic inequality constraints.
- normalize_coefficients
If True, coefficients of the objective function and constraints are normalized to its maximum coefficient being 1.
- cancel_token
Token that can be used to cancel the algorithm.
- cancel_token: CancelToken | None = None
- cancel_token()
A context manager for creating a cancel token.
- sample(ommx_instance, *, time_limit_sec=None, initial_ommx_state=None, num_samples=None, seed=0, options=None, num_threads=None, log_display=False, log_interval_sec=1.0)
Sample solutions for a problem using the weighted local search algorithm or the local ILP algorithm.
By default, the algorithm is deterministic through the use of a fixed seed. A different fixed seed can be passed with the seed parameter, and the algorithm can be made non-deterministic by passing seed=None.
Options
time_limit_sec - The total calculation time (second). This solver tries to calculate within the specified time. - Note that time_limit_sec and options are mutually exclusive, and at least one of them must be specified.
initial_ommx_state - If specified, the search starts from the specified solution.
num_samples - Determines the number of samples.
seed - If specified with an integer, determines the seed used to initialize the random number generator used internally. - If None is specified, no fixed seed is used and the algorithm is non-deterministic. - If unspecified, a default fixed seed is used so results are reproducible.
options - If specified, the solver uses the specified algorithm and its options sequentially. Each algorithm uses the found solution that comes from the previous algorithm as the initial solution. - Note that time_limit_sec and options are mutually exclusive, and at least one of them must be specified.
num_threads - The number of threads to use for parallel processing. If not specified, num_threads is set to max(2, half of physical cores). - num_threads must be at least 2. - If options is specified, this parameter must be None.
log_display - If True, displays runtime metrics during sampling. - The logs include process ID, objective value, feasibility status, and elapsed time (in seconds). - If unspecified, defaults to False.
log_interval_sec - The interval in seconds between log outputs when log_display is True. - If unspecified, defaults to 1.0 seconds. - Has no effect when log_display is False.
- rtype:
- Samplesofsolutiontothe problem.
- Parameters:
ommx_instance (ommx.v1.Instance)
time_limit_sec (Optional[float])
initial_ommx_state (Optional[ommx.v1.State])
num_samples (Optional[int])
seed (Optional[int])
options (Optional[Union[jijzept_solver.solver_parameters.JijZeptSolverOption, jijzept_solver.solver_parameters.SolverOptions]])
num_threads (Optional[int])
log_display (bool)
log_interval_sec (float)
- Return type:
ommx.v1.SampleSet
- solve(ommx_instance, *, time_limit_sec=None, initial_ommx_state=None, seed=0, options=None, num_threads=None, log_display=False, log_interval_sec=1.0, terminate_if_optimal=True)
Solve a problem using the weighted local search algorithm or the local ILP algorithm.
By default, the algorithm is deterministic through the use of a fixed seed. A different fixed seed can be passed with the seed parameter, and the algorithm can be made non-deterministic by passing seed=None.
Options
time_limit_sec - The total calculation time (second). This solver tries to calculate within the specified time. - Note that time_limit_sec and options are mutually exclusive, and at least one of them must be specified.
initial_ommx_state - If specified, the search starts from the specified solution.
seed - If specified with an integer, determines the seed used to initialize the random number generator used internally. - If None is specified, no fixed seed is used and the algorithm is non-deterministic. - If unspecified, a default fixed seed is used so results are reproducible.
options - If specified, the solver uses the specified algorithm and its options sequentially. Each algorithm uses the found solution that comes from the previous algorithm as the initial solution. - Note that time_limit_sec and options are mutually exclusive, and at least one of them must be specified.
num_threads - The number of threads to use for parallel processing. If not specified, num_threads is set to max(2, half of physical cores). - num_threads must be at least 2. - If options is specified, this parameter must be None.
log_display - If True, displays runtime metrics during solving. - The logs include process ID, objective value, feasibility status, and elapsed time (in seconds). - If unspecified, defaults to False.
log_interval_sec - The interval in seconds between log outputs when log_display is True. - If unspecified, defaults to 1.0 seconds. - Has no effect when log_display is False.
terminate_if_optimal - If True, terminate remaining processes early when any process reports an optimal solution (default). - Set to False to continue running all processes even after an optimal solution is detected.
- rtype:
- Solutiontothe problem.
Examples
```python import jijzept_solver import jijmodeling as jm
# Define a problem
v = jm.Placeholder(“v”, ndim=1) N = v.len_at(0, latex=”N”) w = jm.Placeholder(“w”, ndim=1) W = jm.Placeholder(“W”) x = jm.BinaryVar(“x”, shape=(N,)) i = jm.Element(“i”, belong_to=(0, N))
problem = jm.Problem(“Knapsack”, sense=jm.ProblemSense.MAXIMIZE) problem += jm.sum(i, v[i] * x[i]) problem += jm.Constraint(“weight”, jm.sum(i, w[i] * x[i]) <= W)
v = [9,28,26,5,26,29,13,20,24,10,23,15,5,27,21,8,7,8,21,13,24,5,5,6,20,16,25,12,28,20,20,6,6,10,29,29,17,12,26,20,22,20,22,23,6,23,28,5,18,17,22,13,24,17,18,11,8,9,23,21,17,7,10,15,7,20,17,29,22,29,15,5,24,7,5,12,11,28,13,6,9,8,8,13,6,15,27,7,15,29,9,26,25,27,6,26,29,26,9,10] w = [21,37,35,19,39,36,32,32,22,20,29,21,12,39,24,8,9,19,22,12,38,21,7,9,24,23,35,27,29,21,18,10,20,21,30,35,36,10,45,36,38,22,34,23,4,29,28,12,37,23,39,32,32,18,28,26,6,10,23,29,20,18,14,26,23,20,36,37,31,27,18,23,30,22,8,26,16,37,26,10,24,12,11,21,4,14,34,12,15,34,24,27,36,31,23,37,45,44,7,20] W = 100 instance_data = {“v”: v, “w”: w, “W”: W}
interpreter = jm.Interpreter(instance_data) ommx_instance = interpreter.eval_problem(problem)
# Solve the problem using the recommended algorithm within 2 seconds ommx_solution = jijzept_solver.solve(ommx_instance, time_limit_sec=2.0) # Solve the problem using WeightedLocalSearch only with the specified options ommx_solution = jijzept_solver.solve(
ommx_instance, options=[jijzept_solver.WeightedLocalSearchOption(num_iters=4, count_per_iter=10)],
) # Solve the problem using multiple algorithms ommx_solution = jijzept_solver.solve(
ommx_instance, options=[
jijzept_solver.WeightedLocalSearchOption(num_iters=4, count_per_iter=10), jijzept_solver.LocalILPOption(time_limit_sec=0.1),
],
)
- Parameters:
ommx_instance (ommx.v1.Instance)
time_limit_sec (Optional[float])
initial_ommx_state (Optional[ommx.v1.State])
seed (Optional[int])
options (Optional[Union[jijzept_solver.solver_parameters.JijZeptSolverOption, jijzept_solver.solver_parameters.SolverOptions]])
num_threads (Optional[int])
log_display (bool)
log_interval_sec (float)
terminate_if_optimal (bool)
- Return type:
ommx.v1.Solution
- suggest_recommended_options(problem_type, objective_degree, constraint_degree, time_limit_sec, num_threads)
Suggest recommended options for solving a problem based on the instance type.
- Returns:
- JijZeptSolverOption
- Return type:
The recommended options for solving the problem.- Parameters:
problem_type (jijzept_solver.core.ProblemType)
objective_degree (int)
constraint_degree (int)
time_limit_sec (float)
num_threads (int)
- SolverOptions