1
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
"""自检场景生成器(测试端专用)。
|
||||
|
||||
真值只进入测试与 CLI ``--self-test`` 入口,策略端仅见模拟器响应;
|
||||
场景覆盖题面强调的边界情形:近圆域边界源、最小/最大接收半径两档,
|
||||
以及问题4的定向源(含朝向背离圆心的朝外边界源)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
from random import Random
|
||||
|
||||
from .simulator import Source
|
||||
|
||||
|
||||
def random_omni_scene(seed: int = 20260910, count: int = 10) -> list[Source]:
|
||||
"""全向源场景:频道互异,含近圆域边界点,接收半径 1000/1500 交替。"""
|
||||
if not 0 <= count <= 20:
|
||||
raise ValueError("源数量须在 0..20")
|
||||
rng = Random(seed)
|
||||
channels = rng.sample(range(1, 21), count)
|
||||
sources = []
|
||||
for index, channel in enumerate(channels):
|
||||
if index == 0:
|
||||
radius = rng.uniform(1780.0, 1799.0) # 近圆域边界
|
||||
elif index == 1 and count > 1:
|
||||
radius = rng.uniform(1780.0, 1799.0)
|
||||
else:
|
||||
radius = rng.uniform(0.0, 1795.0)
|
||||
angle = rng.uniform(0.0, 2 * math.pi)
|
||||
r_eff = 1000.0 if index % 2 == 0 else 1500.0
|
||||
sources.append(Source(channel=channel,
|
||||
x=radius * math.cos(angle),
|
||||
y=radius * math.sin(angle),
|
||||
r_eff_m=r_eff))
|
||||
return sources
|
||||
|
||||
|
||||
def mixed_scene(seed: int = 20260910, count: int = 10,
|
||||
directional: int = 3) -> list[Source]:
|
||||
"""问题4混合场景:count 个源中 directional 个为定向源。
|
||||
|
||||
改造 random_omni_scene 的前 directional 个源:近圆域边界的前两个定向源
|
||||
朝向取"背离圆心"(发射半平面基本朝向域外,覆盖网格仍保证可发现,
|
||||
即"朝外边界源不漏"验收情形),其余定向源朝向随机。
|
||||
"""
|
||||
if not 0 <= directional <= count:
|
||||
raise ValueError("定向源数量须在 0..count")
|
||||
sources = list(random_omni_scene(seed=seed, count=count))
|
||||
rng = Random(seed + 1)
|
||||
for index in range(directional):
|
||||
source = sources[index]
|
||||
if index < 2 and count > 1 and math.hypot(source.x, source.y) > 1700.0:
|
||||
heading = math.degrees(math.atan2(source.y, source.x)) % 360.0
|
||||
else:
|
||||
heading = rng.uniform(0.0, 360.0)
|
||||
sources[index] = source.__class__(channel=source.channel, x=source.x,
|
||||
y=source.y, r_eff_m=source.r_eff_m,
|
||||
directional=True, heading_deg=heading)
|
||||
return sources
|
||||
Reference in New Issue
Block a user