namespace PBS.Console.Test { public class Helper { private readonly int _numNodes; private readonly double[] _baseDemandValues; private readonly double[][] _precomputedDemands; #region 核心算法实现 private double[][] PrecomputeDemands(int totalRuns) { var rand = new Random(); var demandPool = new double[totalRuns][]; for (int i = 0; i < totalRuns; i++) { demandPool[i] = new double[_numNodes]; for (int n = 0; n < _numNodes; n++) { // 遗传算法式选择 int idx = rand.Next(_baseDemandValues.Length); // 20%概率变异 if (rand.NextDouble() < 0.2) idx = (idx + 1) % _baseDemandValues.Length; demandPool[i][n] = _baseDemandValues[idx]; } } return demandPool; } private double[][] PrecomputeDemands1(int totalRuns) { var rand = new Random(); var demandPool = new double[totalRuns][]; for (int i = 0; i < totalRuns; i++) { demandPool[i] = new double[_numNodes]; for (int n = 0; n < _numNodes; n++) { // 遗传算法式选择 int idx = rand.Next(_baseDemandValues.Length); // 20%概率变异 if (rand.NextDouble() < 0.2) idx = (idx + 1) % _baseDemandValues.Length; demandPool[i][n] = _baseDemandValues[idx]; } } return demandPool; } private double[,] GenerateAllDemands(int nodeCount, int totalIterations, double[] weValues) { double[,] demands = new double[totalIterations, nodeCount]; Parallel.For(0, totalIterations, iter => { var rand = new Random(); for (int node = 0; node < nodeCount; node++) { // 遗传算法式选择 int idx = rand.Next(weValues.Length); // 20%概率变异 if (rand.NextDouble() < 0.2) idx = (idx + 1) % weValues.Length; demands[iter, node] = weValues[idx]; } }); return demands; } #endregion #region 辅助类定义 public class SimulationResult { public int RunId { get; set; } public DateTime TimeStamp { get; set; } public double[] Pressures { get; } public double[] Flows { get; } public SimulationResult(int nodeCount) { Pressures = new double[nodeCount]; Flows = new double[nodeCount]; } } public class SensitivityResult { public double[] FirstOrderIndices { get; } public double[] TotalOrderIndices { get; } public SensitivityResult(int parameterCount) { FirstOrderIndices = new double[parameterCount]; TotalOrderIndices = new double[parameterCount]; } } private class SobolSequence { // Sobol序列生成实现(需根据具体数学库实现) public double[][] Generate(int samples) => throw new NotImplementedException(); } private SensitivityResult CalculateSobolIndices(double[][] inputs, List outputs) { // Sobol指数计算实现 throw new NotImplementedException(); } #endregion } }