基本可行方案

问题描述 投票:0回答:0

我正在尝试在 Julia 中创建一个函数来测试矩阵 A 的基矩阵是否是基本可行解。出于某种我无法弄清楚的原因,每当我运行我的代码时,无论我为我的函数输入什么,我都会得到相同的输出。这是我的代码:

function is_bfs(A, b, basic_col_indices)
m = size(A, 1)
n = size(A, 2)

    # check if input is a standard form polyhedron
    if m > n || length(b) != m || rank(A) != m
        @warn("Input is not a standard form polyhedron!")
        return false
    end
    
    # remove duplicate entries
     unique!(sort!(basic_col_indices))
    
    # check if input data is consistent
    if !issubset(basic_col_indices, 1:n) || length(basic_col_indices) != m
        @warn("basic_col_indices is not a subset of [1,...,n] of cardinality m")
        return false
    end
    
    for basic_col_indices in combinations(1:n, m)
         B = A[:, basic_col_indices]
         x_B = inv(B) * b
    end
    
    if det(B) == 0
        return false
    end
    
    if any(x_B .< -1e-12)
        value = false
    else 
         value= true
    end
    println(value)
    println(B)
    println(x_B)
    return value

end
julia linear-programming
© www.soinside.com 2019 - 2024. All rights reserved.