Skip to content

Minor revisions #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,43 @@

# Constraints.jl

A back-end package for JuliaConstraints front packages, such as `LocalSearchSolvers.jl`.
A back-end package for JuliaConstraints front packages, such as `LocalSearchSolvers.jl`.

It provides the following features:
- A dictionary to store usual constraint: `usual_constraint`, which contains the following entries
- `:all_different`
- `:dist_different`
- `:eq`, `:all_equal`, `:all_equal_param`
- `:ordered`
- `:always_true` (mainly for testing default `Constraint()` constructor)
- A dictionary to store usual constraint: `usual_constraint`, which contains the following entries (in alphabetical order):
- :`all_different`
- :`all_equal`
- :`at_least`
- :`at_most`
- :`cardinality`
- :`cardinality_closed`
- :`cardinality_open`
- :`channel`
- :`circuit`
- :`conflicts`
- :`count`
- :`cumulative`
- :`decreasing`
- :`dist_different`
- :`element`
- :`exactly`
- :`extension`
- :`increasing`
- :`instantiation`
- :`maximum`
- :`mdd`
- :`minimum`
- :`no_overlap`
- :`no_overlap_no_zero`
- :`no_overlap_with_zero`
- :`nvalues`
- :`ordered`
- :`regular`
- :`strictly_decreasing`
- :`strictly_increasing`
- :`sum`
- :`supports`

- For each constraint `c`, the following properties
- arguments length
- concept (predicate the variables compliance with `c`)
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/all_different.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!SECTION - all_different

const description_all_different = """
Global constraint ensuring that all the values of `x` are all different.
Global constraint ensuring that all the values of `x` are all different.
"""

"""
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/all_equal.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!SECTION - all_equal

const description_all_equal = """
Global constraint ensuring that all the values of `x` are all equal.
Global constraint ensuring that all the values of `x` are all equal.
"""

concept_all_equal(x, val) = all(y -> y == val, x)
Expand Down
4 changes: 2 additions & 2 deletions src/constraints/channel.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const description = """
const description_channel = """
The channel constraint establishes a bijective correspondence between two sets of variables. This means that each value in the first set of variables corresponds to a unique value in the second set, and vice versa.
"""

Expand All @@ -11,7 +11,7 @@ Return `true` if the channel constraint is satisfied, `false` otherwise. The cha
- `list::Union{AbstractVector, Tuple}`: list of values to check.

## Variants
- `:channel`: $description
- `:channel`: $description_channel
```julia
concept(:channel, x; dim=1, id=nothing)
concept(:channel)(x; dim=1, id=nothing)
Expand Down
5 changes: 2 additions & 3 deletions src/constraints/mdd.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!SECTION - Multi-valued Decision Diagram

const description_mdd = """
Multi-valued Decision Diagram (MDD) constraint.

The MDD constraint is a constraint that can be used to model a wide range of problems. It is a directed graph where each node is labeled with a value and each edge is labeled with a value. The constraint is satisfied if there is a path from the first node to the last node such that the sequence of edge labels is a valid sequence of the value labels.
Multi-valued Decision Diagram (MDD) constraint.
The MDD constraint is a constraint that can be used to model a wide range of problems. It is a directed graph where each node is labeled with a value and each edge is labeled with a value. The constraint is satisfied if there is a path from the first node to the last node such that the sequence of edge labels is a valid sequence of the value labels.
"""

"""
Expand Down
14 changes: 7 additions & 7 deletions src/constraints/ordered.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const description_ordered = """
Global constraint ensuring that all the values of `x` are in an increasing order.
Global constraint ensuring that all the values of `x` are in an increasing order.
"""

const description_increasing = """
Global constraint ensuring that all the values of `x` are in an increasing order.
Global constraint ensuring that all the values of `x` are in an increasing order.
"""

const description_decreasing = """
Global constraint ensuring that all the values of `x` are in a decreasing order.
Global constraint ensuring that all the values of `x` are in a decreasing order.
"""

const description_sctrictly_increasing = """
Global constraint ensuring that all the values of `x` are in a strictly increasing order.
const description_strictly_increasing = """
Global constraint ensuring that all the values of `x` are in a strictly increasing order.
"""

const description_strictly_decreasing = """
Global constraint ensuring that all the values of `x` are in a strictly decreasing order.
Global constraint ensuring that all the values of `x` are in a strictly decreasing order.
"""

"""
Expand Down Expand Up @@ -44,7 +44,7 @@ concept(:increasing)(x; op=≤, pair_vars=nothing)
concept(:decreasing, x; op=≥, pair_vars=nothing)
concept(:decreasing)(x; op=≥, pair_vars=nothing)
```
- `:strictly_increasing`: $description_sctrictly_increasing
- `:strictly_increasing`: $description_strictly_increasing
```julia
concept(:strictly_increasing, x; op=<, pair_vars=nothing)
concept(:strictly_increasing)(x; op=<, pair_vars=nothing)
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/regular.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const description_regular = """
Ensures that a sequence `x` (interpreted as a word) is accepted by the regular language represented by a given automaton. This constraint verifies the compliance of `x` with the language rules encoded within the `automaton` parameter, which must be an instance of `<:AbstractAutomaton`.
Ensures that a sequence `x` (interpreted as a word) is accepted by the regular language represented by a given automaton. This constraint verifies the compliance of `x` with the language rules encoded within the `automaton` parameter, which must be an instance of `<:AbstractAutomaton`.
"""

"""
Expand Down
4 changes: 3 additions & 1 deletion src/usual_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Adding a new constraint is as simple as defining a new function with the same na
@usual concept_all_different(x; vals=nothing) = xcsp_all_different(list=x, except=vals)
```
"""
const USUAL_CONSTRAINTS = Dict{Symbol, Constraint}(:always_true => Constraint())
const USUAL_CONSTRAINTS = Dict{Symbol, Constraint}()

"""
describe(constraints::Dict{Symbol,Constraint}=USUAL_CONSTRAINTS; width=150)
Expand Down Expand Up @@ -41,6 +41,8 @@ function describe(constraints::Dict{Symbol, Constraint} = USUAL_CONSTRAINTS; wid
)
end

describe(s::Symbol) = USUAL_CONSTRAINTS[s].description

"""
extract_parameters(s::Symbol, constraints_dict=USUAL_CONSTRAINTS; parameters=ConstraintCommons.USUAL_CONSTRAINT_PARAMETERS)

Expand Down
Loading