Skip to content

Commit

Permalink
枚举性能优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Funny-ppt committed Mar 23, 2024
1 parent 65fb305 commit 2c3b35c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions InfrastSim/TimeDriven/Enumerate/EnumerateContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ public Frame(OpEnumData[] comb, Efficiency base_eff, int ucnt) {
uset[op.uid] = true;
}
}
public Frame FromComb(OpEnumData[] new_comb, Efficiency base_eff) {
public Frame FromComb(OpEnumData[] new_comb, Efficiency base_eff, int gid) {
var op = new_comb[^1];
BitArray new_uset = new(uset);
new_uset[op.uid] = true;
return new Frame {
comb = new_comb,
base_eff = base_eff,
gid = new_comb.Length << 24 | (gid & 0xffffff) * op.prime % MOD,
gid = gid,
init_size = init_size,
uset = new_uset
};
Expand Down Expand Up @@ -185,11 +185,12 @@ IEnumerable<Frame> ProcessFrame(Simulator simu, Frame frame) {
foreach (var op in ops) {
if (frame.uset[op.uid]) continue; // 处理干员表中有同一干员的不同位置

OpEnumData[] next_comb = [.. frame.comb, op];
var gid = GetGroupId(next_comb);
var gid = (frame.comb.Length + 1 << 24) | (frame.gid & 0xffffff) * op.prime % MOD;
if (!results.TryAdd(gid, default)) {
continue;
}

OpEnumData[] next_comb = [.. frame.comb, op];
Efficiency eff;
try { // 检验组合是否能被基建容纳,如果可以,则计算其效率
eff = TestMany(simu, next_comb);
Expand All @@ -208,7 +209,7 @@ IEnumerable<Frame> ProcessFrame(Simulator simu, Frame frame) {
tot_extra_eff -= opd.SingleEfficiency;
}
results[gid] = new(next_comb, frame.init_size, eff, tot_extra_eff);
if (next_comb.Length < max_size) yield return frame.FromComb(next_comb, eff);
if (next_comb.Length < max_size) yield return frame.FromComb(next_comb, eff, gid);
}
}
}

0 comments on commit 2c3b35c

Please sign in to comment.