Skip to content

Commit

Permalink
Changed to more natural numbering of the polynomials in value function
Browse files Browse the repository at this point in the history
  • Loading branch information
olof3 committed Nov 7, 2018
1 parent cbd745e commit 6c77334
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,18 @@ function pwq_dp_constrained(ℓ::AbstractTransitionCost{T}, V_N::QuadraticPolyno
#global counter2
#counter1 = 0
#counter2 = 0

N = size(ℓ, 2)
@assert M <= N-1 "Cannot have more segments than N-1."

V_N = deepcopy(V_N)
V_N.time_index = N

Λ = Array{PiecewiseQuadratic{T}}(undef, M, N)

for i=1:N-1
p = minimize_wrt_x2(ℓ[i, N], V_N)
p.time_index = N
p.time_index = i
p.ancestor = V_N
Λ[1, i] = create_new_pwq(p)
end

Expand Down Expand Up @@ -289,7 +292,7 @@ function pwq_dp_constrained(ℓ::AbstractTransitionCost{T}, V_N::QuadraticPolyno
add_quadratic!(Λ_new, μ)

if μ.has_been_used == true
μ.time_index = ip
μ.time_index = i
μ.ancestor = λ.p
μ = QuadraticPolynomial{T}()
μ.has_been_used = false
Expand Down Expand Up @@ -326,7 +329,7 @@ function pwq_dp_regularized(ℓ::AbstractTransitionCost{T}, V_N::QuadraticPolyno
Λ = Vector{PiecewiseQuadratic{T}}(undef, N)

V_N = deepcopy(V_N)
V_N.time_index = -1
V_N.time_index = N
Λ[N] = create_new_pwq(V_N)

μ = QuadraticPolynomial{T}()
Expand All @@ -347,7 +350,7 @@ function pwq_dp_regularized(ℓ::AbstractTransitionCost{T}, V_N::QuadraticPolyno
add_quadratic!(Λ_new, μ)

if μ.has_been_used
μ.time_index = ip
μ.time_index = i
μ.ancestor = λ.p
μ = QuadraticPolynomial{T}()
μ.has_been_used = false
Expand Down Expand Up @@ -377,7 +380,7 @@ function recover_optimal_index_set(Λ::PiecewiseQuadratic{T}, first_index=1) whe

p, y, f = find_minimum(Λ)

I = [first_index]
I = Vector{Int}(undef, 0)

while true
push!(I, p.time_index)
Expand All @@ -387,10 +390,6 @@ function recover_optimal_index_set(Λ::PiecewiseQuadratic{T}, first_index=1) whe
end

p = p.ancestor

if p.time_index == -1
break
end
end

return I, y, f
Expand Down

0 comments on commit 6c77334

Please sign in to comment.