-
Notifications
You must be signed in to change notification settings - Fork 0
Violations + OPF tests #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5c31384
sets
klamike fa08086
inplace API
klamike 30d801d
user api
klamike cb7432a
update
klamike 30f6d05
rm ext
klamike 54dda0b
diff+test
klamike 5ce1fa3
power
klamike 4af68e5
Update test/test_viols.jl
klamike 27b98d0
remove CV
klamike a643cce
refactor
klamike 9659fb9
inline hint for nothing
klamike 493f2a3
opt-in cuda tests
klamike 7ce391d
fix rebase
klamike 886962a
fix rebase cont.
klamike ba2368d
reinstate luksan cpu
klamike 46a9a3b
simplify viol crc
klamike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| """ | ||
| all_violations!(bm::BatchModel, X::AbstractMatrix) | ||
|
|
||
| Compute all constraint and variable violations for a batch of solutions. | ||
| """ | ||
| function all_violations!(bm::BatchModel, X::AbstractMatrix) | ||
| V = cons_nln_batch!(bm, X) | ||
|
|
||
| Vc = constraint_violations!(bm, V) | ||
| Vb = bound_violations!(bm, X) | ||
|
|
||
| return Vc, Vb | ||
| end | ||
|
|
||
| """ | ||
| all_violations!(bm::BatchModel, X::AbstractMatrix, Θ::AbstractMatrix) | ||
|
|
||
| Compute all constraint and variable violations for a batch of solutions and parameters. | ||
| """ | ||
| function all_violations!(bm::BatchModel, X::AbstractMatrix, Θ::AbstractMatrix) | ||
| V = cons_nln_batch!(bm, X, Θ) | ||
|
|
||
| Vc = constraint_violations!(bm, V) | ||
| Vb = bound_violations!(bm, X) | ||
|
|
||
| return Vc, Vb | ||
| end | ||
|
|
||
| """ | ||
| constraint_violations!(bm::BatchModel, V::AbstractMatrix) | ||
|
|
||
| Compute constraint violations for a batch of constraint primal values. | ||
| """ | ||
| function constraint_violations!(bm::BatchModel, V::AbstractMatrix) | ||
| viols_cons_out = _maybe_view(bm, :viols_cons_out, V) | ||
|
|
||
| _violation!.(eachcol(viols_cons_out), eachcol(V), bm.viols_cons) | ||
|
|
||
| return viols_cons_out | ||
| end | ||
|
|
||
| """ | ||
| bound_violations!(bm::BatchModel, X::AbstractMatrix) | ||
|
|
||
| Compute variable violations for a batch of variable primal values. | ||
| """ | ||
| function bound_violations!(bm::BatchModel, X::AbstractMatrix) | ||
| viols_vars_out = _maybe_view(bm, :viols_vars_out, X) | ||
|
|
||
| _violation!.(eachcol(viols_vars_out), eachcol(X), bm.viols_vars) | ||
|
|
||
| return viols_vars_out | ||
| end | ||
|
|
||
| @inline _violation!(d, v, s::S) where {S} = begin | ||
| d .= _violation(v, s) | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """ | ||
| Interval{VT} | ||
|
|
||
| Represents the RHS of M constraints g(xᵢ) ∈ [lᵢ, uᵢ] ∀i ∈ 1:M. | ||
| """ | ||
| struct Interval{VT} | ||
| l::VT | ||
| u::VT | ||
| end | ||
| @inline _violation(v, s::Interval{VT}) where {VT} = begin | ||
| @. max(s.l - v, v - s.u, zero(v)) | ||
| end | ||
|
|
||
| Base.broadcastable(s::Interval) = Ref(s) | ||
| Base.isempty(s::Interval{VT}) where {VT} = isempty(s.l) || isempty(s.u) | ||
|
|
||
| # empty support (unconstrained) | ||
| Interval(::Nothing) = Interval() | ||
| Interval() = Interval(nothing, nothing) | ||
| Base.isempty(::Interval{Nothing}) = true | ||
| @inline _violation(v, ::Interval{Nothing}) = zero(v) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.