using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using NPP.SmartSchedue.Api.Contracts.Domain.Work; namespace NPP.SmartSchedue.Api.Contracts.Services.Integration.Input { /// /// 全局优化分配输入 /// public class GlobalAllocationInput { /// /// 待分配的任务ID列表(当Tasks为空时使用) /// public List TaskIds { get; set; } = new(); /// /// 待分配的任务对象列表(性能优化:避免重复数据库查询) /// public List Tasks { get; set; } = new(); /// /// 排除的人员ID列表 /// public List ExcludedPersonnelIds { get; set; } = new(); /// /// 全局优化配置 /// public GlobalOptimizationConfig OptimizationConfig { get; set; } = new(); } /// /// 全局优化配置 /// public class GlobalOptimizationConfig { /// /// 遗传算法种群大小 /// 生产环境推荐:小规模(20任务)使用50-100,中规模(50-100任务)使用80-150 /// [Range(50, 500, ErrorMessage = "种群大小应在50-500之间")] public int PopulationSize { get; set; } = 100; // 从200降低到100,适合100任务规模 /// /// 最大迭代代数 /// 生产环境推荐:由于预筛选机制,可以适当减少迭代次数 /// [Range(20, 200, ErrorMessage = "迭代代数应在20-200之间")] public int MaxGenerations { get; set; } = 60; // 从100降低到60,在质量和性能间平衡 /// /// 最大执行时间(秒) /// 生产环境:为100任务增加更宽裕的时间限制 /// [Range(5, 300, ErrorMessage = "执行时间应在5-300秒之间")] public int MaxExecutionTimeSeconds { get; set; } = 120; // 从30秒增加到120秒,适应100任务的复杂度 /// /// 基尼系数公平性权重(0-1) /// [Range(0.0, 1.0, ErrorMessage = "公平性权重应在0-1之间")] public double FairnessWeight { get; set; } = 0.3; /// /// 约束满足权重(0-1) /// [Range(0.0, 1.0, ErrorMessage = "约束权重应在0-1之间")] public double ConstraintWeight { get; set; } = 0.6; /// /// 资质匹配权重(0-1) /// [Range(0.0, 1.0, ErrorMessage = "资质权重应在0-1之间")] public double QualificationWeight { get; set; } = 0.1; /// /// 是否启用智能协商 /// public bool EnableIntelligentNegotiation { get; set; } = true; /// /// 收敛阈值 /// [Range(0.001, 0.1, ErrorMessage = "收敛阈值应在0.001-0.1之间")] public double ConvergenceThreshold { get; set; } = 0.001; /// /// 创建适合生产环境的优化配置 /// 适用7天100任务30人员的大规模调度场景 /// /// 任务数量 /// 人员数量 /// 优化后的配置 public static GlobalOptimizationConfig CreateProductionConfig(int taskCount, int personnelCount) { var config = new GlobalOptimizationConfig(); // 根据任务规模动态调整参数 if (taskCount <= 20) { // 小规模:超快速模式(针对6个任务优化) if (taskCount <= 6) { config.PopulationSize = 15; // 从50降到15,减少计算量 config.MaxGenerations = 10; // 从30降到10,快速收敛 config.MaxExecutionTimeSeconds = 15; // 从60降到15秒 } else { config.PopulationSize = 30; // 7-20任务使用中等参数 config.MaxGenerations = 20; config.MaxExecutionTimeSeconds = 30; } } else if (taskCount <= 50) { // 中规模:平衡模式 config.PopulationSize = 80; config.MaxGenerations = 50; config.MaxExecutionTimeSeconds = 90; } else if (taskCount <= 100) { // 大规模:高质量模式(适合生产环境) config.PopulationSize = 100; config.MaxGenerations = 60; config.MaxExecutionTimeSeconds = 120; } else { // 超大规模:保守模式 config.PopulationSize = Math.Min(150, taskCount + 50); config.MaxGenerations = 80; config.MaxExecutionTimeSeconds = 180; } // 根据人员数量调整权重 if (personnelCount < 20) { // 人员较少,提高公平性权重 config.FairnessWeight = 0.4; config.ConstraintWeight = 0.5; config.QualificationWeight = 0.1; } else { // 人员充足,保持默认权重 config.FairnessWeight = 0.3; config.ConstraintWeight = 0.6; config.QualificationWeight = 0.1; } return config; } /// /// 创建快速测试配置(用于开发和测试环境) /// /// 快速测试配置 public static GlobalOptimizationConfig CreateFastTestConfig() { return new GlobalOptimizationConfig { PopulationSize = 30, MaxGenerations = 20, MaxExecutionTimeSeconds = 30, FairnessWeight = 0.2, ConstraintWeight = 0.7, QualificationWeight = 0.1, ConvergenceThreshold = 0.01 // 更宽松的收敛条件以加速测试 }; } /// /// 创建高质量配置(用于关键业务场景) /// /// 高质量配置 public static GlobalOptimizationConfig CreateHighQualityConfig() { return new GlobalOptimizationConfig { PopulationSize = 200, MaxGenerations = 100, MaxExecutionTimeSeconds = 300, FairnessWeight = 0.35, ConstraintWeight = 0.55, QualificationWeight = 0.1, ConvergenceThreshold = 0.0005 }; } } }