-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor(blossom): Extract verification code.
- Loading branch information
1 parent
1ece25e
commit 22bb23b
Showing
7 changed files
with
265 additions
and
179 deletions.
There are no files selected for viewing
This file contains 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 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,56 @@ | ||
import assert from 'assert'; | ||
|
||
// Check optimized delta2 against a trivial computation. | ||
const checkDelta2 = ({ | ||
nvertex, | ||
neighbend, | ||
label, | ||
endpoint, | ||
bestedge, | ||
slack, | ||
inblossom | ||
}) => { | ||
for (let v = 0; v < nvertex; ++v) { | ||
if (label[inblossom[v]] === 0) { | ||
let bd = null; | ||
let bk = -1; | ||
for (let i = 0; i < neighbend[v].length; ++i) { | ||
const p = neighbend[v][i]; | ||
const k = Math.floor(p / 2); | ||
const w = endpoint[p]; | ||
if (label[inblossom[w]] === 1) { | ||
const d = slack(k); | ||
if (bk === -1 || d < bd) { | ||
bk = k; | ||
bd = d; | ||
} | ||
} | ||
} | ||
|
||
if ( | ||
(bestedge[v] !== -1 || bk !== -1) && | ||
(bestedge[v] === -1 || bd !== slack(bestedge[v])) | ||
) { | ||
console.debug( | ||
'v=' + | ||
v + | ||
' bk=' + | ||
bk + | ||
' bd=' + | ||
bd + | ||
' bestedge=' + | ||
bestedge[v] + | ||
' slack=' + | ||
slack(bestedge[v]) | ||
); | ||
} | ||
|
||
assert( | ||
(bk === -1 && bestedge[v] === -1) || | ||
(bestedge[v] !== -1 && bd === slack(bestedge[v])) | ||
); | ||
} | ||
} | ||
}; | ||
|
||
export default checkDelta2; |
Oops, something went wrong.