Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fc-pregmod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pregmodfan
fc-pregmod
Commits
24d733f2
Commit
24d733f2
authored
4 years ago
by
svornost
Browse files
Options
Downloads
Patches
Plain Diff
Add cycle detection to inbreeding calculation.
parent
d011df7e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!7313
Add cycle detection to inbreeding calculation.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/js/ibcJS.js
+24
-16
24 additions, 16 deletions
src/js/ibcJS.js
with
24 additions
and
16 deletions
src/js/ibcJS.js
+
24
−
16
View file @
24d733f2
...
...
@@ -182,30 +182,30 @@ globalThis.ibc = (() => {
return
n
.
_coeff
;
};
// Populate the NodeCodes.
// Populate the NodeCodes.
//
// Each node has a set of NodeCodes, which represent the set of paths from it to its ancestors.
// NodeCodes here are represented by arrays of integers.
//
// NodeCodes are constructed recursively in this fashion:
//
// - Assign each of the founders (nodes with both parents === null) an unique ID, starting from
// 0 and incrementing each time (the order doesn't matter); a founder's set of NodeCodes has
// - Assign each of the founders (nodes with both parents === null) an unique ID, starting from
// 0 and incrementing each time (the order doesn't matter); a founder's set of NodeCodes has
// exactly one NodeCode, which is [ID] (an array containing only their ID)
//
// - For each other node, let M be its child number w.r.t. its mother and N its child number
// w.r.t. its father, i.e. the number of children that the respective parent has had before
// this one (the order is not important to the algorithm, it's arbitrary here for
// - For each other node, let M be its child number w.r.t. its mother and N its child number
// w.r.t. its father, i.e. the number of children that the respective parent has had before
// this one (the order is not important to the algorithm, it's arbitrary here for
// convenience). Its set of NodeCodes is the set of all its mother's NodeCodes with M appended
// and all of its father's NodeCodes with N appended. For example, if its mother has the
// NodeCodes [[2]] and M = 3 and its father has the NodeCodes [[0,1], [3,1]] and N = 1 then
// and all of its father's NodeCodes with N appended. For example, if its mother has the
// NodeCodes [[2]] and M = 3 and its father has the NodeCodes [[0,1], [3,1]] and N = 1 then
// the set of NodeCodes for this node would be
//
//
// [[2, 3], [0, 1, 1], [3, 1, 1]]
//
// We do this iteratively here, looping over the set of all nodes until each has been assigned
// a NodeCode. This requires looping through a number of times equal to the number of
// generations, since as soon as both parents have NodeCodes their children's NodeCodes may be
// a NodeCode. This requires looping through a number of times equal to the number of
// generations, since as soon as both parents have NodeCodes their children's NodeCodes may be
// computed.
let
make_nc
=
nodes
=>
{
// Generate founder NodeCodes
...
...
@@ -221,7 +221,9 @@ globalThis.ibc = (() => {
});
// Generate the rest of the NodeCodes
while
(
seen
.
length
!=
total
)
{
let
oldSeenLength
=
-
1
;
while
(
seen
.
length
!==
total
)
{
oldSeenLength
=
seen
.
length
;
Object
.
keys
(
nodes
).
forEach
(
s
=>
{
let
n
=
nodes
[
s
];
if
(
seen
.
includes
(
+
s
))
// We've already done this
...
...
@@ -232,7 +234,7 @@ globalThis.ibc = (() => {
seen
.
push
(
n
.
id
);
// Compute the NodeCodes from its parents
[
n
.
mother
,
n
.
father
].
forEach
((
a
,
i
)
=>
{
if
(
a
===
null
||
(
n
.
mother
===
n
.
father
&&
i
==
1
))
// Ignore missing parents/repeated
if
(
a
===
null
||
(
n
.
mother
===
n
.
father
&&
i
==
=
1
))
// Ignore missing parents/repeated
return
;
a
.
nodecodes
.
forEach
(
nc
=>
{
...
...
@@ -245,8 +247,14 @@ globalThis.ibc = (() => {
});
// NodeCodes must be sorted; this suffices
n
.
nodecodes
.
sort
()
n
.
nodecodes
.
sort
()
;
});
// check to make sure we're progressing...if not, there's a cycle in the graph
// dump all the nodes participating in or descended from the cycle and let the player figure it out
if
(
oldSeenLength
===
seen
.
length
)
{
const
badSlaveIDs
=
Object
.
keys
(
nodes
).
filter
(
s
=>
!
seen
.
includes
(
+
s
)).
map
(
k
=>
nodes
[
k
].
id
);
throw
(
`Inbreeding calculation: heritance cycle detected. Check slave IDs:
${
badSlaveIDs
}
`
);
}
}
// Cache the string NodeCodes
...
...
@@ -261,7 +269,7 @@ globalThis.ibc = (() => {
// Recursively create the nodes we need, moving upwards from the given slave
let
create_node_rec
=
s
=>
{
// Certain parents (e.g. 0, societal elite) are not considered to be related, despite
// Certain parents (e.g. 0, societal elite) are not considered to be related, despite
// having the same ID; convert them to null
let
m
=
or_null
(
s
.
mother
);
let
f
=
or_null
(
s
.
father
);
...
...
@@ -269,7 +277,7 @@ globalThis.ibc = (() => {
// Ensure that parent nodes are created
[
m
,
f
].
forEach
(
p
=>
{
if
(
p
!==
null
&&
!
(
p
in
nodes
))
{
// Not created, we have to do something
if
(
p
===
-
1
)
{
if
(
p
===
-
1
)
{
create_node_rec
(
SugarCube
.
State
.
variables
.
PC
);
}
else
{
// Search for a slave state, genePool entry, or missingTable entry
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment