|
@@ -58,7 +58,9 @@
|
|
|
<view class="section" v-if="outputData.length > 0">
|
|
|
|
|
|
<div style="display: flex;justify-content: space-between;">
|
|
|
- <text class="section-title">输出</text>
|
|
|
+ <text class="section-title">输出 </text>
|
|
|
+ 计算时间 {{timer}} ms
|
|
|
+
|
|
|
<span>差额: {{ powerDifference }}</span>
|
|
|
</div>
|
|
|
|
|
@@ -126,7 +128,55 @@ const type = ref('')
|
|
|
const genderOptions = ['公', '母'];
|
|
|
const roleOptions = ['目标角色', '备选角色'];
|
|
|
|
|
|
-const inputData = ref([]);
|
|
|
+
|
|
|
+const timer = ref(0)
|
|
|
+
|
|
|
+
|
|
|
+const mockData = [
|
|
|
+ {
|
|
|
+ "backupFemale": "121",
|
|
|
+ "backupMale": "153",
|
|
|
+ "targetFemale": "86",
|
|
|
+ "targetMale": "138"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": "118",
|
|
|
+ "backupMale": "91",
|
|
|
+ "targetFemale": "84",
|
|
|
+ "targetMale": "90"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": "115",
|
|
|
+ "backupMale": "77",
|
|
|
+ "targetFemale": "84"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "targetFemale": "59"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "targetFemale": "53"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "targetFemale": "51"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": null,
|
|
|
+ "backupMale": null
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": null,
|
|
|
+ "backupMale": null
|
|
|
+ }
|
|
|
+]
|
|
|
+
|
|
|
+
|
|
|
+const inputData = ref(mockData);
|
|
|
const outputData = ref([]);
|
|
|
|
|
|
const batchRef = ref(null)
|
|
@@ -275,9 +325,13 @@ function handleConfirm(){
|
|
|
batchRef.value.close()
|
|
|
}
|
|
|
|
|
|
-function calculateBestMatch() {
|
|
|
+async function calculateBestMatch() {
|
|
|
+ let startTime = new Date().getTime()
|
|
|
+
|
|
|
+
|
|
|
+ let endTime = null
|
|
|
+
|
|
|
outputData.value = []
|
|
|
-
|
|
|
const targetData = []
|
|
|
const backupData = []
|
|
|
|
|
@@ -299,17 +353,22 @@ function calculateBestMatch() {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
let target = null
|
|
|
let backup = null
|
|
|
|
|
|
+ let isTansfer = false
|
|
|
+
|
|
|
if(targetData.length > backupData.length){
|
|
|
+ isTansfer = true
|
|
|
target = backupData
|
|
|
backup = targetData
|
|
|
} else {
|
|
|
target = targetData
|
|
|
backup = backupData
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
const result = [];
|
|
|
|
|
@@ -335,6 +394,7 @@ function calculateBestMatch() {
|
|
|
});
|
|
|
costMatrixFemaleMale.push(row);
|
|
|
});
|
|
|
+
|
|
|
|
|
|
// 匹配函数:尽量匹配并返回匹配结果
|
|
|
function matchBestPairs(costMatrix, targetGroup, backupGroup) {
|
|
@@ -344,6 +404,8 @@ function calculateBestMatch() {
|
|
|
let minDiff = Infinity;
|
|
|
let minTargetIdx = -1;
|
|
|
let minBackupIdx = -1;
|
|
|
+
|
|
|
+
|
|
|
for (let i = 0; i < targetGroup.length; i++) {
|
|
|
for (let j = 0; j < backupGroup.length; j++) {
|
|
|
if (costMatrix[i][j] < minDiff) {
|
|
@@ -352,12 +414,17 @@ function calculateBestMatch() {
|
|
|
minBackupIdx = j;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ console.log(targetGroup[minTargetIdx], backupGroup[minBackupIdx])
|
|
|
// 记录最小差值的匹配并移除对应元素
|
|
|
result.push({ target: targetGroup[minTargetIdx], backup: backupGroup[minBackupIdx] });
|
|
|
+
|
|
|
targetGroup.splice(minTargetIdx, 1);
|
|
|
backupGroup.splice(minBackupIdx, 1);
|
|
|
+
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
@@ -365,53 +432,19 @@ function calculateBestMatch() {
|
|
|
// 匹配公对母,母对公
|
|
|
const maleFemaleMatches = matchBestPairs(costMatrixMaleFemale, targetMale, backupFemale);
|
|
|
const femaleMaleMatches = matchBestPairs(costMatrixFemaleMale, targetFemale, backupMale);
|
|
|
-
|
|
|
+
|
|
|
// 合并匹配结果
|
|
|
result.push(...maleFemaleMatches, ...femaleMaleMatches);
|
|
|
-
|
|
|
- // 如果 target 中有剩余,尝试与 backup 中未匹配的项配对
|
|
|
- const unmatchedTargetMale = targetMale.length > 0 ? targetMale : targetFemale;
|
|
|
- const unmatchedBackup = backup.filter(b => !b.matched); // 剩余的未匹配项
|
|
|
-
|
|
|
- // 最小化剩余匹配差值
|
|
|
- while (unmatchedTargetMale.length > 0 && unmatchedBackup.length > 0) {
|
|
|
- let minDiff = Infinity;
|
|
|
- let minTargetIdx = -1;
|
|
|
- let minBackupIdx = -1;
|
|
|
-
|
|
|
- for (let i = 0; i < unmatchedTargetMale.length; i++) {
|
|
|
- for (let j = 0; j < unmatchedBackup.length; j++) {
|
|
|
- const diff = Math.abs(unmatchedTargetMale[i].power - unmatchedBackup[j].power);
|
|
|
- if (diff < minDiff) {
|
|
|
- minDiff = diff;
|
|
|
- minTargetIdx = i;
|
|
|
- minBackupIdx = j;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 记录最小差值的匹配
|
|
|
- result.push({
|
|
|
- target: unmatchedTargetMale[minTargetIdx],
|
|
|
- backup: unmatchedBackup[minBackupIdx],
|
|
|
- });
|
|
|
-
|
|
|
- // 从剩余数据中移除匹配项
|
|
|
- unmatchedTargetMale.splice(minTargetIdx, 1);
|
|
|
- unmatchedBackup.splice(minBackupIdx, 1);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
let totalTargetPower = 0
|
|
|
let totalBackupPower = 0
|
|
|
|
|
|
result.forEach(item => {
|
|
|
outputData.value.push({
|
|
|
- targetGender: item.target.gender,
|
|
|
- targetPower: item.target.power,
|
|
|
- backupGender: item.backup.gender,
|
|
|
- backupPower: item.backup.power,
|
|
|
+ targetGender: isTansfer ? item.backup.gender : item.target.gender,
|
|
|
+ targetPower: isTansfer ? item.backup.power : item.target.power,
|
|
|
+ backupGender:isTansfer ? item.target.gender : item.backup.gender,
|
|
|
+ backupPower:isTansfer ? item.target.power : item.backup.power,
|
|
|
})
|
|
|
})
|
|
|
|
|
@@ -432,7 +465,15 @@ function calculateBestMatch() {
|
|
|
backupGender: '',
|
|
|
backupPower: totalBackupPower,
|
|
|
})
|
|
|
+
|
|
|
+
|
|
|
+ endTime = new Date().getTime()
|
|
|
+
|
|
|
|
|
|
+ const calc = endTime - startTime
|
|
|
+
|
|
|
+
|
|
|
+ timer.value = calc
|
|
|
}
|
|
|
</script>
|
|
|
|