|
@@ -48,8 +48,9 @@
|
|
|
<el-button type="primary" style="width:100%;margin-bottom: 10px;margin-top:10px" @click="switchRoles">
|
|
|
交换角色
|
|
|
</el-button>
|
|
|
-
|
|
|
- <el-button type="primary" style="width:100%;margin-bottom: 10px;margin-top:10px" @click="calculateBestMatch">
|
|
|
+
|
|
|
+ <el-button type="primary" style="width:100%;margin-bottom: 10px;margin-top:10px"
|
|
|
+ @click="calculateBestMatch">
|
|
|
计算最佳配对
|
|
|
</el-button>
|
|
|
</div>
|
|
@@ -58,9 +59,7 @@
|
|
|
<view class="section" v-if="outputData.length > 0">
|
|
|
|
|
|
<div style="display: flex;justify-content: space-between;">
|
|
|
- <text class="section-title">输出 </text>
|
|
|
- 计算时间 {{timer}} ms
|
|
|
-
|
|
|
+ <text class="section-title">输出, 计算时间 {{}} ms </text>
|
|
|
<span>差额: {{ powerDifference }}</span>
|
|
|
</div>
|
|
|
|
|
@@ -69,6 +68,7 @@
|
|
|
<template #="{ $index }">{{ $index + 1 === outputData.length ? '合计' : $index + 1}}</template>
|
|
|
</el-table-column>
|
|
|
|
|
|
+
|
|
|
<el-table-column label="目标角色">
|
|
|
<el-table-column label="性别" min-width="60px" prop="targetGender" />
|
|
|
<el-table-column label="势力" min-width="60px" prop="targetPower" />
|
|
@@ -93,15 +93,11 @@
|
|
|
|
|
|
|
|
|
<span class="dialog-title">猫咪势力(公)</span>
|
|
|
- <textarea
|
|
|
- v-model="malePowers"
|
|
|
- placeholder="用逗号隔开,如:200,10,100"
|
|
|
+ <textarea v-model="malePowers" placeholder="用逗号隔开,如:200,10,100"
|
|
|
style="height: 70px;border: 1px solid #dfe2e5" />
|
|
|
|
|
|
<span class="dialog-title">猫咪势力(母)</span>
|
|
|
- <textarea
|
|
|
- v-model="feMalePowers"
|
|
|
- placeholder="用逗号隔开,如:200,10,100"
|
|
|
+ <textarea v-model="feMalePowers" placeholder="用逗号隔开,如:200,10,100"
|
|
|
style="height: 70px;border: 1px solid #dfe2e5" />
|
|
|
|
|
|
|
|
@@ -124,58 +120,134 @@ const feMalePowers = ref('')
|
|
|
const role = ref("")
|
|
|
|
|
|
const type = ref('')
|
|
|
-// 性别选项
|
|
|
-const genderOptions = ['公', '母'];
|
|
|
-const roleOptions = ['目标角色', '备选角色'];
|
|
|
-
|
|
|
-
|
|
|
-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
|
|
|
- }
|
|
|
+ {
|
|
|
+ "backupFemale": "180",
|
|
|
+ "backupMale": "174",
|
|
|
+ "targetFemale": "121",
|
|
|
+ "targetMale": "153"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": "165",
|
|
|
+ "backupMale": "152",
|
|
|
+ "targetFemale": "118",
|
|
|
+ "targetMale": "91"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": "158",
|
|
|
+ "backupMale": "147",
|
|
|
+ "targetFemale": "115",
|
|
|
+ "targetMale": "77"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": "154",
|
|
|
+ "backupMale": "102",
|
|
|
+ "targetFemale": "86",
|
|
|
+ "targetMale": "138"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": "152",
|
|
|
+ "backupMale": "101",
|
|
|
+ "targetFemale": "84",
|
|
|
+ "targetMale": "90"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": "151",
|
|
|
+ "backupMale": "98",
|
|
|
+ "targetFemale": "84",
|
|
|
+ "targetMale": "80"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": "150",
|
|
|
+ "backupMale": "98",
|
|
|
+ "targetMale": "60",
|
|
|
+ "targetFemale": "59"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "backupFemale": "150",
|
|
|
+ "backupMale": "97",
|
|
|
+ "targetMale": "54",
|
|
|
+ "targetFemale": "53"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": "52",
|
|
|
+ "targetFemale": "51",
|
|
|
+ "backupMale": "62",
|
|
|
+ "backupFemale": "102"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": "52",
|
|
|
+ "backupMale": "60",
|
|
|
+ "backupFemale": "101"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": "52",
|
|
|
+ "backupMale": "58",
|
|
|
+ "backupFemale": "101"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": null,
|
|
|
+ "targetFemale": null,
|
|
|
+ "backupMale": "19",
|
|
|
+ "backupFemale": "93"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": null,
|
|
|
+ "targetFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "backupFemale": "61"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": null,
|
|
|
+ "targetFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "backupFemale": "30"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": null,
|
|
|
+ "targetFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "backupFemale": "30"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": null,
|
|
|
+ "targetFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "backupFemale": "29"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": null,
|
|
|
+ "targetFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "backupFemale": "29"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": null,
|
|
|
+ "targetFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "backupFemale": "29"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": null,
|
|
|
+ "targetFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "backupFemale": "27"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": null,
|
|
|
+ "targetFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "backupFemale": "10"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "targetMale": null,
|
|
|
+ "targetFemale": null,
|
|
|
+ "backupMale": null,
|
|
|
+ "backupFemale": "10"
|
|
|
+ }
|
|
|
]
|
|
|
|
|
|
-
|
|
|
const inputData = ref(mockData);
|
|
|
const outputData = ref([]);
|
|
|
|
|
@@ -194,7 +266,7 @@ function editRow(_gender, _role) {
|
|
|
|
|
|
|
|
|
function switchRoles(){
|
|
|
- const cloneInputData = inputData.value.map(item => ({ ...item }))
|
|
|
+ // const cloneInputData = inputData.value.map(item => ({ ...item }))
|
|
|
const backups = inputData.value.map(item => ({ male: item.backupMale, female: item.backupFemale }))
|
|
|
const targets = inputData.value.map(item => ({ male: item.targetMale, female: item.targetFemale }))
|
|
|
|
|
@@ -207,18 +279,7 @@ function switchRoles(){
|
|
|
|
|
|
}
|
|
|
|
|
|
-// 计算属性
|
|
|
-const totalTargetPower = computed(() => {
|
|
|
- return outputData.value.reduce((sum, item) => (sum + item.targetGender ? (Number(item.targetPower) || 0) : 0), 0);
|
|
|
-});
|
|
|
-
|
|
|
-const totalBackupPower = computed(() => {
|
|
|
- return outputData.value.reduce((sum, item) => sum + (item.backupGender ? (Number(item.backupPower) || 0) : 0), 0);
|
|
|
-});
|
|
|
-
|
|
|
-const powerDifference = computed(() => {
|
|
|
- return totalTargetPower.value - totalBackupPower.value
|
|
|
-});
|
|
|
+const powerDifference = ref(0)
|
|
|
|
|
|
// 目标角色操作
|
|
|
const addTargetRow = () => {
|
|
@@ -236,22 +297,13 @@ function isPositiveInteger(str) {
|
|
|
function generatePowers(_powers, gender){
|
|
|
const keys = ['targetMale', 'targetFemale', 'backupMale', 'backupFemale']
|
|
|
|
|
|
- _powers = _powers.replace(/,/g, ',')
|
|
|
- const powerSet = _powers.split(',')
|
|
|
-
|
|
|
+ _powers = _powers.replace(/,|、|,/g, ',')
|
|
|
+ const powerSet = _powers.split(',').map(item => item.trim()).filter(item => item !== '')
|
|
|
|
|
|
const isOk = powerSet.every(num => isPositiveInteger(num))
|
|
|
|
|
|
+ if (!isOk && powerSet.length !== 0) return false
|
|
|
|
|
|
-
|
|
|
- if(!isOk) return false
|
|
|
-
|
|
|
- // if(!isOk){
|
|
|
- // ElMessage.warning('势力必须为正整数')
|
|
|
- // return
|
|
|
- // }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
const roleProp = role.value === '目标角色' ? 'target' : 'backup'
|
|
|
const genderProp = gender === '公' ? 'Male' : 'Female'
|
|
@@ -310,7 +362,7 @@ function handleConfirm(){
|
|
|
const _malePowers = malePowers.value.trim()
|
|
|
const _feMalePowers = feMalePowers.value.trim()
|
|
|
|
|
|
- const isMaleOk = generatePowers(_malePowers, '公')
|
|
|
+ const isMaleOk = generatePowers(_malePowers, '公')
|
|
|
const isFemakeOk = generatePowers(_feMalePowers, '母')
|
|
|
|
|
|
if(typeof isMaleOk === 'boolean' && !isMaleOk){
|
|
@@ -325,155 +377,171 @@ function handleConfirm(){
|
|
|
batchRef.value.close()
|
|
|
}
|
|
|
|
|
|
-async function calculateBestMatch() {
|
|
|
- let startTime = new Date().getTime()
|
|
|
-
|
|
|
-
|
|
|
- let endTime = null
|
|
|
-
|
|
|
+// 生成数组的所有组合(辅助函数,用于生成指定个数元素的组合情况)
|
|
|
+function getCombinations(arr, num) {
|
|
|
+ const result = [];
|
|
|
+ if (num === 0) { return [[]]; }
|
|
|
+
|
|
|
+
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ const element = arr[i];
|
|
|
+
|
|
|
+ const remainingCombos = getCombinations(arr.slice(i + 1), num - 1);
|
|
|
+
|
|
|
+ for (const combo of remainingCombos) {
|
|
|
+ result.push([element].concat(combo));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function calculateBestMatch() {
|
|
|
outputData.value = []
|
|
|
+
|
|
|
const targetData = []
|
|
|
const backupData = []
|
|
|
|
|
|
inputData.value.forEach(item => {
|
|
|
- if(item.targetMale){ targetData.push({ gender: '公', power: item.targetMale }) }
|
|
|
- if(item.targetFemale){ targetData.push({ gender: '母', power: item.targetFemale }) }
|
|
|
- if(item.backupMale){ backupData.push({ gender: '公', power: item.backupMale }) }
|
|
|
- if(item.backupFemale){ backupData.push({ gender: '母', power: item.backupFemale }) }
|
|
|
+ if (item.targetMale) { targetData.push({ gender: '公', power: item.targetMale }) }
|
|
|
+ if (item.targetFemale) { targetData.push({ gender: '母', power: item.targetFemale }) }
|
|
|
+ if (item.backupMale) { backupData.push({ gender: '公', power: item.backupMale }) }
|
|
|
+ if (item.backupFemale) { backupData.push({ gender: '母', power: item.backupFemale }) }
|
|
|
})
|
|
|
|
|
|
- if (targetData.length === 0) {
|
|
|
- ElMessage.warning('至少添加一条目标角色数据')
|
|
|
+
|
|
|
+ const targetMale = targetData.filter(item => item.gender === '公').map(item => Number(item.power));
|
|
|
+ const targetFemale = targetData.filter(item => item.gender === '母').map(item => Number(item.power));
|
|
|
+ const backupMale = backupData.filter(item => item.gender === '公').map(item => Number(item.power));
|
|
|
+ const backupFemale = backupData.filter(item => item.gender === '母').map(item => Number(item.power));
|
|
|
+
|
|
|
+
|
|
|
+ // const targetMale = [153, 91, 77, 138, 90, 80, 60, 54, 52, 52, 52];
|
|
|
+ // const targetFemale = [121, 118, 115, 86, 84, 84, 59, 53, 51];
|
|
|
+ // const backupMale = [180, 165, 158, 154, 152, 151, 150, 150, 102, 101, 101, 93, 61, 30, 30, 29, 29, 29, 27, 10, 10];
|
|
|
+ // const backupFemale = [174, 152, 147, 102, 101, 98, 98, 97, 62, 60, 58, 19];
|
|
|
+
|
|
|
+ // const targetMale = [238, 90, 90];
|
|
|
+ // const targetFemale = [86, 84, 84];
|
|
|
+ // const backupMale = [153, 91, 77];
|
|
|
+ // const backupFemale = [121, 118, 115];
|
|
|
+
|
|
|
+
|
|
|
+ if (targetFemale.length > backupMale.length && backupMale.length !== 0){
|
|
|
+ ElMessage.warning('备选角色的公数据长度必须大于或等于目标角色的母数据')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if (backupData.length === 0) {
|
|
|
- ElMessage.warning('至少添加一条备选角色数据')
|
|
|
+ if (targetMale.length > backupFemale.length && backupFemale.length !== 0) {
|
|
|
+ ElMessage.warning('备选角色的母数据长度必须或等于大于目标角色的公数据')
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- 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 targetMaleLen = targetMale.length;
|
|
|
+ const targetFemaleLen = targetFemale.length;
|
|
|
+
|
|
|
+
|
|
|
+ let targetWeight = 0
|
|
|
+ if (backupMale.length === 0){
|
|
|
+ targetWeight = targetMale.reduce((acc, val) => acc + val, 0);
|
|
|
+ } else if(backupFemale.length === 0){
|
|
|
+ targetWeight = targetFemale.reduce((acc, val) => acc + val, 0)
|
|
|
+ } else if(backupMale.length !== 0 && backupFemale.length !== 0){
|
|
|
+ targetWeight = targetMale.reduce((acc, val) => acc + val, 0) + targetFemale.reduce((acc, val) => acc + val, 0);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
|
|
|
- const result = [];
|
|
|
-
|
|
|
- // 按性别分类
|
|
|
- const targetMale = target.filter(item => item.gender === '公');
|
|
|
- const targetFemale = target.filter(item => item.gender === '母');
|
|
|
- const backupMale = backup.filter(item => item.gender === '公');
|
|
|
- const backupFemale = backup.filter(item => item.gender === '母');
|
|
|
-
|
|
|
- // 计算匹配成本矩阵(power 差的绝对值)
|
|
|
- const costMatrixMaleFemale = [];
|
|
|
- targetMale.forEach(t => {
|
|
|
- const row = [];
|
|
|
- backupFemale.forEach(b => { row.push(Math.abs(t.power - b.power)); });
|
|
|
- costMatrixMaleFemale.push(row);
|
|
|
- });
|
|
|
-
|
|
|
- const costMatrixFemaleMale = [];
|
|
|
- targetFemale.forEach(t => {
|
|
|
- const row = [];
|
|
|
- backupMale.forEach(b => {
|
|
|
- row.push(Math.abs(t.power - b.power));
|
|
|
- });
|
|
|
- costMatrixFemaleMale.push(row);
|
|
|
- });
|
|
|
+ let minDifference = Infinity; // 初始化最小差额为正无穷大
|
|
|
+ let bestfemaleCombination = null;
|
|
|
+ let bestMaleCombination = null;
|
|
|
|
|
|
-
|
|
|
- // 匹配函数:尽量匹配并返回匹配结果
|
|
|
- function matchBestPairs(costMatrix, targetGroup, backupGroup) {
|
|
|
- const result = [];
|
|
|
- while (targetGroup.length > 0 && backupGroup.length > 0) {
|
|
|
- // 找到最小的 cost
|
|
|
- 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) {
|
|
|
- minDiff = costMatrix[i][j];
|
|
|
- minTargetIdx = i;
|
|
|
- minBackupIdx = j;
|
|
|
+ const femaleCombinations = getCombinations(backupFemale, targetMaleLen);
|
|
|
+ const maleCombinations = getCombinations(backupMale, targetFemaleLen);
|
|
|
+
|
|
|
+ if (femaleCombinations.length !== 0 && maleCombinations.length !== 0){
|
|
|
+ for (const femaleComb of femaleCombinations) {
|
|
|
+ for (const maleComb of maleCombinations) {
|
|
|
+ const totalWeight = femaleComb.reduce((acc, val) => acc + val, 0) + maleComb.reduce((acc, val) => acc + val, 0);
|
|
|
+ const difference = Math.abs(totalWeight - targetWeight);
|
|
|
+ if (difference < minDifference) {
|
|
|
+ minDifference = difference;
|
|
|
+ bestfemaleCombination = femaleComb;
|
|
|
+ bestMaleCombination = maleComb;
|
|
|
+ if (minDifference == 0) {
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- console.log(targetGroup[minTargetIdx], backupGroup[minBackupIdx])
|
|
|
- // 记录最小差值的匹配并移除对应元素
|
|
|
- result.push({ target: targetGroup[minTargetIdx], backup: backupGroup[minBackupIdx] });
|
|
|
-
|
|
|
- targetGroup.splice(minTargetIdx, 1);
|
|
|
- backupGroup.splice(minBackupIdx, 1);
|
|
|
-
|
|
|
+ // 备选数据的母为空
|
|
|
+ if (femaleCombinations.length === 0 && maleCombinations.length !== 0) {
|
|
|
+ for (const maleComb of maleCombinations) {
|
|
|
+ const totalWeight = maleComb.reduce((acc, val) => acc + val , 0);
|
|
|
+ const difference = Math.abs(totalWeight - targetWeight);
|
|
|
+ if (difference < minDifference) {
|
|
|
+ minDifference = difference;
|
|
|
+ bestMaleCombination = maleComb;
|
|
|
+ if (minDifference == 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- return result;
|
|
|
}
|
|
|
|
|
|
- // 匹配公对母,母对公
|
|
|
- const maleFemaleMatches = matchBestPairs(costMatrixMaleFemale, targetMale, backupFemale);
|
|
|
- const femaleMaleMatches = matchBestPairs(costMatrixFemaleMale, targetFemale, backupMale);
|
|
|
-
|
|
|
- // 合并匹配结果
|
|
|
- result.push(...maleFemaleMatches, ...femaleMaleMatches);
|
|
|
-
|
|
|
- let totalTargetPower = 0
|
|
|
- let totalBackupPower = 0
|
|
|
+ // 备选数据的公为空
|
|
|
+ if (femaleCombinations.length !== 0 && maleCombinations.length === 0) {
|
|
|
+ for (const femaleComb of femaleCombinations) {
|
|
|
+ const totalWeight = femaleComb.reduce((acc, val) => acc + val, 0)
|
|
|
+ const difference = Math.abs(totalWeight - targetWeight);
|
|
|
+ if (difference < minDifference) {
|
|
|
+ minDifference = difference;
|
|
|
+ bestfemaleCombination = femaleComb;
|
|
|
+ if (minDifference == 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bestMaleCombination && bestMaleCombination.sort((a, b) => a - b)
|
|
|
+ bestfemaleCombination && bestfemaleCombination.sort((a, b) => a - b)
|
|
|
+ targetMale.sort((a, b) => a - b)
|
|
|
+ targetFemale.sort((a, b) => a - b)
|
|
|
|
|
|
- result.forEach(item => {
|
|
|
+ if (!bestMaleCombination && !bestfemaleCombination){ return }
|
|
|
+
|
|
|
+
|
|
|
+ bestfemaleCombination && targetMale.forEach((_, index) => {
|
|
|
outputData.value.push({
|
|
|
- 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,
|
|
|
+ targetGender: '公',
|
|
|
+ targetPower: targetMale[index],
|
|
|
+ backupGender: '母',
|
|
|
+ backupPower: bestfemaleCombination[index]
|
|
|
})
|
|
|
- })
|
|
|
-
|
|
|
- outputData.value = outputData.value.filter(item => {
|
|
|
- if (item.targetGender === '公' && item.backupGender === '公') return false
|
|
|
- if (item.targetGender === '母' && item.backupGender === '母') return false
|
|
|
- return true
|
|
|
})
|
|
|
|
|
|
- outputData.value.forEach(item => {
|
|
|
- totalTargetPower = totalTargetPower + Number(item.targetPower)
|
|
|
- totalBackupPower = totalBackupPower + Number(item.backupPower)
|
|
|
+ bestMaleCombination && targetFemale.forEach((_, index) => {
|
|
|
+ outputData.value.push({
|
|
|
+ targetGender: '母',
|
|
|
+ targetPower: targetFemale[index],
|
|
|
+ backupGender: '公',
|
|
|
+ backupPower: bestMaleCombination[index]
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
+
|
|
|
+
|
|
|
outputData.value.push({
|
|
|
targetGender: '',
|
|
|
- targetPower: totalTargetPower,
|
|
|
+ targetPower: outputData.value.reduce((prev, current) => prev + current.targetPower,0),
|
|
|
backupGender: '',
|
|
|
- backupPower: totalBackupPower,
|
|
|
+ backupPower: outputData.value.reduce((prev, current) => prev + current.backupPower, 0),
|
|
|
})
|
|
|
-
|
|
|
-
|
|
|
- endTime = new Date().getTime()
|
|
|
-
|
|
|
|
|
|
- const calc = endTime - startTime
|
|
|
-
|
|
|
-
|
|
|
- timer.value = calc
|
|
|
+ powerDifference.value = minDifference
|
|
|
}
|
|
|
</script>
|
|
|
|