bounds.bend
unified-nsga-iii@0.1.2.0 · 59 lines · 0 definitions
1# IProblem box — variable count + per-var [lo, hi].
2# Named problems (ZDT1 / ZDT2 / DTLZ2) live in problems.bend.
3
4import Base
5
6type Interval is Data:
7 MkInterval{
8 low: F32
9 high: F32
10 }
11
12type Box is Data:
13 MkBox{
14 m: Nat
15 ivs: List<&2, Interval>
16 }
17
18def interval(+low: F32, +high: F32) -> Interval:
19 MkInterval{low, high}
20
21def lo(b: Interval) -> F32:
22 match b:
23 case MkInterval{low, high}:
24 low
25
26def hi(b: Interval) -> F32:
27 match b:
28 case MkInterval{low, high}:
29 high
30
31def box(+m: Nat, ivs: List<&2, Interval>) -> Box:
32 MkBox{m, ivs}
33
34def n_obj(b: Box) -> Nat:
35 match b:
36 case MkBox{m, ivs}:
37 m
38
39def intervals_of(b: Box) -> List<&2, Interval>:
40 match b:
41 case MkBox{m, ivs}:
42 ivs
43
44def n_var(b: Box) -> Nat:
45 List.length(&2, Interval, intervals_of(b))
46
47def at.go(m: Maybe<&2, Interval>) -> Interval:
48 match m:
49 case None{}:
50 MkInterval{0.0, 1.0}
51 case Some{iv}:
52 iv
53
54def at(b: Box, i: Nat) -> Interval:
55 at.go(List.get(&2, Interval, intervals_of(b), i))
56
57# nv copies of [0, 1]. Smoke / operator tests; not a named problem.
58def unit_n(nv: Nat, nm: Nat) -> Box:
59 MkBox{nm, List.replicate(Interval, nv, MkInterval{0.0, 1.0})}