code wiki / (root) / nx_caplab_cities.nx

nx_caplab_cities.nx source

↩ module page · 61 lines · 2375 B

1// nx_caplab_cities.nx -- Capitalism Lab R6: cities + retail presence (the MAP). 2// 3// Capitalism Lab is geographic. Each CITY is its own market, sized by 4// population; a firm only competes in a city where it has RETAIL PRESENCE 5// (capacity > 0 there); a product's total sales = the sum across cities. 6// Expanding to more / bigger cities reaches more demand. Composes R4 7// (quality/brand split) + R5 (per-market capacity) across geography. 8// 9// MODEL: 10// city_M = base_M * population / pop_ref (bigger city = more demand) 11// per city = split among PRESENT firms by appeal, capped by retail capacity 12// product total = sum over cities of that firm's per-city sales 13// 14// nx_safety_envelope: 15// intended_use: capitalism-lab geography (pure functions, no I/O) 16// sil_target: SIL1 17// verdict: NOT_YET_EVALUATED 18// 19// genealogy_id: capitalism_lab_cities_map_canon 20// lineage_id: nx_caplab_cities_v1 21 22import "nx_syscalls.nx" 23import "nx_tier.nx" 24import "nx_caplab_quality.nx" 25 26// A city's market size scales with its population (relative to a reference). 27func nx_clab_city_market_m(base_m: nx_int, population: nx_int, pop_ref: nx_int) -> nx_int { 28 return base_m * population / pop_ref 29} 30 31// Run one city's market for one product: ONLY firms with retail presence 32// (caps[i] > 0) compete; demand splits by price/quality/brand appeal among the 33// present firms, capped by each firm's retail capacity in that city. 34func nx_clab_city_run(n: nx_int, prices: *i64, quals: *i64, brands: *i64, 35 choke: nx_int, wp: nx_int, wq: nx_int, wb: nx_int, 36 city_m: nx_int, caps: *i64, out_sold: *i64) { 37 let wv: *i64 = (sys_mmap(n * NX_SIZEOF_NX_INT)) as *i64 38 var i: nx_int = 0 39 while i < n { 40 if caps[i] > 0 { 41 wv[i] = nx_clab_appeal_qb(choke, prices[i], quals[i], brands[i], wp, wq, wb) 42 } else { 43 wv[i] = 0 44 } 45 i = i + 1 46 } 47 nx_clab_apportion(n, wv, city_m, out_sold) 48 i = 0 49 while i < n { 50 if out_sold[i] > caps[i] { out_sold[i] = caps[i] } 51 i = i + 1 52 } 53} 54 55// Sum one firm's sales for a product across all cities it operates in. 56func nx_clab_geo_total(n_cities: nx_int, per_city_sold: *i64) -> nx_int { 57 var t: nx_int = 0 58 var i: nx_int = 0 59 while i < n_cities { t = t + per_city_sold[i]; i = i + 1 } 60 return t 61}