Julia 有没有办法在一个函数中调用两个内部函数
我有一个函数,它有两个我想调用的内部函数 我尝试过使用闭包法,但我认为我做得不对Julia 有没有办法在一个函数中调用两个内部函数,julia,Julia,我有一个函数,它有两个我想调用的内部函数 我尝试过使用闭包法,但我认为我做得不对 using JuMP 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
using JuMP
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
我建议改用匿名函数(
setc=function(c).
而不是function setc(c).
)。@SebastianPfitzner它向我展示了与我之前在帖子中提到的相同的结果这没有什么不同,这只是一个显示问题?解算器打印出来可能很有趣,但我不认为这是个问题。我真的不知道,因为无论我输入什么矩阵,它都会显示相同的结果thing@MattB. 我知道这可能是一个显示问题,但我认为product
函数也造成了问题
* 2 linear constraints
* 4 variables
Solver is Clp), getfield(Main, Symbol("##4#6")){Model,Int64,Array{Int64,1},Array{Int64,1},Array{Int64,1},Array{Variable,1}}(Feasibility problem with:
* 2 linear constraints
* 4 variables
Solver is Clp, 4, [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], x[i] ∀ i ∈ {1,2,3,4}))```
which doesn't make sense