jijzept_solver.solver

Module Contents

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:

- Samples of solution to the problem.

Parameters:
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:

- Solution to the 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:
Return type:

ommx.v1.Solution