Skip to content

Commit

Permalink
Merge pull request #33 from blegat/MOIv1
Browse files Browse the repository at this point in the history
Update to MOI v1
  • Loading branch information
Azzaare authored Aug 17, 2024
2 parents 24b9288 + b286498 commit aa4adfa
Show file tree
Hide file tree
Showing 64 changed files with 360 additions and 2,374 deletions.
10 changes: 10 additions & 0 deletions .SpellCheck.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[default]
extend-ignore-identifiers-re = [
# Match any identifier that contains "OT"
".*OT.*"
]

[default.extend-identifiers]
# Explicitly accept "OT"
OT = "OT"
arrayNd = "arrayNd"
43 changes: 43 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Check if Julia is already available in the PATH
id: julia_in_path
run: which julia
continue-on-error: true
- name: Install Julia, but only if it is not already available in the PATH
uses: julia-actions/setup-julia@v2
with:
version: "1"
arch: ${{ runner.arch }}
if: steps.julia_in_path.outcome != 'success'
- name: "Add the General registry via Git"
run: |
import Pkg
ENV["JULIA_PKG_SERVER"] = ""
Pkg.Registry.add("General")
shell: julia --color=yes {0}
- name: "Install CompatHelper"
run: |
import Pkg
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
version = "3"
Pkg.add(; name, uuid, version)
shell: julia --color=yes {0}
- name: "Run CompatHelper"
run: |
import CompatHelper
CompatHelper.main()
shell: julia --color=yes {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
4 changes: 2 additions & 2 deletions .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: '1.6'
version: '1'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
Expand Down
61 changes: 55 additions & 6 deletions .github/workflows/GitHubCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,79 @@ on:
pull_request:
branches:
- master
- dev
paths-ignore:
- "docs/**"
push:
branches:
- master
tags: '*'
paths-ignore:
- "docs/**"
jobs:
# formatter:
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# julia-version: [1]
# julia-arch: [x86]
# os: [ubuntu-latest]
# steps:
# - uses: julia-actions/setup-julia@latest
# with:
# version: ${{ matrix.julia-version }}

# - uses: actions/checkout@v4
# - name: Install JuliaFormatter and format
# # This will use the latest version by default but you can set the version like so:
# #
# # julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
# run: |
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="1.0.50"))'
# julia -e 'using JuliaFormatter; format(".", verbose=true)'
# - name: Format check
# run: |
# julia -e '
# out = Cmd(`git diff`) |> read |> String
# if out == ""
# exit(0)
# else
# @error "Some files have not been formatted !!!"
# write(stdout, out)
# exit(1)
# end'
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.6'
- "lts"
- "1"
- "pre"
os:
- ubuntu-latest
arch:
- x64
# - x86 # TODO fix tests for x86
include:
# test macOS and Windows with latest Julia only
- os: macOS-latest
arch: x64
version: 1
- os: windows-latest
arch: x64
version: 1
- os: windows-latest
arch: x86
version: 1
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
Expand All @@ -39,7 +88,7 @@ jobs:
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v4
with:
file: lcov.info
- uses: coverallsapp/github-action@master
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/SpellCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Spell Check

on: [pull_request]

jobs:
typos-check:
name: Spell Check with Typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4
- name: Check spelling
uses: crate-ci/typos@master
with:
config: ./.SpellCheck.toml
18 changes: 17 additions & 1 deletion .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ on:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: "3"
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
Expand All @@ -12,4 +28,4 @@ jobs:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
16 changes: 16 additions & 0 deletions .github/workflows/register.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Register Package
on:
workflow_dispatch:
inputs:
version:
description: Version to register or component to bump
required: true
jobs:
register:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: julia-actions/RegisterAction@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
MathOptInterface = "~0.10"
julia = "^1"
MathOptInterface = "1"
julia = "1"
27 changes: 12 additions & 15 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@ using Documenter, ConstraintProgrammingExtensions

makedocs(
sitename="ConstraintProgrammingExtensions",
format = Documenter.HTML(
format=Documenter.HTML(
# See https://github.com/JuliaDocs/Documenter.jl/issues/868
prettyurls = get(ENV, "CI", nothing) == "true",
mathengine = Documenter.MathJax2(),
collapselevel = 1,
prettyurls=get(ENV, "CI", nothing) == "true",
mathengine=Documenter.MathJax2(),
collapselevel=1,
),
strict = true,
modules = [ConstraintProgrammingExtensions],
checkdocs = :exports,
pages = [
strict=true,
modules=[ConstraintProgrammingExtensions],
checkdocs=:exports,
pages=[
"Introduction" => "index.md",
"Reference" => [
"reference/sets.md",
"reference/bridges_sets.md",
],
"Reference" => ["reference/sets.md", "reference/bridges_sets.md"],
"Comparison to other CP packages" => [
"mappings/constraintsolver.md",
"mappings/cplexcp.md",
Expand All @@ -30,11 +27,11 @@ makedocs(
"mappings/numberjack.md",
"mappings/sas.md",
"mappings/yalmip.md",
]
],
],
)

deploydocs(
push_preview = true,
repo = "github.com/dourouc05/ConstraintProgrammingExtensions.jl.git",
push_preview=true,
repo="github.com/JuliaConstraints/ConstraintProgrammingExtensions.jl.git",
)
20 changes: 10 additions & 10 deletions docs/src/mappings/minizinc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

MiniZinc has a similar goal to this project: a common modelling interface for many underlying solvers. It is based on a similar concept to that of bridges, but with much less flexibility: each high-level constraint is mapped in a fixed way onto lower-level constraints.

* Basic CP constraints:
* Domain:
* Basic CP constraints:
* Domain:
* Fixed: `CP.Domain`
* Variable: `CP.Membership`
* Multivalued: `CP.VectorDomain`
* [`table`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/table.mzn): [one binary variable per possible combination](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/linear/fzn_table_int.mzn)
* All different:
* All different:
* Base: `CP.AllDifferent`
* [`all_different`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/all_different.mzn): mapped onto [a MILP-like model](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_all_different_int.mzn).
* [`all_different_reif`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/all_different.mzn): similar, [with an equivalence](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_all_different_int_reif.mzn).
* These constraints are available in two includes: `all_different.mzn` and `alldifferent.mzn`.
* These constraints are available in two includes: `all_different.mzn` and `alldifferent.mzn`.
* All different except constants: `CP.AllDifferentExceptConstants`
* [`alldifferent_except_0`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/alldifferent_except_0.mzn) (one excluded value: 0) and [`alldifferent_except`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/alldifferent_except.mzn) (set of excluded values): either mapped [onto neq and disjunctions or onto GCC](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_alldifferent_except.mzn).
* [`alldifferent_except_0`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/alldifferent_except_0.mzn) (one excluded value: 0) and [`alldifferent_except`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/alldifferent_except.mzn) (set of excluded values): either mapped [onto neq and disjunctions or onto GCC](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_alldifferent_except.mzn).
* [`alldifferent_except_0_reif`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/alldifferent_except_0.mzn) (one excluded value: 0) and [`alldifferent_except_reif`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/alldifferent_except.mzn) (set of excluded values): the reified versions are only mapped [onto neq and disjunctions](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_alldifferent_except_reif.mzn).
* With symmetry: `SymmetricAllDifferent`
* [`symmetric_all_different`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/symmetric_all_different.mzn): [`all_different` and `inverse`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_symmetric_all_different.mzn)
Expand All @@ -37,7 +37,7 @@ MiniZinc has a similar goal to this project: a common modelling interface for ma
* [`nvalue_fn`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/nvalue_fn.mzn): function.
* Inversion: `CP.Inverse`
* [`inverse`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/inverse.mzn): [index computations](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_inverse.mzn).
* [`inverse_reif`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/inverse.mzn): similar, [wih an equivalence](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_inverse_reif.mzn).
* [`inverse_reif`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/inverse.mzn): similar, [with an equivalence](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_inverse_reif.mzn).
* Also available [as a function](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/inverse_fn.mzn).
* [`inverse_in_range`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/inverse_in_range.mzn): [?](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_inverse_in_range.mzn).
* Sliding sum: `CP.SlidingSum`
Expand All @@ -47,9 +47,9 @@ MiniZinc has a similar goal to this project: a common modelling interface for ma
* [`value_precede`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/value_precede.mzn): [several reifications)(https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_value_precede_int.mzn).
* [No reified variant)(https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_value_precede_int_reif.mzn).
* Combinatorial sets:
* Bin packing:
* Bin packing:
* Raw: `CP.BinPacking` (with supplementary load variables)
* [`bin_packing`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/bin_packing.mzn): mapped onto [a MILP-like model](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_bin_packing.mzn), but without binary variables (replaced by their definition in the capacity constraint: `bin[item] == value`).
* [`bin_packing`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/bin_packing.mzn): mapped onto [a MILP-like model](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_bin_packing.mzn), but without binary variables (replaced by their definition in the capacity constraint: `bin[item] == value`).
* [`bin_packing_reif`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/bin_packing.mzn): similar, [with an equivalence](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_bin_packing_reif.mzn).
* Capacitated: `CP.FixedCapacityBinPacking` and `CP.VariableCapacityBinPacking` (with supplementary load variables)
* [`bin_packing_capa`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/bin_packing_capa.mzn): same MILP-like model [with a linear capacity constraint](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_bin_packing_capa.mzn).
Expand All @@ -62,7 +62,7 @@ MiniZinc has a similar goal to this project: a common modelling interface for ma
* Knapsack: `CP.Knapsack` with values
* [`knapsack`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/knapsack.mzn): mapped onto [a MILP model](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_knapsack.mzn).
* [`knapsack_reif`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/knapsack.mzn): similar, [with an equivalence](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_knapsack_reif.mzn).
* Sorting:
* Sorting:
* Maximum/minimum: `CP.MaximumAmong` and `CP.MinimumAmong`
* [`maximum`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/maximum.mzn): built-in, [except for linear solvers](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/linear/redefinitions.mzn)
* [`minimum`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/minimum.mzn): built-in, [except for linear solvers](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/linear/redefinitions.mzn)
Expand Down Expand Up @@ -90,7 +90,7 @@ MiniZinc has a similar goal to this project: a common modelling interface for ma
* [`lex2`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/lex2.mzn): in a matrix, have both rows and columns lexicographically sorted, [mapped to two chains](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_lex2.mzn).
* [`strict_lex2`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/strict_lex2.mzn): in a matrix, have both rows and columns strictly lexicographically sorted, [mapped to two chains](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_strict_lex2.mzn).
* Reifications are available.
* Scheduling:
* Scheduling:
* Rectangle overlapping: `CP.NonOverlappingOrthotopes`
* [`diffn`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/diffn.mzn): [mapped to a disjunction of linear inequalities](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/fzn_diffn.mzn).
* [`diffn_k`](https://github.com/MiniZinc/libminizinc/blob/master/share/minizinc/std/diffn.mzn): generalisation to `k` dimensions.
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/AllDifferent/ad_to_neq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function MOIBC.bridge_constraint(
Tuple{Int, Int},
MOI.ConstraintIndex{MOI.ScalarAffineFunction{T}, CP.DifferentFrom{T}},
}()
sizehint!(cons, dim * (dim - 1) / 2)
sizehint!(cons, div(dim * (dim - 1), 2))

for i in 1:dim
for j in (i+1):dim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function MOIBC.bridge_constraint(
# Upper-triangular matrix of constraints: i >= j, i.e. d(d-1)/2 elements:
# \sum_{i=2}^{d} (n - i + 1) = d (d - 1) / 2
cons = Dict{Tuple{Int, Int}, MOI.ConstraintIndex}()
sizehint!(cons, dim * (dim - 1) / 2)
sizehint!(cons, div(dim * (dim - 1), 2))

for i in 1:dim
for j in (i+1):dim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ function MOIBC.bridge_constraint(
cons_different_reif = Dict{Tuple{Int, Int}, MOI.ConstraintIndex{MOI.VectorAffineFunction{T}, CP.Reification{CP.DifferentFrom{T}}}}()
cons = Dict{Tuple{Int, Int}, MOI.ConstraintIndex{MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}}}()

sizehint!(vars_different, s.dimension * (s.dimension - 1) / 2)
sizehint!(vars_different_bin, s.dimension * (s.dimension - 1) / 2)
sizehint!(cons_different_reif, s.dimension * (s.dimension - 1) / 2)
sizehint!(cons, s.dimension * (s.dimension - 1) / 2)
sizehint!(vars_different, div(s.dimension * (s.dimension - 1), 2))
sizehint!(vars_different_bin, div(s.dimension * (s.dimension - 1), 2))
sizehint!(cons_different_reif, div(s.dimension * (s.dimension - 1), 2))
sizehint!(cons, div(s.dimension * (s.dimension - 1), 2))

for i in 1:s.dimension
for j in (i+1):s.dimension
Expand Down
14 changes: 6 additions & 8 deletions src/Bridges/Constraint/DifferentFrom_Reify/reif_neq_to_milp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,14 @@ function MOIBC.bridge_constraint(
)

# If the constraint is satisfied, constrain the reified.
smallm = if T <: Int
one(T)
else
T(_REIF_EQTO_FLOAT_EPSILON)
end

con_smallm = MOI.add_constraint(
model,
f_scalars[1] - var_abs / smallm,
MOI.LessThan(zero(T))
if T <: Int
f_scalars[1] - var_abs
else
f_scalars[1] - var_abs / T(_REIF_EQTO_FLOAT_EPSILON)
end,
MOI.LessThan(zero(T)),
)

return ReificationDifferentFrom2MILPBridge{T}(var_abs, var_abs_int, con_abs, con_bigm, con_smallm)
Expand Down
Loading

0 comments on commit aa4adfa

Please sign in to comment.