i have some problems in replacing the deprecated function produce()
with Channel()
in this code:
function scan_maker(A)
m = JuMP.Model(solver=ClpSolver(PrimalTolerance=1e-3, DualTolerance=1e-3, InfeasibleReturn=1, PresolveType=1))
# m = Model(solver=GurobiSolver())
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(c)
for i = 1:size(A, 1)
m.linconstr[i].lb = float(c[i])
end
end
function scan()
i = 1
init = 1
while i > 0
if i >= init
@objective(m, Max, x[i])
res = JuMP.solve(m, suppress_warnings=true)
if res==:Optimal || res==:Unbounded
ub[i] = round(Int, getvalue(x[i]))
setobjectivesense(m, :Min)
res = JuMP.solve(m, suppress_warnings=true)
@assert res==:Optimal || res==:Unbounded
lb[i] = round(Int, getvalue(x[i]))
v[i] = lb[i]
init += 1
else
@assert res==:Infeasible
i -= 1
continue
end
elseif v[i] < ub[i]
v[i] += 1
else
setupperbound(x[i], Inf)
setlowerbound(x[i], -Inf)
init -= 1
i -= 1
continue
end
if i >= level
produce(v)
continue
else
setupperbound(x[i], v[i])
setlowerbound(x[i], v[i])
i += 1
end
end
end
return setc, scan
end
i have tried to put c::Channel
as an argument of the function scan()
and change produce(v)
with put!(c,v)
the function was compiled but when i want to call the functions for example:
julia> A=[2 2;1 1;4 3]
3×2 Array{Int64,2}:
2 2
1 1
4 3
julia> B=[2;3;7]
3-element Array{Int64,1}:
2
3
7
julia> a,b=scan_maker(A)
(getfield(Main, Symbol("#setc#3")){Array{Int64,2},Model}([2 2; 1 1; 4 3], Feasibility problem with:
* 3 linear constraints
* 2 variables
Solver is Clp), getfield(Main, Symbol("#scan#4")){Model,Int64,Array{Int64,1},Array{Int64,1},Array{Int64,1},Array{Variable,1}}(Feasibility problem with:
* 3 linear constraints
* 2 variables
Solver is Clp, 2, [0, 0], [0, 0], [0, 0], x[i] ∀ i ∈ {1,2}))
julia> a(B) # i'm calling the new function which is supposed to return nothing and it's working
julia> mychannel=Channel((channel_arg) -> b( pwd(), channel_arg)) # defining a Channel
Channel{Any}(sz_max:0,sz_curr:0)
julia> b(mychannel)
ERROR: MethodError: no method matching (::getfield(Main, Symbol("#scan#4")){Model,Int64,Array{Int64,1},Array{Int64,1},Array{Int64,1},Array{Variable,1}})(::String, ::Channel{Any})
Stacktrace:
[1] check_channel_state at ./channels.jl:117 [inlined]
[2] put! at ./channels.jl:273 [inlined]
[3] push! at ./channels.jl:312 [inlined]
[4] (::getfield(Main, Symbol("#scan#4")){Model,Int64,Array{Int64,1},Array{Int64,1},Array{Int64,1},Array{Variable,1}})(::Channel{Any}) at ./REPL[3]:50
[5] top-level scope at REPL[20]:1
when i call the function scan
i get that error above, i don’t know how to deal with this.
The output should be something like this:
v = [-1, 6]
v = [0, 4]
v = [1, 2]