1 # IProblem box — variable count + per-var [lo, hi]. 2 # Named problems live in problems.bend. 3 4 import Base 5 6 type Interval is Data: 7 MkInterval{ 8 low: F32 9 high: F32 10 } 11 12 type Box is Data: 13 MkBox{ 14 m: Nat 15 ivs: List<&2, Interval> 16 } 17 18 def interval(+low: F32, +high: F32) -> Interval: 19 MkInterval{low, high} 20 21 def lo(b: Interval) -> F32: 22 match b: 23 case MkInterval{low, high}: 24 low 25 26 def hi(b: Interval) -> F32: 27 match b: 28 case MkInterval{low, high}: 29 high 30 31 def box(+m: Nat, ivs: List<&2, Interval>) -> Box: 32 MkBox{m, ivs} 33 34 def n_obj(b: Box) -> Nat: 35 match b: 36 case MkBox{m, ivs}: 37 m 38 39 def intervals_of(b: Box) -> List<&2, Interval>: 40 match b: 41 case MkBox{m, ivs}: 42 ivs 43 44 def n_var(b: Box) -> Nat: 45 List.length(&2, Interval, intervals_of(b)) 46 47 def 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 54 def 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; unit ZDT / DTLZ boxes. 58 def unit_n(nv: Nat, nm: Nat) -> Box: 59 MkBox{nm, List.replicate(Interval, nv, MkInterval{0.0, 1.0})} 60 61 # nv copies of [low, high]. Sphere / Ackley / Rosenbrock and any uniform range. 62 def span_n(nv: Nat, nm: Nat, +low: F32, +high: F32) -> Box: 63 MkBox{nm, List.replicate(Interval, nv, MkInterval{low, high})}