02c9843e1b
- Implemented runtime-only adaptive quality controller to optimize simulation performance based on CPU time. - Added adaptive quality thresholds and recovery cycles to dynamically adjust simulation fidelity. - Introduced single-step solving method for civilization transitions to improve performance under high loads. - Updated benchmark scripts to include speed parameter for testing various simulation speeds. - Added tests for adaptive quality adjustments and their effects on civilization flow calculations. - Documented results of optimization attempts and their impact on performance metrics.
51 lines
1.9 KiB
GDScript
51 lines
1.9 KiB
GDScript
extends SceneTree
|
|
|
|
var checks: int = 0
|
|
var failures: int = 0
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run")
|
|
|
|
func check(condition: bool, message: String) -> void:
|
|
checks += 1
|
|
if not condition:
|
|
failures += 1
|
|
push_error(message)
|
|
|
|
func run() -> void:
|
|
var world = load("res://world/owniverse/owniverse.gd").new()
|
|
world.update_adaptive_quality(250000)
|
|
check(world.adaptive_quality == 2, "A slow cycle selects the medium approximation")
|
|
world.update_adaptive_quality(250000)
|
|
check(world.adaptive_quality == 3, "A slow medium-approximation cycle selects the coarse mode")
|
|
check(world.adaptive_generation_phase == 1, "Coarse generation phase alternates")
|
|
for i in 36: world.update_adaptive_quality(100000)
|
|
check(world.adaptive_quality == 2, "Thirty consecutive recovery cycles lower quality by one level")
|
|
for i in 30: world.update_adaptive_quality(100000)
|
|
check(world.adaptive_quality == 1, "Sustained headroom lowers quality gradually")
|
|
for i in 30: world.update_adaptive_quality(100000)
|
|
check(world.adaptive_quality == 0, "The exact mode returns after sustained headroom")
|
|
|
|
var rows: Array = []
|
|
for node in 12:
|
|
var edges: Dictionary = {}
|
|
var outgoing: float = 0.0
|
|
if node < 6:
|
|
edges[node + 6] = 0.25
|
|
outgoing = 0.25
|
|
rows.append({"edges": edges, "outgoing": outgoing})
|
|
var generator: Dictionary = {"rows": rows, "index": {"source": 0}}
|
|
var solved: Dictionary = world.civilization_flow._solve_single_step(generator, "source", 2.0)
|
|
for ethic in 6:
|
|
var mass: float = 0.0
|
|
var occupation: float = 0.0
|
|
for node in range(ethic, 12, 6):
|
|
mass += solved.mass[node]
|
|
occupation += solved.occupation[node]
|
|
check(absf(mass - 1.0) < 1e-12, "Approximate transition conserves ethic mass %d" % ethic)
|
|
check(absf(occupation - 2.0) < 1e-12, "Approximate transition conserves integrated time %d" % ethic)
|
|
|
|
world.free()
|
|
print("Adaptive quality: %d checks, %d failures" % [checks, failures])
|
|
quit(1 if failures else 0)
|