# Having nothing as an outcome using GLPK and JuMP

**URL:** <https://discourse.julialang.org/t/having-nothing-as-an-outcome-using-glpk-and-jump/62948>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [June 15, 2021, 1:55pm UTC](https://discourse.julialang.org/t/having-nothing-as-an-outcome-using-glpk-and-jump/62948 "2021-06-15T13:55:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marouane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marouane/32/16267_2.png) [@marouane](https://discourse.julialang.org/u/marouane)\
**Post date:** [June 15, 2021, 1:55pm UTC](https://discourse.julialang.org/t/having-nothing-as-an-outcome-using-glpk-and-jump/62948/1 "2021-06-15T13:55:16Z")

</div>

i have this piece of code for optimization:

```julia
using JuMP
using GLPK

function scan_maker(A)
    m= Model(GLPK.Optimizer)
    

    level = size(A, 2)
    v = zeros(Int, level)
    ub = zeros(Int, level)
    lb = zeros(Int, level)

    @variable(m, x[1:level])
    @constraint(m, con, A*x.>=0)

    function setc(a)
        set_normalized_rhs.(con, float.(a))
    end
    
    function scan(c::Channel)
        i = 1
        init = 1
        while i > 0
            if i >= init
                @objective(m, Max, x[i])
                res = JuMP.optimize!(m)
                if termination_status(m) == MOI.OPTIMAL || termination_status(m) == MOI.DUAL_INFEASIBLE
                    ub[i] = round(Int, getvalue(x[i]))
                    set_objective_sense(m, MOI.MIN_SENSE)
                    res = JuMP.optimize!(m)
                    @assert termination_status(m) == MOI.OPTIMAL || termination_status(m) == MOI.DUAL_INFEASIBLE
                    lb[i] = round(Int, getvalue(x[i]))

                    v[i] = lb[i]
                    init += 1
                else
                    @assert termination_status(m) == MOI.INFEASIBLE
                    i -= 1
                    continue
                end
            elseif v[i] < ub[i]
                v[i] += 1
            else
                set_upper_bound(x[i], Inf)
                set_lower_bound(x[i], -Inf)
                init -= 1
                i -= 1
                continue
            end

            if i >= level
                put!(c, v)
                continue
            else
                set_upper_bound(x[i], v[i])
                set_lower_bound(x[i], v[i])
                i += 1
            end
        end
        close(c)
    end
    
    return setc, scan
end

```

the code works quite well except for the first nested function `setc` when i call it it shows `nothing` in the output and i don’t know with what i should change `set_normalized_rhs`  
because when i do this :

```julia
A=[2 2;1 1;4 3]
a=[2,3,7]
b, d= scan_maker(A)

b(a)

```

i get this

```julia
3-element Array{Nothing,1}:
 nothing
 nothing
 nothing

```

---

<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:** [June 16, 2021, 1:29am UTC](https://discourse.julialang.org/t/having-nothing-as-an-outcome-using-glpk-and-jump/62948/2 "2021-06-16T01:29:19Z")

</div>

What do you expect `b(a)` to return?

You’re broadcasting a function (`set_normalized_rhs`) that returns `nothing` over three elements, so you get a vector of 3 `nothing`s.

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [June 16, 2021, 11:49am UTC](https://discourse.julialang.org/t/having-nothing-as-an-outcome-using-glpk-and-jump/62948/5 "2021-06-16T11:49:10Z")

</div>

What @odow is saying is that the result of of `set_normalized_rhs` is **always** `nothing`. Since `setc` returns the results of `set_normalized_rhs`, you get `nothing`s. So your code needs to be changed in order to return something else. What do you want it to return?

---

<div class="post-metadata">

**Author:** ![marouane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marouane/32/16267_2.png) [@marouane](https://discourse.julialang.org/u/marouane)\
**Post date:** [June 16, 2021, 11:52am UTC](https://discourse.julialang.org/t/having-nothing-as-an-outcome-using-glpk-and-jump/62948/6 "2021-06-16T11:52:31Z")

</div>

oh now i get it, well i was using on `JuMP@0.18` this: `model.linconstr.lb` where `lb` is the lower bound, now i switched to `set_normalized_rhs`, so basically i’m expecting to get the lower bound.

---

<div class="post-metadata">

**Author:** ![marouane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marouane/32/16267_2.png) [@marouane](https://discourse.julialang.org/u/marouane)\
**Post date:** [June 16, 2021, 1:02pm UTC](https://discourse.julialang.org/t/having-nothing-as-an-outcome-using-glpk-and-jump/62948/7 "2021-06-16T13:02:18Z")

</div>

using on `JuMP@0.18` this: `model.linconstr.lb` where `lb` is the lower bound, now i switched to `set_normalized_rhs` , so basically i’m expecting to get the lower bound according to the constraint

---

<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:** [June 16, 2021, 6:41pm UTC](https://discourse.julialang.org/t/having-nothing-as-an-outcome-using-glpk-and-jump/62948/8 "2021-06-16T18:41:19Z")

</div>

The lower bound will be `a`, because you’re setting it. Why do you need it returned from `setc`? You’re passing it in as an argument.
