//默认参数使机器数量尽量少,成本分数可以通过搜索降下来 //对Pre A,不对实例排序结果反而更好 public static Solution Fit(double cpuUtilH = 0.5, double cpuUtilL = 0.78, int vipDisk = 300, int vipMem = 12, int vipCpu = 7, bool saveSubmitCsv = false) { // var sol = InitSolution.Clone(); var machines = sol.Machines; var appInsts = sol.AppInsts; foreach (var m in machines) { m.CpuUtilLimit = m.IsLargeMachine ? cpuUtilH : cpuUtilL; } var vips = (from inst in appInsts where !inst.IsDeployed && (inst.R.Disk >= vipDisk || inst.R.Mem.Avg >= vipMem || inst.R.Cpu.Avg >= vipCpu) select inst).ToList(); BinPacking.FirstFit(vips, machines, onlyIdleMachine: true); BinPacking.FirstFit(appInsts, machines); var msg = $"==Fit@{cpuUtilH:0.00},{cpuUtilL:0.00},{vipDisk},{vipMem},{vipCpu}== "; if (!sol.AllAppInstDeployed) { var undeployed = sol.AppInstCount - sol.DeployedAppInstCount; msg += $"undeployed: {undeployed} = " + $" {sol.AppInstCount} - {sol.DeployedAppInstCount}\t e.g. "; msg += sol.UndeployedAppInst[index : 0].ToString(); } msg += $"\t{sol.ActualScore:0.00},{sol.MachineCountHasApp}"; WriteLine(msg); if (saveSubmitCsv) { Solution.SaveAndJudgeApp(sol); } return(sol); }
public static Solution Fit(double cpuUtilH = 0.65, double cpuUtilL = 0.65, bool saveSubmitCsv = false) { var sol = DataSet.InitSolution.Clone(); var machines = sol.Machines; var appInsts = sol.AppInsts; foreach (var m in machines) { m.CpuUtilLimit = m.IsLargeMachine ? cpuUtilH : cpuUtilL; } var instList = HighCpuUtilAppInsts(machines, Min(cpuUtilH, cpuUtilL)); BinPacking.FirstFit(instList, machines, forceMigrate: true); BinPacking.FirstFit(appInsts, machines); var msg = $"==Fit@{cpuUtilH:0.00},{cpuUtilL:0.00}== "; if (!sol.AllAppInstDeployed) { var undeployed = sol.AppInstCount - sol.DeployedAppInstCount; msg += $"undeployed: {undeployed} = " + $" {sol.AppInstCount} - {sol.DeployedAppInstCount}\t e.g. "; msg += sol.UndeployedAppInst[index : 0].ToString(); } msg += $"\t{sol.ActualScore:0.00},{sol.MachineCountHasApp}"; WriteLine(msg); if (saveSubmitCsv) { Solution.SaveAndJudgeApp(sol); } return(sol); }