Skip to content

Public API

# ConstraintCommons.AutomatonType.
julia
Automaton{S, T, F <: Union{S, Vector{S}, Set{S}}} <: AbstractAutomaton

A minimal implementation of a deterministic automaton structure.

source


# ConstraintCommons.MDDType.
julia
MDD{S,T} <: AbstractMultivaluedDecisionDiagram

A minimal implementation of a multivalued decision diagram structure.

source


# ConstraintCommons.acceptMethod.
julia
accept(a::Union{Automaton, MDD}, w)

Return true if a accepts the word w and false otherwise.

source


# ConstraintCommons.consinMethod.
julia
consin(::Any, ::Nothing)

Extends Base.in (or ) when the set is nothing. Returns false.

source


# ConstraintCommons.consisemptyMethod.
julia
consisempty(::Nothing)

Extends Base.isempty when the set is nothing. Returns true.

source


# ConstraintCommons.extract_parametersMethod.
julia
extract_parameters(m::Union{Method, Function}; parameters)

Extracts the intersection between the kargs of m and parameters (defaults to USUAL_CONSTRAINT_PARAMETERS).

source


# ConstraintCommons.incsert!Function.
julia
incsert!(d::Union{AbstractDict, AbstractDictionary}, ind, val = 1)

Increase or insert a counter in a dictionary-based collection. The counter insertion defaults to val = 1.

source


# ConstraintCommons.oversampleMethod.
julia
oversample(X, f)

Oversample elements of X until the boolean function f has as many true and false configurations.

source


# ConstraintCommons.symconFunction.
julia
symcon(s1::Symbol, s2::Symbol, connector::AbstractString="_")

Extends * to Symbols multiplication by connecting the symbols by an _.

source


# ConstraintCommons.δ_extremaMethod.
julia
δ_extrema(X...)

Compute both the difference between the maximum and the minimum of over all the collections of X.

source


# ConstraintDomains.AbstractDomainType.
julia
AbstractDomain

An abstract super type for any domain type. A domain type D <: AbstractDomain must implement the following methods to properly interface AbstractDomain.

  • Base.∈(val, ::D)

  • Base.rand(::D)

  • Base.length(::D) that is the number of elements in a discrete domain, and the distance between bounds or similar for a continuous domain

Additionally, if the domain is used in a dynamic context, it can extend

  • add!(::D, args)

  • delete!(::D, args)

where args depends on D's structure

source


# ConstraintDomains.ContinuousDomainType.
julia
ContinuousDomain{T <: Real} <: AbstractDomain

An abstract supertype for all continuous domains.

source


# ConstraintDomains.DiscreteDomainType.
julia
DiscreteDomain{T <: Number} <: AbstractDomain

An abstract supertype for discrete domains (set, range).

source


# ConstraintDomains.ExploreSettingsMethod.
julia
ExploreSettings(domains; 
                complete_search_limit = 10^6, 
                max_samplings = sum(domain_size, domains), 
                search = :flexible, 
                solutions_limit = floor(Int, sqrt(max_samplings)))

Create an ExploreSettings object to configure the exploration of a search space composed of a collection of domains.

Arguments

  • domains: A collection of domains to be explored.

  • complete_search_limit: An integer specifying the maximum limit for complete search iterations. Default is 10^6.

  • max_samplings: An integer specifying the maximum number of samplings. Default is the sum of domain sizes.

  • search: A symbol indicating the type of search to perform. Default is :flexible.

  • solutions_limit: An integer specifying the limit on the number of solutions. Default is the floor of the square root of max_samplings.

Returns

  • ExploreSettings object with the specified settings.

source


# ConstraintDomains.RangeDomainType.
julia
RangeDomain

A discrete domain defined by a range <: AbstractRange{Real}. As ranges are immutable in Julia, changes in RangeDomain must use set_domain!.

source


# ConstraintDomains.SetDomainType.
julia
SetDomain{T <: Number} <: DiscreteDomain{T}

Domain that stores discrete values as a set of (unordered) points.

source


# Base.delete!Method.
julia
Base.delete!(d::SetDomain, value)(d::SetDomain, value)

Delete value from the list of points in d.

source


# ConstraintDomains.add!Method.
julia
add!(d::SetDomain, value)

Add value to the list of points in d.

source


# ConstraintDomains.domainMethod.
julia
domain(values)
domain(range::R) where {T <: Real, R <: AbstractRange{T}}

Construct either a SetDomain or a RangeDomain.

julia
d1 = domain(1:5)
d2 = domain([53.69, 89.2, 0.12])
d3 = domain([2//3, 89//123])
d4 = domain(4.3)
d5 = domain(1,42,86.9)

source


# ConstraintDomains.domainMethod.
julia
domain()

Construct an EmptyDomain.

source


# ConstraintDomains.domainMethod.
julia
domain(a::Tuple{T, Bool}, b::Tuple{T, Bool}) where {T <: Real}
domain(intervals::Vector{Tuple{Tuple{T, Bool},Tuple{T, Bool}}}) where {T <: Real}

Construct a domain of continuous interval(s).

source


# ConstraintDomains.domain_sizeMethod.
julia
domain_size(itv::Intervals)

Return the difference between the highest and lowest values in itv.

source


# ConstraintDomains.domain_sizeMethod.
julia
domain_size(d <: AbstractDomain)

Fallback method for domain_size(d) that return length(d).

source


# ConstraintDomains.domain_sizeMethod.
julia
domain_size(d::D) where D <: DiscreteDomain

Return the maximum distance between two points in d.

source


# ConstraintDomains.exploreMethod.
julia
explore(domains, concept; settings = ExploreSettings(domains), parameters...)

Search (a part of) a search space and return a pair of vectors of configurations: (solutions, non_solutions). The exploration behavior is determined based on the settings.

Arguments

  • domains: A collection of domains to be explored.

  • concept: The concept representing the constraint to be targeted.

  • settings: An optional ExploreSettings object to configure the exploration. Default is ExploreSettings(domains).

  • parameters...: Additional parameters for the concept.

Returns

  • A tuple of sets: (solutions, non_solutions).

source


# ConstraintDomains.generate_parametersMethod.
julia
generate_parameters(d<:AbstractDomain, param)

Generates random parameters based on the domain d and the kind of parameters param.

source


# ConstraintDomains.get_domainMethod.
julia
get_domain(::AbstractDomain)

Access the internal structure of any domain type.

source


# ConstraintDomains.intersect_domainsMethod.
julia
intersect_domains(d₁, d₂)

Compute the intersections of two domains.

source


# ConstraintDomains.merge_domainsMethod.
julia
merge_domains(d₁::AbstractDomain, d₂::AbstractDomain)

Merge two domains of same nature (discrete/contiuous).

source


# ConstraintDomains.to_domainsMethod.
julia
to_domains(args...)

Convert various arguments into valid domains format.

source


# Constraints.USUAL_CONSTRAINTSConstant.
julia
USUAL_CONSTRAINTS::Dict

Dictionary that contains all the usual constraints defined in Constraint.jl. It is based on XCSP3-core specifications available at https://arxiv.org/abs/2009.00514

Adding a new constraint is as simple as defining a new function with the same name as the constraint and using the @usual macro to define it. The macro will take care of adding the new constraint to the USUAL_CONSTRAINTS dictionary.

Example

julia
@usual concept_all_different(x; vals=nothing) = xcsp_all_different(list=x, except=vals)

source


# Constraints.USUAL_SYMMETRIESConstant.
julia
USUAL_SYMMETRIES

A Dictionary that contains the function to apply for each symmetry to avoid searching a whole space.

source


# Constraints.ConstraintType.
julia
Constraint

Parametric structure with the following fields.

  • concept: a Boolean function that, given an assignment x, outputs true if x satisfies the constraint, and false otherwise.

  • error: a positive function that works as preferences over invalid assignments. Return 0.0 if the constraint is satisfied, and a strictly positive real otherwise.

source


# ConstraintCommons.extract_parametersFunction.
julia
extract_parameters(s::Symbol, constraints_dict=USUAL_CONSTRAINTS; parameters=ConstraintCommons.USUAL_CONSTRAINT_PARAMETERS)

Return the parameters of the constraint s in constraints_dict.

Arguments

  • s::Symbol: the constraint name.

  • constraints_dict::Dict{Symbol,Constraint}: dictionary of constraints. Default is USUAL_CONSTRAINTS.

  • parameters::Vector{Symbol}: vector of parameters. Default is ConstraintCommons.USUAL_CONSTRAINT_PARAMETERS.

Example

julia
extract_parameters(:all_different)

source


# Constraints.argsMethod.
julia
args(c::Constraint)

Return the expected length restriction of the arguments in a constraint c. The value nothing indicates that any strictly positive number of value is accepted.

source


# Constraints.conceptMethod.
julia
concept(c::Constraint)

Return the concept (function) of constraint c. concept(c::Constraint, x...; param = nothing) Apply the concept of c to values x and optionally param.

source


# Constraints.conceptMethod.
julia
concept(s::Symbol, args...; kargs...)

Return the concept of the constraint s applied to args and kargs. This is a shortcut for concept(USUAL_CONSTRAINTS[s])(args...; kargs...).

Arguments

  • s::Symbol: the constraint name.

  • args...: the arguments to apply the concept to.

  • kargs...: the keyword arguments to apply the concept to.

Example

julia
concept(:all_different, [1, 2, 3])

source


# Constraints.constraints_descriptionsFunction.
julia
constraints_descriptions(C=USUAL_CONSTRAINTS)

Return a pretty table with the descriptions of the constraints in C.

Arguments

  • C::Dict{Symbol,Constraint}: dictionary of constraints. Default is USUAL_CONSTRAINTS.

Example

julia
constraints_descriptions()

source


# Constraints.constraints_parametersFunction.
julia
constraints_parameters(C=USUAL_CONSTRAINTS)

Return a pretty table with the parameters of the constraints in C.

Arguments

  • C::Dict{Symbol,Constraint}: dictionary of constraints. Default is USUAL_CONSTRAINTS.

Example

julia
constraints_parameters()

source


# Constraints.describeFunction.
julia
describe(constraints::Dict{Symbol,Constraint}=USUAL_CONSTRAINTS; width=150)

Return a pretty table with the description of the constraints in constraints.

Arguments

  • constraints::Dict{Symbol,Constraint}: dictionary of constraints to describe. Default is USUAL_CONSTRAINTS.

  • width::Int: width of the table.

Example

julia
describe()

source


# Constraints.error_fMethod.
julia
error_f(c::Constraint)

Return the error function of constraint c. error_f(c::Constraint, x; param = nothing) Apply the error function of c to values x and optionally param.

source


# Constraints.params_lengthMethod.
julia
params_length(c::Constraint)

Return the expected length restriction of the arguments in a constraint c. The value nothing indicates that any strictly positive number of parameters is accepted.

source


# Constraints.symmetriesMethod.
julia
symmetries(c::Constraint)

Return the list of symmetries of c.

source


# CompositionalNetworks.CompositionMethod.
julia
Composition(f::F, symbols) where {F<:Function}

Construct a Composition.

source


# CompositionalNetworks.CompositionType.
julia
struct Composition{F<:Function}

Store the all the information of a composition learned by an ICN.

source


# CompositionalNetworks.ICNType.
julia
ICN(; nvars, dom_size, param, transformation, arithmetic, aggregation, comparison)

Construct an Interpretable Compositional Network, with the following arguments:

  • nvars: number of variable in the constraint

  • dom_size: maximum domain size of any variable in the constraint

  • param: optional parameter (default to nothing)

  • transformation: a transformation layer (optional)

  • arithmetic: a arithmetic layer (optional)

  • aggregation: a aggregation layer (optional)

  • comparison: a comparison layer (optional)

source


# CompositionalNetworks.aggregation_layerMethod.
julia
aggregation_layer()

Generate the layer of aggregations of the ICN. The operations are mutually exclusive, that is only one will be selected.

source


# CompositionalNetworks.arithmetic_layerMethod.
julia
arithmetic_layer()

Generate the layer of arithmetic operations of the ICN. The operations are mutually exclusive, that is only one will be selected.

source


# CompositionalNetworks.codeFunction.
julia
code(c::Composition, lang=:maths; name="composition")

Access the code of a composition c in a given language lang. The name of the generated method is optional.

source


# CompositionalNetworks.comparison_layerFunction.
julia
comparison_layer(param = false)

Generate the layer of transformations functions of the ICN. Iff param value is set, also includes all the parametric comparison with that value. The operations are mutually exclusive, that is only one will be selected.

source


# CompositionalNetworks.composeFunction.
julia
compose(icn, weights=nothing)

Return a function composed by some of the operations of a given ICN. Can be applied to any vector of variables. If weights are given, will assign to icn.

source


# CompositionalNetworks.compose_to_file!Method.
julia
compose_to_file!(concept, name, path; domains, param = nothing, language = :Julia, search = :complete, global_iter = 10, local_iter = 100, metric = hamming, popSize = 200)

Explore, learn and compose a function and write it to a file.

Arguments:

  • concept: the concept to learn

  • name: the name to give to the constraint

  • path: path of the output file

Keywords arguments:

  • domains: domains that defines the search space

  • param: an optional parameter of the constraint

  • language: the language to export to, default to :julia

  • search: either :partial or :complete search

  • global_iter: number of learning iteration

  • local_iter: number of generation in the genetic algorithm

  • metric: the metric to measure the distance between a configuration and known solutions

  • popSize: size of the population in the genetic algorithm

source


# CompositionalNetworks.compositionMethod.
julia
composition(c::Composition)

Access the actual method of an ICN composition c.

source


# CompositionalNetworks.composition_to_file!Function.
julia
composition_to_file!(c::Composition, path, name, language=:Julia)

Write the composition code in a given language into a file at path.

source


# CompositionalNetworks.explore_learn_composeMethod.
julia
explore_learn_compose(concept; domains, param = nothing, search = :complete, global_iter = 10, local_iter = 100, metric = hamming, popSize = 200, action = :composition)

Explore a search space, learn a composition from an ICN, and compose an error function.

Arguments:

  • concept: the concept of the targeted constraint

  • domains: domains of the variables that define the training space

  • param: an optional parameter of the constraint

  • search: either flexible,:partial or :complete search. Flexible search will use search_limit and solutions_limit to determine if the search space needs to be partially or completely explored

  • global_iter: number of learning iteration

  • local_iter: number of generation in the genetic algorithm

  • metric: the metric to measure the distance between a configuration and known solutions

  • popSize: size of the population in the genetic algorithm

  • action: either :symbols to have a description of the composition or :composition to have the composed function itself

source


# CompositionalNetworks.hammingMethod.
julia
hamming(x, X)

Compute the hamming distance of x over a collection of solutions X, i.e. the minimal number of variables to switch in xto reach a solution.

source


# CompositionalNetworks.lazyMethod.
julia
lazy(funcs::Function...)

Generate methods extended to a vector instead of one of its components. A function f should have the following signature: f(i::Int, x::V).

source


# CompositionalNetworks.lazy_paramMethod.
julia
lazy_param(funcs::Function...)

Generate methods extended to a vector instead of one of its components. A function f should have the following signature: f(i::Int, x::V; param).

source


# CompositionalNetworks.learn_composeMethod.
julia
learn_compose(;
    nvars, dom_size, param=nothing, icn=ICN(nvars, dom_size, param),
    X, X_sols, global_iter=100, local_iter=100, metric=hamming, popSize=200
)

Create an ICN, optimize it, and return its composition.

source


# CompositionalNetworks.manhattanMethod.
julia
manhattan(x, X)

source


# CompositionalNetworks.minkowskiMethod.
julia
minkowski(x, X, p)

source


# CompositionalNetworks.nbitsMethod.
julia
nbits(icn)

Return the expected number of bits of a viable weight of an ICN.

source


# CompositionalNetworks.regularizationMethod.
julia
regularization(icn)

Return the regularization value of an ICN weights, which is proportional to the normalized number of operations selected in the icn layers.

source


# CompositionalNetworks.show_layersMethod.
julia
show_layers(icn)

Return a formatted string with each layers in the icn.

source


# CompositionalNetworks.symbolsMethod.
julia
symbols(c::Composition)

Output the composition as a layered collection of Symbols.

source


# CompositionalNetworks.transformation_layerFunction.
julia
transformation_layer(param = Vector{Symbol}())

Generate the layer of transformations functions of the ICN. Iff param value is non empty, also includes all the related parametric transformations.

source


# CompositionalNetworks.weights!Method.
julia
weights!(icn, weights)

Set the weights of an ICN with a BitVector.

source


# CompositionalNetworks.weightsMethod.
julia
weights(icn)

Access the current set of weights of an ICN.

source


# CompositionalNetworks.weights_biasMethod.
julia
weights_bias(x)

A metric that bias x towards operations with a lower bit. Do not affect the main metric.

source


# QUBOConstraints.QUBO_linear_sumMethod.
julia
QUBO_linear_sum(n, σ)

One valid QUBO matrix given n variables and parameter σ for the linear sum constraint.

source


# QUBOConstraints.binarizeMethod.
julia
binarize(x[, domain]; binarization = :one_hot)

Binarize x following the binarization encoding. If x is a vector (instead of a number per say), domain is optional.

source


# QUBOConstraints.debinarizeMethod.
julia
debinarize(x[, domain]; binarization = :one_hot)

Transform a binary vector into a number or a set of number. If domain is not given, it will compute a default value based on binarization and x.

source


# QUBOConstraints.is_validFunction.
julia
is_valid(x, encoding::Symbol = :none)

Check if x has a valid format for encoding.

For instance, if encoding == :one_hot, at most one bit of x can be set to 1.

source


# QUBOConstraints.trainMethod.
julia
train(args...)

Default train method for any AbstractOptimizer.

source