From f842c0dea8f986c69ccbfbe533a840f6397fd663 Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 31 Jul 2024 11:08:38 +1200 Subject: [PATCH] [docs] add warning to docs about tolerances in Bin and Int variables --- docs/src/manual/variables.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/src/manual/variables.md b/docs/src/manual/variables.md index e7f8daef473..dc3b33c0c39 100644 --- a/docs/src/manual/variables.md +++ b/docs/src/manual/variables.md @@ -562,6 +562,14 @@ julia> @variable(model, x, Bin) x ``` +!!! warning + Solvers use tolerances to decide whether a variable satisfies the binary + constraint. Thus, the true feasible region is + $[-\varepsilon, \varepsilon] \cup [1 - \varepsilon, 1 + \varepsilon]$, + where $\varepsilon$ is solver-specific, but typically `1e-6`. As a result, + you should expect the `value(x)` of a `Bin` variable to sometimes take a + value like `-0.0`, `1e-8`, or `0.999999`. + Check if a variable is binary using [`is_binary`](@ref): ```jldoctest variables_binary julia> is_binary(x) @@ -604,6 +612,14 @@ julia> @variable(model, x, Int) x ``` +!!! warning + Solvers use tolerances to decide whether a variable satisfies the integer + constraint. Thus, the true feasible region is + $\cup_{z \in \mathbb{Z}}[z - \varepsilon, z + \varepsilon]$, + where $\varepsilon$ is solver-specific, but typically `1e-6`. As a result, + you should expect the `value(x)` of an `Int` variable to sometimes take a + value like `1e-8`, or `2.999999`. + Check if a variable is integer using [`is_integer`](@ref): ```jldoctest variables_integer julia> is_integer(x)