Implement sorting by size
This AI bullshit will be the end of me...
This commit is contained in:
@@ -324,7 +324,8 @@ class ModList {
|
||||
int total = scoreInfo['total']!;
|
||||
|
||||
if (total == 0 || bestScore == total) {
|
||||
return bestOrder; // All constraints satisfied or no constraints
|
||||
// All constraints satisfied or no constraints, sort by size where possible
|
||||
return _sortSizeWithinConstraints(bestOrder);
|
||||
}
|
||||
|
||||
// Use a limited number of improvement passes
|
||||
@@ -397,7 +398,77 @@ class ModList {
|
||||
if (!improved) break; // If no improvements in this pass, stop
|
||||
}
|
||||
|
||||
return bestOrder;
|
||||
// After optimizing for soft constraints, sort by size where possible
|
||||
return _sortSizeWithinConstraints(bestOrder);
|
||||
}
|
||||
|
||||
/// Sort mods by size within compatible groups
|
||||
List<String> _sortSizeWithinConstraints(List<String> order) {
|
||||
// Find groups of mods that can be reordered without breaking constraints
|
||||
List<List<String>> groups = [];
|
||||
List<String> currentGroup = [];
|
||||
|
||||
for (int i = 0; i < order.length; i++) {
|
||||
String modId = order[i];
|
||||
Mod mod = mods[modId]!;
|
||||
|
||||
if (currentGroup.isEmpty) {
|
||||
currentGroup.add(modId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if this mod can join the current group
|
||||
bool canJoin = true;
|
||||
for (String groupModId in currentGroup) {
|
||||
Mod groupMod = mods[groupModId]!;
|
||||
|
||||
// Check hard dependencies
|
||||
if (mod.dependencies.contains(groupModId) ||
|
||||
groupMod.dependencies.contains(modId)) {
|
||||
canJoin = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Check soft constraints
|
||||
if (mod.loadAfter.contains(groupModId) ||
|
||||
groupMod.loadBefore.contains(modId) ||
|
||||
mod.loadBefore.contains(groupModId) ||
|
||||
groupMod.loadAfter.contains(modId)) {
|
||||
canJoin = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (canJoin) {
|
||||
currentGroup.add(modId);
|
||||
} else {
|
||||
// Start a new group
|
||||
if (currentGroup.isNotEmpty) {
|
||||
groups.add(List.from(currentGroup));
|
||||
currentGroup = [modId];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the last group if not empty
|
||||
if (currentGroup.isNotEmpty) {
|
||||
groups.add(currentGroup);
|
||||
}
|
||||
|
||||
// Sort each group by size
|
||||
for (List<String> group in groups) {
|
||||
if (group.length > 1) {
|
||||
group.sort((a, b) => mods[b]!.size.compareTo(mods[a]!.size));
|
||||
}
|
||||
}
|
||||
|
||||
// Reconstruct the order
|
||||
List<String> result = [];
|
||||
for (List<String> group in groups) {
|
||||
result.addAll(group);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
List<String> loadDependencies(
|
||||
|
Reference in New Issue
Block a user