# Understanding of implies

**URL:** <https://discourse.julialang.org/t/understanding-of-implies/61978>\
**Category:** Optimization (Mathematical)\
**Created:** [May 28, 2021, 7:58am UTC](https://discourse.julialang.org/t/understanding-of-implies/61978 "2021-05-28T07:58:52Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 29, 2021, 1:42am UTC](https://discourse.julialang.org/t/understanding-of-implies/61978/11 "2021-05-29T01:42:09Z")

</div>

I’ll repeat my answer from: [Trying to solve a puzzle - #15 by odow](https://discourse.julialang.org/t/trying-to-solve-a-puzzle/61515/15)

```plaintext
using JuMP, Cbc
function main(; houses::Vector{Tuple{Int,Int}}, ratio::Float64)
    M = maximum(h[1] for h in houses)
    N = maximum(h[2] for h in houses)
    model = Model(Cbc.Optimizer)
    @variable(model, cell_tower[1:M, 1:N], Bin)
    @variable(model, is_covered[houses], Bin)
    @objective(model, Min, sum(cell_tower))
    stencil(i, j) = cell_tower[max(i-1,1):min(i+1,M), max(j-1,1):min(j+1,N)]
    @constraint(model, [h in houses], is_covered[h] <= sum(stencil(h[1], h[2])))
    @constraint(model, sum(is_covered) >= ratio * length(houses))
    optimize!(model)
    return value.(cell_tower)
end
houses = [(1, 9), (3, 2), (4, 4), (5, 6), (8, 9), (9, 1)]
main(houses, ratio = 0.7)

```

If the right-hand side of the `is_covered[h] <= ` constraint is 1, then `is_covered[h]` can be 0 or 1. But the next constraint means that there is a benefit to it taking the value 1. Of course, is the `ratio` constraint isn’t binding in an optimal solution, then there may be some houses `h` that are covered by the cell tower, but still have `is_covered[h] = 0`.

The typical way to fix this is to add a small term to the objective to encourage the “correct” solution

```julia
@objective(model, Min, sum(cell_tower) - 0.001 * sum(is_covered))

```

OR modeling is a large field, and more of an art than a science. There are some good online courses to learn more:

> **[Discrete Optimization](https://www.coursera.org/learn/discrete-optimization)**
>
> Offered by The University of Melbourne. Tired of solving Sudokus by hand? This class teaches you how to solve complex search problems with ... Enroll for free.

---

_[View the full topic](https://discourse.julialang.org/t/understanding-of-implies/61978)._
