# Trying to solve a puzzle

**URL:** <https://discourse.julialang.org/t/trying-to-solve-a-puzzle/61515>\
**Category:** Optimization (Mathematical)\
**Created:** [May 20, 2021, 1:05pm UTC](https://discourse.julialang.org/t/trying-to-solve-a-puzzle/61515 "2021-05-20T13:05:25Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![sogrbilja](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sogrbilja/32/17521_2.png) [@sogrbilja](https://discourse.julialang.org/u/sogrbilja)\
**Post date:** [May 21, 2021, 5:11pm UTC](https://discourse.julialang.org/t/trying-to-solve-a-puzzle/61515/22 "2021-05-21T17:11:25Z")

</div>

Wait, you already created a model for this problem and solve it???

---

<div class="post-metadata">

**Author:** ![MarcMush](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcmush/32/18006_2.png) [@MarcMush](https://discourse.julialang.org/u/MarcMush)\
**Post date:** [May 21, 2021, 5:24pm UTC](https://discourse.julialang.org/t/trying-to-solve-a-puzzle/61515/23 "2021-05-21T17:24:09Z")

</div>

not a JuMP model, you can’t express this as a linear problem, and I don’t think it’s even a convex problem

just a few loops over the 1,000,000 possibilities and keeping the best arrangement

---

<div class="post-metadata">

**Author:** ![sogrbilja](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sogrbilja/32/17521_2.png) [@sogrbilja](https://discourse.julialang.org/u/sogrbilja)\
**Post date:** [May 22, 2021, 7:49am UTC](https://discourse.julialang.org/t/trying-to-solve-a-puzzle/61515/24 "2021-05-22T07:49:39Z")

</div>

I was thinking is it possible to put a @variable in for loop? For example:

```julia

Size = 2

@constraint(
    model, 
    [h in houses],
    isCovered[h] <=
    sum(
        isAntenna[r, c]
        for r in h[1] - Size:h[1] + Size, c in h[2] - Size:h[2] + Size
        if 1 <= r <= M && 1 <= c <= N
    ) 
)

Is it possible to make Size to be Int @variable? ...and if not, why?

```

---

<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 23, 2021, 2:32am UTC](https://discourse.julialang.org/t/trying-to-solve-a-puzzle/61515/25 "2021-05-23T02:32:19Z")

</div>

> Is it possible to make Size to be Int @variable?

No.

> if not, why?

Sums have to be structural over a fixed number of elements. The _values_ of the variables can change, but not the sparsity pattern of the summation.

[Previous page](https://discourse.julialang.org/t/trying-to-solve-a-puzzle/61515.md?page=1)
