-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Hi,
I was trying to define a semialgebraic sets (composed by inequalities and equalities, but I focused only on equalities for the moment) and I'm stuck in the definition.
I cannot find a way to define an empty set, and then add iteratively constraint to it. I have the following code
@polyvar(t[1:4])
@polyvar(s[1:3])
# inequalities = Vector{MultivariatePolynomials.Polynomial}(undef,0)
inequalities = []
equalities = []
# K = BasicSemialgebraicSet{Float64,Polynomial{Float64,Float64}}()
# K = basic_semialgebraic_set(FullSpace(), [t[1]])
# add_inequality!( K, t[2] )
for j=1:n-1
push!(inequalities, t[j])
if j==1
push!(inequalities, t[j]^2 - s[j]^2)
elseif j==n-1
push!(inequalities, t[j]^2 - (-s[j-1])^2)
else
push!(inequalities, t[j]^2 - (s[j]-s[j-1])^2)
end
end
for j=1:n-2
push!(inequalities, s[j]+smax)
push!(inequalities, -s[j]+smax)
g = s[j]
for v in -smax:smax
if v!=0
g *= (s[j]-v)
end
end
push!(equalities, g)
end
for j=1:n-1
if j==1
g1 = 0.25*t[j]^2 - 0.5*t[j]*(s[j]) - 0.25*s[j]^2 - 0.5*s[j] + distances[j]
g2 = 0.25*t[j]^2 + 0.5*t[j]*(s[j]) - 0.25*s[j]^2 + 0.5*s[j] - distances[j]
push!(inequalities, g1)
push!(inequalities, g2)
elseif j==n-1
g1 = 0.25*t[j]^2 - 0.5*t[j]*(s[j-1]) - 0.25*s[j-1]^2 + 0.5*s[j-1] + distances[j]
g2 = 0.25*t[j]^2 + 0.5*t[j]*(s[j-1]) - 0.25*s[j-1]^2 - 0.5*s[j-1] - distances[j]
push!(inequalities, g1)
push!(inequalities, g2)
else
g1 = 0.25*t[j]^2 - 0.5*t[j]*(s[j-1]+s[j]) - 0.25*s[j-1]^2 - 0.25*s[j]^2 + 0.5*s[j-1]*s[j] - 0.5*s[j] + 0.5*s[j-1] + distances[j]
g2 = 0.25*t[j]^2 + 0.5*t[j]*(s[j-1]+s[j]) - 0.25*s[j-1]^2 - 0.25*s[j]^2 + 0.5*s[j-1]*s[j] + 0.5*s[j] - 0.5*s[j-1] - distances[j]
push!(inequalities, g1)
push!(inequalities, g2)
end
end
where I define my polyvar and then I create multiple polynomials inequalities. Now, how can I transform all of these (the vector inequalities and equalities) into a set?
I tried the following ways
K = basic_semialgebraic_set(algebraic_set(equalities), inequalities)
# only inequalities
K = basic_semialgebraic_set(FullSpace(), inequalities)
But both of them failed. Even if try to expand all the inequalities with the @set macro
K = @set t[1]>=0 && t[2]>=0 && t[3]>=0 && t[4]>=0 && t[1]^2>=s[1]^2 && t[2]^2>=(s[2]-s[1])^2 && t[3]^2>=(s[3]-s[2])^2 && t[4]^2>=(s[3])^2 &&
s[1]+smax>=0 && -s[1]+smax>=0 && s[2]+smax>=0 && -s[2]+smax>=0 && s[3]+smax>=0 && -s[3]+smax>=0 && 0.25*t[1]^2 - 0.5*t[1]*(s[1]) - 0.25*s[1]^2 - 0.5*s[1] + distances[1] &&
0.25*t[1]^2 + 0.5*t[1]*(s[1]) - 0.25*s[1]^2 + 0.5*s[1] - distances[1] &&
0.25*t[2]^2 - 0.5*t[2]*(s[1]+s[2]) - 0.25*s[1]^2 - 0.25*s[2]^2 + 0.5*s[1]*s[2] - 0.5*s[2] + 0.5*s[1] + distances[2] &&
0.25*t[2]^2 + 0.5*t[2]*(s[1]+s[2]) - 0.25*s[1]^2 - 0.25*s[2]^2 + 0.5*s[1]*s[2] + 0.5*s[2] - 0.5*s[1] - distances[2] &&
0.25*t[3]^2 - 0.5*t[3]*(s[2]+s[3]) - 0.25*s[2]^2 - 0.25*s[3]^2 + 0.5*s[2]*s[3] - 0.5*s[3] + 0.5*s[2] + distances[3] &&
0.25*t[3]^2 + 0.5*t[3]*(s[2]+s[3]) - 0.25*s[2]^2 - 0.25*s[3]^2 + 0.5*s[2]*s[3] + 0.5*s[3] - 0.5*s[2] - distances[3] &&
0.25*t[4]^2 - 0.5*t[4]*(s[3]) - 0.25*s[3]^2 + 0.5*s[3] + distances[4] &&
0.25*t[4]^2 + 0.5*t[4]*(s[3]) - 0.25*s[3]^2 - 0.5*s[3] - distances[4]
I get the following error
ERROR: LoadError: MethodError: no method matching length(::SemialgebraicSets.BasicSemialgebraicSet{Int64, MultivariatePolynomials.VectorPolynomial{Int64, MultivariatePolynomials.Term{Int64, TypedPolynomials.Monomial{(s₁, s₂, s₃, t₁, t₂, t₃, t₄), 7}}}, SemialgebraicSets.FullSpace})
Closest candidates are:
length(::BenchmarkTools.Trial)
@ BenchmarkTools ~/.julia/packages/BenchmarkTools/1i1mY/src/trials.jl:41
length(::Combinatorics.CoolLexCombinations)
@ Combinatorics ~/.julia/packages/Combinatorics/nV2DW/src/combinations.jl:137
length(::Base.Iterators.Flatten{Tuple{}})
@ Base iterators.jl:1193
...
Metadata
Metadata
Assignees
Labels
No labels