MinizincSolver (solverl v1.1.2)

Minizinc solver API.

Summary

Functions

Get list of solver ids for solvers available to MinizincSolver.

Get list of descriptions for solvers available to MinizincSolver.

Lookup a solver by (possibly partial) id; for results, it could be 'cplex' or 'org.minizinc.mip.cplex'

Solve (asynchronously) with model, data and options.

Solve (synchronously) with model, data and options.

Get solver status

Stop solver process.

Types

server_opts()

@type server_opts() :: GenServer.options()

solver_opt()

@type solver_opt() ::
  {:minizinc_executable, binary()}
  | {:solver, binary()}
  | {:checker, MinizincModel.mzn_model()}
  | {:time_limit, integer()}
  | {:solution_handler, function() | module()}
  | {:solution_timeout, timeout()}
  | {:fzn_timeout, timeout()}
  | {:sync_to, pid() | nil}
  | {:extra_flags, binary()}
  | {:debug_exec, integer()}
  | {:cmd_opts, list()}

solver_opts()

@type solver_opts() :: [solver_opt()]

Functions

get_solverids()

Get list of solver ids for solvers available to MinizincSolver.

get_solvers(minizinc_executable \\ MinizincUtils.default_executable())

Get list of descriptions for solvers available to MinizincSolver.

lookup(solver_id)

Lookup a solver by (possibly partial) id; for results, it could be 'cplex' or 'org.minizinc.mip.cplex'

solve(model, data \\ [], solver_opts \\ [], server_opts \\ [])

@spec solve(
  MinizincModel.mzn_model(),
  MinizincData.mzn_data(),
  solver_opts(),
  server_opts()
) ::
  {:ok, pid()} | {:error, any()}

Solve (asynchronously) with model, data and options.

Example:

# Solve Sudoku puzzle with "mzn/sudoku.mzn" model, "mzn/sudoku.dzn" data,
# and custom solution handler Sudoku.solution_handler/2.
#
MinizincSolver.solve("mzn/sudoku.mzn", "mzn/sudoku.dzn", [solution_handler: &Sudoku.solution_handler/2])

Check out Sudoku module in examples/sudoku.ex for more details on handling solutions.

solve_sync(model, data \\ [], solver_opts \\ [], opts \\ [])

@spec solve_sync(
  model :: MinizincModel.mzn_model(),
  data :: MinizincData.mzn_data(),
  solver_opts :: solver_opts(),
  server_opts :: server_opts()
) :: {:ok, any()} | {:error, any()}

Solve (synchronously) with model, data and options.

Example:

# Solve N-queens puzzle with n = 4.
# Use Gecode solver, solve within 1000 ms.
#
results = MinizincSolver.solve_sync("mzn/nqueens.mzn", %{n: 4}, [solver: "gecode", time_limit: 1000])

Check out NQueens module in examples/nqueens.ex for more details on handling solutions.

solver_status(solver_pid)

Get solver status

stop_solver(pid)

Stop solver process.

update_solution_handler(pid, handler)