GuillotineModels.Utilities

GuillotineModels.Utilities.SavedVarConfType

Stores 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.

source
GuillotineModels.Utilities.SavedVarConfMethod
SavedVarConf(var :: VariableRef) :: SavedVarConf

Creates a SavedVarConf struct from the configuration of the given variable. Note that the VariableRef itself is not stored.

source
GuillotineModels.Utilities.SortedLinkedLWType

Grouping 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 and w).

  • swi2pii::Array{D,1} where D

    Translator from indexes in sw to piece index (l and w).

  • pii2sli::Array{D,1} where D

    Translator from piece indexes (l and w) to index in sl.

  • pii2swi::Array{D,1} where D

    Translator from piece indexes (l and w) to index in sw.

source
GuillotineModels.Utilities.SortedLinkedLWMethod
SortedLinkedLW(::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.

source
GuillotineModels.Utilities.bits2idxsMethod
bits2idxs(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.

source
GuillotineModels.Utilities.expandMethod
expand(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]
source
GuillotineModels.Utilities.gather_nonzeroMethod
gather_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.

source
GuillotineModels.Utilities.num_all_constraintsMethod
num_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.

source
GuillotineModels.Utilities.optimize_within_time_limit!Function
optimize_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.

source
GuillotineModels.Utilities.relax!Method
relax!(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).

source
GuillotineModels.Utilities.restore!Method
restore!(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.

source
GuillotineModels.Utilities.shift_idxs!Method
shift_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.

source
GuillotineModels.Utilities.switched_dimsMethod
switched_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.

source
GuillotineModels.Utilities.unify!Method
unify!(::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
source