Skip to content

Commit

Permalink
v0.2.1 (#12)
Browse files Browse the repository at this point in the history
* Normalize and rows in general parameter constraints

* only normalize if norm_factor > 0

* v0.2.1
  • Loading branch information
darnstrom authored Jan 8, 2025
1 parent 32955d1 commit f51c526
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ParametricDAQP"
uuid = "19f72acb-e2a9-45c8-96b9-4d5487c8db2e"
authors = ["Daniel Arnström <[email protected]>"]
version = "0.2.0"
version = "0.2.1"

[deps]
DAQP = "c47d62df-3981-49c8-9651-128b1cd08617"
Expand Down
7 changes: 6 additions & 1 deletion src/mpsolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ function mpsolve(mpQP,Θ;opts=nothing, AS0 = nothing) # bounds_table as option
# Setup parametric problem and normalize
prob = setup_mpp(mpQP;fix_ids,fix_vals)
prob, Θ, tf = normalize_parameters(prob,Θ)
if(isnothing(prob)) # Θ makes the problem trivially infeasible
@warn "The parameter region of interest is empty"
F,info = CriticalRegion[], (solve_time = 0, nCR = 0, nLPs = 0, nExplored = 0,status=:EmptyParameterRegion)
end


if(isnothing(AS0))
AS0 = compute_AS0(prob,Θ)
Expand All @@ -50,7 +55,7 @@ function mpdaqp_explicit(prob,Θ,AS0;opts = Settings())
if(length(id_cands) < m)
id_zeros = findall(prob.norm_factors .≤ opts.eps_zero)
opts.verbose > 0 && @warn "Rows $id_zeros in A are zero → seen as parameter constraints"
if hasproperty(Θ,:Ath)
if hasproperty(Θ,:A)
A =.A -prob.d[1:end-1,id_zeros]]
b =.b; prob.d[end,id_zeros]]
else
Expand Down
28 changes: 24 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ function setup_mpp(mpQP;normalize=true, fix_ids=Int[],fix_vals=zeros(0))
norm_factor = 0
for i in 1:m
norm_factor = norm(view(M,i,:),2)
M[i,:]./=norm_factor
d[:,i]./=norm_factor
if(norm_factor > 0)
M[i,:]./=norm_factor
d[:,i]./=norm_factor
end
norm_factors[i]= norm_factor
end
end
Expand All @@ -65,7 +67,7 @@ function setup_mpp(mpQP;normalize=true, fix_ids=Int[],fix_vals=zeros(0))
end

## Normalize parameters to -1 ≤ θ ≤ 1
function normalize_parameters(prob::MPLDP,Θ)
function normalize_parameters(prob::MPLDP;eps_zero=1e-12)
if(isempty.ub)) # assume already normalized
return prob,Θ,(center=0,scaling = 1)
end
Expand All @@ -80,8 +82,26 @@ function normalize_parameters(prob::MPLDP,Θ)

Ath = haskey(Θ,:A) ? Θ.A : zeros(nth,0);
bth = haskey(Θ,:b) ? Θ.b : zeros(0);
Θ =(A=norm_factors.*Ath, b = bth-(center'*Ath)[:], # TODO: verify

# Normalize A to box -1 ≤ θ ≤ 1
A = norm_factors.*Ath
b = bth-(center'*Ath)[:]

# Normalize A
is_nonzero = falses(length(b))
for i in 1:length(b)
norm_factor = norm(view(A,:,i),2);
if(norm_factor>eps_zero)
rdiv!(view(A,:,i),norm_factor)
b[i]/=norm_factor
is_nonzero[i] = true
else
(b[i]<-eps_zero) && return nothing,nothing,nothing # trivially infeasible
end
end
Θ =(A=A[:,is_nonzero], b = b[is_nonzero], # TODO: verify
lb = -ones(nth), ub = ones(nth));

return prob, Θ,(center=center, scaling = 1 ./ norm_factors)
end
function normalize_parameters(prob::MPQP,Θ)
Expand Down

2 comments on commit f51c526

@darnstrom
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/122595

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" f51c5260a7a1b90e052929f25775149d809c219b
git push origin v0.2.1

Please sign in to comment.