ConstraintModels
Documentation for ConstraintModels.
ConstraintModels.SudokuInstance
ConstraintModels.SudokuInstance
Base.Multimedia.display
Base.Multimedia.display
Base.Multimedia.display
Base.Multimedia.display
Base.size
ConstraintModels._format_line
ConstraintModels._format_line_segment
ConstraintModels._format_val
ConstraintModels._get_sep_line
ConstraintModels.golomb
ConstraintModels.magic_square
ConstraintModels.mincut
ConstraintModels.n_queens
ConstraintModels.scheduling
ConstraintModels.sudoku
ConstraintModels.SudokuInstance
— Typemutable 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
— MethodSudokuInstance(X::Dictionary)
Construct a SudokuInstance
with the values X
of a solver as input.
Base.Multimedia.display
— Methoddisplay(io::IO, S::SudokuInstance)
display(S::SudokuInstance) # default to stdout
Displays an $n\times n$ SudokuInstance.
Base.Multimedia.display
— MethodBase.display(X, Val(:sudoku))
Extends Base.display
to a sudoku configuration.
Base.Multimedia.display
— MethodBase.display(S::SudokuInstance)
Extends Base.display
to SudokuInstance
.
Base.Multimedia.display
— MethodBase.display(X::Dictionary)
Extends Base.display
to a sudoku configuration.
Base.size
— MethodBase.size(S::SudokuInstance)
Extends Base.size
for SudokuInstance
.
ConstraintModels._format_line
— Method_format_line(r, M)
Format line of a sudoku grid.
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._get_sep_line
— Method_get_sep_line(s, pos_row, M)
Return a line separator.
ConstraintModels.golomb
— Functiongolomb(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
— Methodmagic_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
— Methodmincut(graph::AbstractMatrix{T}; source::Int, sink::Int, interdiction::Int = 0) where T <: Number
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 links
ConstraintModels.n_queens
— Methodn_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.scheduling
— Methodscheduling(processing_time, due_date; 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.sudoku
— Methodsudoku(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))