streamline constraints generation

and make it a bit less dependent on the ordering of elements in basis
This commit is contained in:
Marek Kaluba 2023-05-22 22:40:32 +02:00
parent d1a58d3890
commit 66f10612de
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
1 changed files with 6 additions and 10 deletions

View File

@ -156,12 +156,8 @@ function constraints(
mstr::StarAlgebras.MultiplicativeStructure; mstr::StarAlgebras.MultiplicativeStructure;
augmented = false, augmented = false,
) )
cnstrs = _constraints( id = basis[one(first(basis))]
mstr; cnstrs = _constraints(mstr; augmented = augmented, id = mstr[id, id])
augmented = augmented,
num_constraints = length(basis),
id = basis[one(first(basis))],
)
return Dict( return Dict(
basis[i] => ConstraintMatrix(c, size(mstr)..., 1) for basis[i] => ConstraintMatrix(c, size(mstr)..., 1) for
@ -172,11 +168,11 @@ end
function _constraints( function _constraints(
mstr::StarAlgebras.MultiplicativeStructure; mstr::StarAlgebras.MultiplicativeStructure;
augmented::Bool = false, augmented::Bool = false,
num_constraints = maximum(mstr),
id, id,
) )
cnstrs = [signed(eltype(mstr))[] for _ in 1:num_constraints] cnstrs = [signed(eltype(mstr))[] for _ in 1:maximum(mstr)]
LI = LinearIndices(size(mstr)) LI = LinearIndices(size(mstr))
id_ = mstr[id, id]
for ci in CartesianIndices(size(mstr)) for ci in CartesianIndices(size(mstr))
k = LI[ci] k = LI[ci]
@ -185,8 +181,8 @@ function _constraints(
push!(cnstrs[a_star_b], k) push!(cnstrs[a_star_b], k)
if augmented if augmented
# (1-a)'(1-b) = 1 - a' - b + a'b # (1-a)'(1-b) = 1 - a' - b + a'b
push!(cnstrs[id], k) push!(cnstrs[id_], k)
a_star, b = mstr[-i, id], j a_star, b = mstr[-i, id], mstr[j, id]
push!(cnstrs[a_star], -k) push!(cnstrs[a_star], -k)
push!(cnstrs[b], -k) push!(cnstrs[b], -k)
end end