splittintting

This commit is contained in:
33333-33333 2026-05-28 02:47:33 +09:00
commit d2e7a80e72
11 changed files with 1341 additions and 1349 deletions

View file

@ -748,6 +748,35 @@ export function splitOversizedPrefecturesByMunicipalityCount(nodes, owner, maxCo
return changed;
}
export function lockPrefectureCapitalNeighborMunicipalities(owner, nodes, seeds = [], maxNeighbors = 6) {
let changed = 0;
const seedIds = new Set((seeds || []).map((node) => node?.id).filter((id) => id !== undefined));
for (const seedNode of seeds || []) {
if (!seedNode || !nodes.has(seedNode.id)) continue;
const prefId = owner.get(seedNode.id);
if (prefId === undefined || prefId < 0) continue;
const neighbors = [...(nodes.get(seedNode.id)?.adjacent || [])]
.map(([id, edge]) => ({ node: nodes.get(id), id, edge }))
.filter((row) => row.node && owner.get(row.id) !== prefId && !seedIds.has(row.id))
.sort((a, b) => (a.edge.crossingCost ?? 1) - (b.edge.crossingCost ?? 1) || Math.hypot(a.node.x - seedNode.x, a.node.y - seedNode.y) - Math.hypot(b.node.x - seedNode.x, b.node.y - seedNode.y));
let taken = 0;
for (const row of neighbors) {
if (taken >= maxNeighbors) break;
const donorPref = owner.get(row.id);
if (donorPref === undefined || donorPref < 0 || donorPref === prefId) continue;
if (!wouldRemainConnectedAfterRemoval(nodes, owner, row.id, donorPref)) continue;
owner.set(row.id, prefId);
changed++;
taken++;
}
}
if (changed) {
repairPrefectureMunicipalityConnectivity(nodes, owner);
repairPrefectureMunicipalityEnclaves(nodes, owner, 6);
}
return changed;
}
function averageRegionalBorderField(adminId, municipalityToPrefectureId, prefectureMask, sea, field) {
if (!field) return 0;
let sum = 0;
@ -803,6 +832,10 @@ export function generatePrefecturesFromMunicipalities(context, adminResult) {
changedForConnectivity += repairPrefectureMunicipalityConnectivity(graph.nodes, owner);
changedForEnclaveRepair += repairPrefectureMunicipalityEnclaves(graph.nodes, owner, 10);
changedForConnectivity += repairPrefectureMunicipalityConnectivity(graph.nodes, owner);
const changedForCapitalNeighborLock = lockPrefectureCapitalNeighborMunicipalities(owner, graph.nodes, seeds, 7);
changedForConnectivity += repairPrefectureMunicipalityConnectivity(graph.nodes, owner);
changedForEnclaveRepair += repairPrefectureMunicipalityEnclaves(graph.nodes, owner, 12);
changedForConnectivity += repairPrefectureMunicipalityConnectivity(graph.nodes, owner);
const maxAdminId = Math.max(-1, ...[...graph.nodes.keys()]);
const municipalityToPrefectureId = new Int16Array(maxAdminId + 1);
municipalityToPrefectureId.fill(-1);
@ -846,6 +879,7 @@ export function generatePrefecturesFromMunicipalities(context, adminResult) {
prefectureMunicipalityCountRebalanceChangedMunicipalities: (changedForMunicipalityCountRebalance || 0) + (changedForPostMergeMunicipalityCountRebalance || 0),
prefectureTinyMunicipalityCountMergeChangedMunicipalities: changedForTinyPrefectureCountMerge || 0,
prefectureOversizedCountSplitChangedMunicipalities: changedForOversizedPrefectureSplit || 0,
prefectureCapitalNeighborLockChangedMunicipalities: changedForCapitalNeighborLock || 0,
finalRegionalMaxMunicipalityCount: Math.max(...prefectureMunicipalityCounts(owner).values()),
finalRegionalMunicipalityCountCap: 88,
finalRegionalMinMunicipalityCount: Math.min(...prefectureMunicipalityCounts(owner).values()),