GuillotineModels.Utilities
GuillotineModels.Utilities.SavedVarConf
— TypeStores the type and bounds of a variable so they may be restored.
was_bin::Bool
Stores wether the variable was binary.
was_int::Bool
Stores wether the variable was integer (not binary, nor continuous).
was_fixed::Bool
Stores wether the variable was fixed.
fix_value::Float64
If the variable was fixed, to which value they were fixed.
had_lb::Bool
Stores wether the variable had a lower bound.
lb::Float64
If the variable had a lower bound, the value of their lower bound.
had_ub::Bool
Stores wether the variable had an upper bound.
ub::Float64
If the variable had an upper bound, the value of their upper bound.
GuillotineModels.Utilities.SavedVarConf
— MethodSavedVarConf(var :: VariableRef) :: SavedVarConf
Creates a SavedVarConf
struct from the configuration of the given variable. Note that the VariableRef itself is not stored.
GuillotineModels.Utilities.SortedLinkedLW
— TypeGrouping of the length and width piece vectors (in original and sorted order), and their reverse indexes, allowing to, for example, iterate the pieces by length while having O(1)
access to their width.
l::Array{S,1} where S
The pieces length in the original order.
w::Array{S,1} where S
The pieces width in the original order.
sl::Array{S,1} where S
The pieces length sorted by increase-or-same order.
sw::Array{S,1} where S
The pieces width sorted by increase-or-same order.
sli2pii::Array{D,1} where D
Translator from indexes in
sl
to piece index (l
andw
).swi2pii::Array{D,1} where D
Translator from indexes in
sw
to piece index (l
andw
).pii2sli::Array{D,1} where D
Translator from piece indexes (
l
andw
) to index insl
.pii2swi::Array{D,1} where D
Translator from piece indexes (
l
andw
) to index insw
.
GuillotineModels.Utilities.SortedLinkedLW
— MethodSortedLinkedLW(::Type{D}, l :: [S], w :: [S])
Construts a SortedLinkedLW structure using type D
as the type for indexes, and l
and w
as the pieces length and width in the 'original' ordering.
NOTE: l
and w
are not copyed, so mutating them after will silently and completely invalidate the entire structure. They are not copyed for performance reasons and because if the original vectors may be changed then the concept of 'original order' is not really relevant.
GuillotineModels.Utilities.all_constraints
— Methodall_constraints(m)
JuMP only allow to query the number of constraints of some specific type; this method queries all constraint used in the model.
GuillotineModels.Utilities.allsame
— Methodallsame(x) :: Bool
Returns true
if all elements inside x
are the same (uses ==
); false
otherwise.
GuillotineModels.Utilities.bits2idxs
— Methodbits2idxs(bits, idx_type = Int) :: Vector{idx_type}
Given a BitArray
or a Vector{Bool}
return a vector of the indexes storing true values. The returned vector has its elements in increasing order.
GuillotineModels.Utilities.expand
— Methodexpand(d :: [D], a :: [T]) :: [T]
Given two vectors of the same size, create a copy of a
that replaces each element a[i]
by d[i]
copies of it, and then flatten the copy.
expand([0, 1, 2, 3], [4, 5, 6, 7])
[5, 6, 6, 7, 7, 7]
GuillotineModels.Utilities.gather_nonzero
— Methodgather_nonzero(vars, ::Type{D}, threshold = 1e-5, sol_idx = 1)
Given some valid JuMP.Model vars
, return a list of all indexes in vars
in which the variable value rounded to nearest integer is non-zero, and a list of the rounded values themselves.
The elements of the first list (variable indexes) are in increasing order.
The ::Type{D}
is the integer type for the rounded values. The threshold
parameter is used to give a warning if the difference between the extracted value (Float64) and the rounded value is larger than it. The sol_idx
is passed to JuMP.value(...; result = sol_idx)
to allow choosing which solution of the model is to be queried.
GuillotineModels.Utilities.num_all_constraints
— Methodnum_all_constraints(m) :: Int64
JuMP only allow to query the number of constraints of some specific type; this method queries all constraint types used in the model and then sums the number of constraints of each type.
GuillotineModels.Utilities.optimize_within_time_limit!
— Functionoptimize_within_time_limit!(model, start, limit[, now = time()])
optimize_within_time_limit!(f, model, start, limit[, now = time()])
Throws a TimeoutError
if the time limit has been violated before calling the JuMP.optimize!
, change the solver to respect a time limit of the remaining time, throws a TimeoutError
if the solver termination status is MOI.TIME_LIMIT
OR calling time()
shows a time limit violation.
If the method with the f
parameter is called, and a timeout happens, then f
is called with four parameters: model
, start
, limit
, and the value returned by a call to time()
just after the model stopping. If f
returns true
then the exception is not thrown, any other return value is ignored and the exception is thrown.
GuillotineModels.Utilities.optimize_within_time_limit!
— Methodoptimize_within_time_limit!(model, secs)
Set the solver time limit to secs
seconds and call optimize!
. Change the solver time limit to the old value before returning.
GuillotineModels.Utilities.relax!
— Methodrelax!(var) :: SavedVarConf
relax!(vars) :: Vector{SavedVarConf}
The var
is made continuous. If the variable was binary, and had a lower (upper) bound below zero (above one) it is replaced by zero (one).
GuillotineModels.Utilities.restore!
— Methodrestore!(var :: VariableRef, c :: SavedVarConf) :: Nothing
restore!(vars :: Vector{...}, cs :: Vector{...}) :: Nothing
If var
type and/or bounds are different than the ones specified in c
, then change var
type and/or bounds to adhere to c
.
GuillotineModels.Utilities.shift_idxs!
— Methodshift_idxs!(old_idxs, kept_bits)
Given a sorted list of indexes (old_idxs
) from a vector A
and a bitarray-like (kept_bits
) marking (with true
) which positions of A
were not deleted since last shift_idxs!
, it changes the old_idxs
to point to the correct positions and return it.
The code throws if the old_idxs
are not positions marked as kept by kept_bits
.
This code is efficient if old_idxs
is a "small" subset of A
indexes.
The code assumes A
had the usual 1:length(A)
indexes.
The code does not allocate from the heap.
GuillotineModels.Utilities.switched_dims
— Methodswitched_dims(sllw :: SortedLinkedLW{D, S}) where {D, S}
Returns a copy of sllw
as it was created switching L
/W
and l
/w
.
DANGER: Both the original and the copy share the same arrays, so any modification in one will change the other.
GuillotineModels.Utilities.throw_if_unrecognized
— Methodthrow_if_unrecognized(name, value, list)
If value
is NOT in list
, then throw an argument error explaining that because value
is not in list
so it is a valid value for parameter name
.
GuillotineModels.Utilities.unify!
— Methodunify!(::Type{QT_TYPE}, a)
Apply sort!
and unique!
to array a
and then returns a Vector{QT_TYPE}
with the corresponding quantity of value in a
before compacting it.
> a = [40, 10, 20, 10, 20, 30, 20];
> unify!(Int16, a)
4-element Array{Int16,1}:
2
3
1
1
> a
4-element Array{Int64,1}:
10
20
30
40