def loop.go

unified-nsga-iii@0.2.2.0 · polynomial_mutation.bend:98

import unified-nsga-iii@0.2.2.0/polynomial_mutation.bend as PolynomialMutation
import Base
import unified-nsga-iii@0.2.2.0/bounds.bend as Bounds
import unified-nsga-iii@0.2.2.0/rng.bend as Rng

98# Kind: 0n = copy the head (skip or tiny span), 1n = mutate the head.
99def loop.go(
100  fuel: Nat,
101  kind: Nat,
102  xs: List<&2, F32>,
103  ivs: List<&2, Bounds.Interval>,
104  +eta: F32,
105  rng: Rng.State,
106  acc: List<&2, F32>,
107  +p: F32
108) -> Rng.State & List<&2, F32>:
109  match fuel kind xs ivs:
110    case 0n k a b:
111      done(rng, acc)
112    case 1n++f 0n +x <> rest +iv <> +ivrest:
113      +rng2 = advance(rng, f)
114      loop.go(
115        f,
116        skip_kind(F32.is_gt(Rng.last_double(rng2), p), tiny_head(ivrest)),
117        rest, ivrest, eta, rng2, x <> acc, p
118      )
119    case 1n++f 1n+q +x <> rest +iv <> +ivrest:
120      +lo = Bounds.lo(iv)
121      +hi = Bounds.hi(iv)
122      +dmax = F32.sub(hi, lo)
123      +rng_a = Rng.next_double(rng)
124      +rand = Rng.last_double(rng_a)
125      +mut_pow = F32.div(1.0, F32.add(eta, 1.0))
126      +dq = deltaq(eta, mut_pow, F32.div(F32.sub(x, lo), dmax), F32.div(F32.sub(hi, x), dmax), rand)
127      +y = F32.clamp(F32.add(x, F32.mul(dq, dmax)), lo, hi)
128      +rng_b = advance(rng_a, f)
129      loop.go(
130        f,
131        skip_kind(F32.is_gt(Rng.last_double(rng_b), p), tiny_head(ivrest)),
132        rest, ivrest, eta, rng_b, y <> acc, p
133      )
134    case 1n++f k Nil{} b:
135      done(rng, acc)
136    case 1n++f k a <> as Nil{}:
137      done(rng, acc)

Uses (21)

Used by (1)