Having nothing as an outcome using GLPK and JuMP

i have this piece of code for optimization:

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 :

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

b(a)

i get this

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

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 nothings.

1 Like

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 nothings. So your code needs to be changed in order to return something else. What do you want it to return?

1 Like

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.

1 Like

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

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.