ConstraintModels.jl
Documentation for ConstraintModels.jl
.
ConstraintModels.SudokuInstance Type
mutable struct SudokuInstance{T <: Integer} <: AbstractMatrix{T}
A struct
for SudokuInstances, which is a subtype of AbstractMatrix
.
SudokuInstance(A::AbstractMatrix{T})
SudokuInstance(::Type{T}, n::Int) # fill in blank sudoku of type T
SudokuInstance(n::Int) # fill in blank sudoku of type Int
SudokuInstance(::Type{T}) # fill in "standard" 9×9 sudoku of type T
SudokuInstance() # fill in "standard" 9×9 sudoku of type Int
SudokuInstance(n::Int, P::Pair{Tuple{Int, Int}, T}...) where {T <: Integer} # construct a sudoku given pairs of coordinates and values
SudokuInstance(P::Pair{Tuple{Int, Int}, T}...) # again, default to 9×9 sudoku, constructing given pairs
Constructor functions for the SudokuInstance
struct
.
ConstraintModels.SudokuInstance Method
SudokuInstance(X::Dictionary)
Construct a SudokuInstance
with the values X
of a solver as input.
Base.Multimedia.display Method
display(io::IO, S::SudokuInstance)
display(S::SudokuInstance) # default to stdout
Displays an
Base.Multimedia.display Method
Base.display(X, Val(:sudoku))
Extends Base.display
to a sudoku configuration.
Base.Multimedia.display Method
Base.display(S::SudokuInstance)
Extends Base.display
to SudokuInstance
.
Base.Multimedia.display Method
Base.display(X::Dictionary)
Extends Base.display
to a sudoku configuration.
ConstraintModels._format_line_segment Method
_format_line_segment(r, col_pos, M)
Format line segment of a sudoku grid.
ConstraintModels._format_val Method
_format_val(a)
Format an integer a
into a string for SudokuInstance.
ConstraintModels.chemical_equilibrium Method
chemical_equilibrium(atoms_compounds, elements_weights, standard_free_energy; modeler = :JuMP)
Warning
Even the structure to model problems with continuous domains is available, the default solver is not yet equiped to solve such problems efficiently.
From Wikipedia
In a chemical reaction, chemical equilibrium is the state in which both the reactants and products are present in concentrations which have no further tendency to change with time, so that there is no observable change in the properties of the system. This state results when the forward reaction proceeds at the same rate as the reverse reaction. The reaction rates of the forward and backward reactions are generally not zero, but they are equal. Thus, there are no net changes in the concentrations of the reactants and products. Such a state is known as dynamic equilibrium.
ConstraintModels.golomb Function
golomb(n, L=n²)
Model the Golomb problem of n
marks on the ruler 0:L
. The modeler
argument accepts :raw, and :JuMP (default), which refer respectively to the solver internal model, the MathOptInterface model, and the JuMP model.
ConstraintModels.magic_square Method
magic_square(n; modeler = :JuMP)
Create a model for the magic square problem of order n
. The modeler
argument accepts :JuMP (default), which refer to the solver the JuMP model.
ConstraintModels.mincut Method
mincut(graph; source, sink, interdiction =0, modeler = :JuMP)
Compute the minimum cut of a graph.
Arguments:
graph
: Any matrix <: AbstractMatrix that describes the capacities of the graphsource
: Id of the source node; must be setsink
: Id of the sink node; must be setinterdiction
: indicates the number of forbidden linksmodeler
: Default to:JuMP
.
ConstraintModels.n_queens Method
n_queens(n; modeler = :JuMP)
Create a model for the n-queens problem with n
queens. The modeler
argument accepts :JuMP (default), which refer to the JuMP model.
ConstraintModels.qap Method
qap(n, weigths, distances; modeler = :JuMP)
Modelize an instance of the Quadractic Assignment Problem with
n
: number of both facilities and locationsweights
:Matrix
of the weights of each pair of facilitiesdistances
:Matrix
of distances between locationsmodeler
: Default to:JuMP
. No other modeler available for now.
From Wikipedia
There are a set of n
facilities and a set of n
locations. For each pair of locations, a distance is specified and for each pair of facilities a weight
or flow is specified (e.g., the amount of supplies transported between the two facilities). The problem is to assign all facilities to different locations with the goal of minimizing the sum of the distances
multiplied by the corresponding flows.
ConstraintModels.sudoku Method
sudoku(n; start= Dictionary{Int, Int}(), modeler = :JuMP)
Create a model for the sudoku problem of domain 1:n²
with optional starting values. The modeler
argument accepts :raw, :MOI, and :JuMP (default), which refer respectively to the solver internal model, the MathOptInterface model, and the JuMP model.
# Construct a JuMP model `m` and its associated matrix `grid` for sudoku 9×9
m, grid = sudoku(3)
# Same with a starting instance
instance = [
9 3 0 0 0 0 0 4 0
0 0 0 0 4 2 0 9 0
8 0 0 1 9 6 7 0 0
0 0 0 4 7 0 0 0 0
0 2 0 0 0 0 0 6 0
0 0 0 0 2 3 0 0 0
0 0 8 5 3 1 0 0 2
0 9 0 2 8 0 0 0 0
0 7 0 0 0 0 0 5 3
]
m, grid = sudoku(3, start = instance)
# Run the solver
optimize!(m)
# Retrieve and display the values
solution = value.(grid)
display(solution, Val(:sudoku))