/
GeekNerd
/
ServerModelingProject
Обзор
Документация
Войти
/
GeekNerd
/
ServerModelingProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Assets/Scripts/OptimizationLogic/Core/TopologyValidator.cs
65 строк
2 KB
Gorney-Alex
Init
30 май 2026, 19:05
30 май 2026, 19:05
3cdcc49
Код
Авторство
О чём код?
using System.Collections.Generic; using DataClasses.Algorithm; using UnityEngine; namespace OptimizationLogic.Core { public sealed class TopologyValidator { public float RecirculationIndex { get; private set; } public float ComputeRecirculationIndex(IReadOnlyList<RackGene> genes, IReadOnlyList<PlacementZone> zones) { int placedCount = 0; int errorCount = 0; if (genes == null || zones == null) { RecirculationIndex = 0f; return RecirculationIndex; } for (int i = 0; i < genes.Count; i++) { RackGene g = genes[i]; if (!g.IsPlaced) continue; placedCount++; Vector2 front = Geometry2D.FrontVectorFromRotation(g.Rotation); Vector2 cold = GetZoneColdDirection(zones, g.ZoneId); if (placedCount <= 3) // log only first 3 to avoid spam { float dot = Vector2.Dot(front, cold); Debug.Log($"[Topology] rack[{i}] rot={g.Rotation}, front={front}, cold={cold}, dot={dot:F3}, isError={dot >= 0f}"); } // ColdAirDirection is the cold airflow direction (from CRAC toward the zone). // Rack front should face INTO the cold flow (i.e., opposite the flow direction). // Therefore dot(front, cold) < 0 is correct, and dot >= 0 is a topology error. if (Vector2.Dot(front, cold) >= 0f) errorCount++; } RecirculationIndex = placedCount == 0 ? 0f : (float)errorCount / placedCount; return RecirculationIndex; } public float ComputeTopologyFitness(IReadOnlyList<RackGene> genes, IReadOnlyList<PlacementZone> zones) { float ri = ComputeRecirculationIndex(genes, zones); return Mathf.Clamp01(1f - ri); } private static Vector2 GetZoneColdDirection(IReadOnlyList<PlacementZone> zones, int zoneId) { for (int i = 0; i < zones.Count; i++) { if (zones[i].ZoneId == zoneId) return Geometry2D.SafeNormalize(zones[i].ColdAirDirection, Vector2.up); } return Vector2.up; } } }