Skip to content
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 by Bors] - General valued constraint satisfaction problem defined #7404

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
67e5b5a
template defined
madvorak Sep 27, 2023
99660ce
the order must be linear
madvorak Sep 28, 2023
eabbed9
move docstring
madvorak Sep 28, 2023
e8834ed
mess
madvorak Sep 28, 2023
0a22003
fix and more definitions and example
madvorak Sep 28, 2023
7d25edd
inheriting `Bool.linearOrder` by a single line
madvorak Sep 28, 2023
71dea62
more omitted
madvorak Sep 28, 2023
9aa34f5
lil finite-valued example
madvorak Sep 29, 2023
05d035d
moved to Combinatorics
madvorak Sep 29, 2023
dd15809
docs for VCSP
madvorak Sep 29, 2023
cda3275
indent docs/references.bib
madvorak Sep 29, 2023
23403fa
better docs
madvorak Sep 29, 2023
70d57b8
docs
madvorak Sep 29, 2023
ccf48fd
we need a set of cost functions (possibly infinite), not just a list
madvorak Sep 29, 2023
3697e27
mathlib conventions
madvorak Sep 29, 2023
67f962a
small ValuedCspTerm refactor
madvorak Oct 3, 2023
d6bbaec
API for unary and binary cost functions
madvorak Oct 3, 2023
a2f35bf
m
madvorak Oct 3, 2023
a329ed9
d
madvorak Oct 3, 2023
49219d7
Update Mathlib/Combinatorics/Optimization/ValuedCSP.lean
madvorak Oct 19, 2023
c47bf2d
Update Mathlib/Combinatorics/Optimization/ValuedCSP.lean
madvorak Oct 19, 2023
bec3f58
Type*
madvorak Oct 19, 2023
12dc292
camelCase
madvorak Oct 19, 2023
def2137
examples pushed out
madvorak Oct 19, 2023
c678064
unused import
madvorak Oct 19, 2023
a137693
changes
madvorak Oct 19, 2023
3606d62
Merge remote-tracking branch 'origin/master' into vcsp
madvorak Oct 23, 2023
5b0ea27
Merge remote-tracking branch 'origin/master' into vcsp
madvorak Oct 23, 2023
4c4d2c9
departure of n1aryOfUnary and n2aryOfBinary
madvorak Oct 23, 2023
c1b123e
better naming
madvorak Oct 23, 2023
e713b2e
let it be Multiset
madvorak Oct 23, 2023
81cd487
Update Mathlib/Combinatorics/Optimization/Deleteme.lean
madvorak Oct 23, 2023
231a22e
Delete Mathlib/Combinatorics/Optimization/Deleteme.lean
madvorak Oct 23, 2023
de3037e
OrderedAddCommMonoid and explanation
madvorak Oct 23, 2023
ac9d025
Update Mathlib/Combinatorics/Optimization/ValuedCSP.lean
madvorak Oct 24, 2023
8e701f5
Update Mathlib/Combinatorics/Optimization/ValuedCSP.lean
madvorak Oct 24, 2023
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
1 change: 1 addition & 0 deletions Mathlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,7 @@ import Mathlib.Combinatorics.HalesJewett
import Mathlib.Combinatorics.Hall.Basic
import Mathlib.Combinatorics.Hall.Finite
import Mathlib.Combinatorics.Hindman
import Mathlib.Combinatorics.Optimization.ValuedCSP
madvorak marked this conversation as resolved.
Show resolved Hide resolved
import Mathlib.Combinatorics.Partition
import Mathlib.Combinatorics.Pigeonhole
fpvandoorn marked this conversation as resolved.
Show resolved Hide resolved
import Mathlib.Combinatorics.Quiver.Arborescence
Expand Down
67 changes: 67 additions & 0 deletions Mathlib/Combinatorics/Optimization/ValuedCSP.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/-
Copyright (c) 2023 Martin Dvorak. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Martin Dvorak
-/
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.BigOperators.Multiset.Basic

/-!

# General-Valued Constraint Satisfaction Problems

General-Valued CSP is a very broad class of problems in discrete optimization.
General-Valued CSP subsumes Min-Cost-Hom (including 3-SAT for example) and Finite-Valued CSP.

## Main definitions
* `ValuedCsp`: A VCSP template; fixes a domain, a codomain, and allowed cost functions.
* `ValuedCsp.Term`: One summand in a VCSP instance; calls a concrete function from given template.
* `ValuedCsp.Term.evalSolution`: An evaluation of the VCSP term for given solution.
* `ValuedCsp.Instance`: An instance of a VCSP problem over given template.
* `ValuedCsp.Instance.evalSolution`: An evaluation of the VCSP instance for given solution.
* `ValuedCsp.Instance.OptimumSolution`: Is given solution a minimum of the VCSP instance?

## References
* [D. A. Cohen, M. C. Cooper, P. Creed, P. G. Jeavons, S. Živný,
*An Algebraic Theory of Complexity for Discrete Optimisation*][cohen2012]

-/

/-- A template for a valued CSP problem over a domain `D` with costs in `C`.
Regarding `C` we want to support `Bool`, `Nat`, `ENat`, `Int`, `Rat`, `NNRat`,
`Real`, `NNReal`, `EReal`, `ENNReal`, and tuples made of any of those types. -/
@[reducible, nolint unusedArguments]
def ValuedCsp (D C : Type*) [OrderedAddCommMonoid C] :=
Set (Σ (n : ℕ), (Fin n → D) → C) -- Cost functions `D^n → C` for any `n`

variable {D C : Type*} [OrderedAddCommMonoid C]

/-- A term in a valued CSP instance over the template `Γ`. -/
structure ValuedCsp.Term (Γ : ValuedCsp D C) (ι : Type*) where
/-- Arity of the function -/
n : ℕ
/-- Which cost function is instantiated -/
f : (Fin n → D) → C
/-- The cost function comes from the template -/
inΓ : ⟨n, f⟩ ∈ Γ
/-- Which variables are plugged as arguments to the cost function -/
app : Fin n → ι

/-- Evaluation of a `Γ` term `t` for given solution `x`. -/
def ValuedCsp.Term.evalSolution {Γ : ValuedCsp D C} {ι : Type*}
(t : Γ.Term ι) (x : ι → D) : C :=
t.f (x ∘ t.app)

/-- A valued CSP instance over the template `Γ` with variables indexed by `ι`.-/
def ValuedCsp.Instance (Γ : ValuedCsp D C) (ι : Type*) :=
madvorak marked this conversation as resolved.
Show resolved Hide resolved
Multiset (Γ.Term ι)

/-- Evaluation of a `Γ` instance `I` for given solution `x`. -/
def ValuedCsp.Instance.evalSolution {Γ : ValuedCsp D C} {ι : Type*}
(I : Γ.Instance ι) (x : ι → D) : C :=
(I.map (·.evalSolution x)).sum

/-- Condition for `x` being an optimum solution (min) to given `Γ` instance `I`.-/
def ValuedCsp.Instance.OptimumSolution {Γ : ValuedCsp D C} {ι : Type*}
madvorak marked this conversation as resolved.
Show resolved Hide resolved
(I : Γ.Instance ι) (x : ι → D) : Prop :=
∀ y : ι → D, I.evalSolution x ≤ I.evalSolution y
16 changes: 16 additions & 0 deletions docs/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,22 @@ @Book{ clark_gon
url = {http://alpha.math.uga.edu/~pete/geometryofnumbers.pdf}
}

@Article{ cohen2012,
author = {David A. Cohen and Martin C. Cooper and Páidí Creed and
Peter G. Jeavons and Stanislav Živný},
title = {An Algebraic Theory of Complexity for Discrete
Optimisation},
journal = {CoRR},
volume = {abs/1207.6692},
year = {2012},
url = {http://arxiv.org/abs/1207.6692},
eprinttype = {arXiv},
eprint = {1207.6692},
timestamp = {Mon, 03 Aug 2020 17:29:56 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-1207-6692.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}

@Book{ conrad2000,
author = {Conrad, Brian},
title = {Grothendieck duality and base change},
Expand Down