Skip to content

Commit b617c80

Browse files
authored
Merge pull request #53 from JuliaConstraints/revisions
minor revisions
2 parents f1b5a32 + bc2f3d9 commit b617c80

File tree

3 files changed

+89
-24
lines changed

3 files changed

+89
-24
lines changed

docs/src/constraints/constraint_commons.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ at_end
6060

6161
## Extensions
6262

63-
We extended some operations for `Nothing` and `Symbol`.
63+
We extend some operations for `Nothing` and `Symbol`.
6464

6565
```@docs; canonical=false
6666
symcon
@@ -89,7 +89,7 @@ consisempty
8989

9090
## Sampling
9191

92-
During our constraint learning processes, we use sampling to efficiently make partial exploration of search spaces. Follows some sampling utilities.
92+
During our constraint learning processes, we use sampling to efficiently make partial exploration of search spaces. The following are some examples of sampling utilities.
9393

9494
```@docs; canonical=false
9595
oversample
@@ -112,18 +112,18 @@ We need to compute the difference between extrema of various kind of collections
112112
δ_extrema
113113
```
114114

115+
### Performances
116+
115117
```@raw html
116118
<div style="display: flex; justify-content: space-between;">
117119
<img src="https://github.com/JuliaConstraints/Benchmarks/blob/main/ConstraintCommons/visuals/bench_evolution_extrema.png?raw=true" alt="Bench Evolution" style="width:48%;"/>
118120
<img src="https://github.com/JuliaConstraints/Benchmarks/blob/main/ConstraintCommons/visuals/chair_evolution_extrema.png?raw=true" alt="Chair Evolution" style="width:48%;"/>
119121
</div>
120122
```
121123

122-
### Performances
123-
124124
## Dictionaries
125125

126-
We provide the everuseful `incsert!` function for dictionaries.
126+
We provide the ever-useful `incsert!` function for dictionaries.
127127

128128
```@docs; canonical=false
129129
incsert!
@@ -136,4 +136,4 @@ incsert!
136136
<img src="https://github.com/JuliaConstraints/Benchmarks/blob/main/ConstraintCommons/visuals/bench_evolution_dictionaries.png?raw=true" alt="Bench Evolution" style="width:48%;"/>
137137
<img src="https://github.com/JuliaConstraints/Benchmarks/blob/main/ConstraintCommons/visuals/chair_evolution_dictionaries.png?raw=true" alt="Chair Evolution" style="width:48%;"/>
138138
</div>
139-
```
139+
```

docs/src/constraints/generic_constraints.md

+82-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Note that the *intention* constraint is not directly available through the JC-AP
1414

1515
We provide a straightforward example through the `:dist_different` constraint on how to define and add such a constraint in the `USUAL_CONSTRAINTS` collection.
1616

17-
Higher level modeling language such as `JuMP` should provide a `Intention` interface.
17+
Higher level modeling languages such as `JuMP` should provide a `Intention` interface.
1818

1919
### Defining an intention constraint in JC-API
2020

@@ -33,7 +33,7 @@ Ensures that the distances between marks on the ruler are unique.
3333
predicate_dist_different(x) = abs(x[1] - x[2]) abs(x[3] - x[4])
3434

3535
# Add it to usual constraints
36-
@usual concept_dist_different(x) = xcsp_intension(
36+
@usual concept_dist_different(x) = xcsp_intention(
3737
list = x,
3838
predicate = predicate_dist_different
3939
)
@@ -44,11 +44,11 @@ Please check the section dedicated to the Golomb Ruler problem to see a use for
4444

4545
### APIs
4646

47-
Note that the *intension* constraint is not directly available through the JC-API in Constraints.jl. It is designed as such since defining a constraint through a *predicate* is the natural way.
47+
Note that the *intention* constraint is not directly available through the JC-API in Constraints.jl. It is designed as such since defining a constraint through a *predicate* is the natural way.
4848

4949
We provide here a usage example for the `:dist_different` constraint, previously added to the `USUAL_CONSTRAINTS` collection.
5050

51-
Higher level modeling language such as `JuMP` should provide an `Intension` interface.
51+
Higher level modeling language such as `JuMP` should provide an `Intention` interface.
5252

5353
::: code-group
5454

@@ -63,7 +63,7 @@ concept(:dist_different)(x)
6363
# Defines the DistDifferent constraint
6464
using Constraints
6565

66-
c = x -> xcsp_intension(
66+
c = x -> xcsp_intention(
6767
list = x,
6868
predicate = y -> abs(y[1] - y[2]) abs(y[3] - y[4])
6969
)
@@ -76,35 +76,100 @@ c([1, 2, 3, 4]) # false
7676
using CBLS, JuMP
7777

7878
model = Model(CBLS.Optimizer)
79+
80+
# Using build-in DistDifferent
7981
@variable(model, 0 <= X[1:4] <= 10, Int)
8082
@constraint(model, X in DistDifferent())
83+
84+
# Alternatively
85+
@variable(model, 0 <= Y[1:4] <= 10, Int)
86+
@constraint(model, Y in Intention(y -> abs(y[1] - y[2]) abs(y[3] - y[4])))
87+
8188
optimize!(model)
8289

8390
@info value.(X)
84-
85-
# Note that this example gives a solution for the constraint within the interval 0:10
91+
@info value.(Y)
8692
```
8793

8894
```julia [MOI]
89-
# TODO: How to handle intention in JuMP/MOI
90-
```
95+
using CBLS
96+
import MathOptInterface as MOI
9197

92-
:::
98+
optimizer = CBLS.Optimizer()
9399

94-
### Specific documentation
100+
x = MOI.add_variables(optimizer, 4)
101+
for xi in x
102+
# Missing RangeDomain currently in CBLS
103+
MOI.add_constraint(optimizer, xi, CBLS.DiscreteSet(collect[1:10]))
104+
end
105+
MOI.add_constraint(optimizer, x, CBLS.Intention(y -> abs(y[1] - y[2]) abs(y[3] - y[4])))
95106

96-
```@docs; canonical=false
97-
xcsp_intension
107+
MOI.optimize!(optimizer)
98108
```
99109

110+
:::
111+
100112
## Extension Constraints
101113

102-
These are constraints that are defined by explicitly listing all the tuples of values that satisfy the constraint. They are called extensional because they are defined by the set of values they allow. For example, a binary constraint that specifies that a variable X must be either 1 or 2 and a variable Y must be either 3 or 4 could be defined extensionally by the set of tuples {(1,3), (1,4), (2,3), (2,4)}.
114+
These are constraints that are defined by explicitly listing all the tuples of values that satisfy the constraint. They are called extensional because they are defined by the set of values they allow. For example, a binary constraint that specifies that a variable ``X`` must be either ``1`` or ``2`` and a variable ``Y`` must be either ``3`` or ``4`` could be defined extensionally by the set of tuples $${(1,3), (1,4), (2,3), (2,4)}.$$
103115

104116
These two types of constraints provide a flexible way to define complex relationships between variables in constraint programming.
105117

106-
### [XCSP](https://arxiv.org/abs/2009.00514) in Constraints.jl
118+
::: code-group
119+
120+
```julia [JC-API]
121+
using Constraints
107122

108-
```@docs; canonical=false
109-
xcsp_extension
123+
concept(:dist_different, x)
124+
concept(:dist_different)(x)
110125
```
126+
127+
```julia [XCSP]
128+
# Defines the DistDifferent constraint
129+
using Constraints
130+
131+
c = x -> xcsp_intention(
132+
list = x,
133+
predicate = y -> abs(y[1] - y[2]) abs(y[3] - y[4])
134+
)
135+
136+
c([1, 2, 3, 3]) # true
137+
c([1, 2, 3, 4]) # false
138+
```
139+
140+
```julia [JuMP]
141+
using CBLS, JuMP
142+
143+
model = Model(CBLS.Optimizer)
144+
145+
# Using build-in DistDifferent
146+
@variable(model, 0 <= X[1:4] <= 10, Int)
147+
@constraint(model, X in DistDifferent())
148+
149+
# Alternatively
150+
@variable(model, 0 <= Y[1:4] <= 10, Int)
151+
@constraint(model, Y in Intention(y -> abs(y[1] - y[2]) abs(y[3] - y[4])))
152+
153+
optimize!(model)
154+
155+
@info value.(X)
156+
@info value.(Y)
157+
```
158+
159+
```julia [MOI]
160+
using CBLS
161+
import MathOptInterface as MOI
162+
163+
optimizer = CBLS.Optimizer()
164+
165+
x = MOI.add_variables(optimizer, 4)
166+
for xi in x
167+
# Missing RangeDomain currently in CBLS
168+
MOI.add_constraint(optimizer, xi, CBLS.DiscreteSet(collect[1:10]))
169+
end
170+
MOI.add_constraint(optimizer, x, CBLS.Intention(y -> abs(y[1] - y[2]) abs(y[3] - y[4])))
171+
172+
MOI.optimize!(optimizer)
173+
```
174+
175+
:::

docs/src/constraints/variables_and_domains.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ MOI.add_constraint(optimizer, v4, CBLS.DiscreteSet([1, 42, 3.14]))
6969

7070
### `RangeDomain`
7171

72-
A range domain allows for minimal storage and more efficient operation on discrete sets defined as `Range` in Julia. It is not recommended for dynamic domains (it will be replaced with `SetDomain` as soon non-extremal element is removed).
72+
A range domain allows for minimal storage and more efficient operation on discrete sets defined as `Range` in Julia. It is not recommended for dynamic domains (it will be replaced with `SetDomain` as soon as a non-extremal element is removed).
7373

7474
::: code-group
7575

0 commit comments

Comments
 (0)