import json import numpy as np # 行是方案,列是越大越好的指标。权重之和为 1。 x = np.array([[3, 1], [4, 4], [1, 3]], dtype=float) weights = np.array([.6, .4]) weighted = x / np.linalg.norm(x, axis=0) * weights ideal = weighted.max(axis=0) worst = weighted.min(axis=0) distance_best = np.linalg.norm(weighted - ideal, axis=1) distance_worst = np.linalg.norm(weighted - worst, axis=1) # 理想点得 1,负理想点得 0,其他方案在两者之间。 score = distance_worst / (distance_best + distance_worst) assert score.argmax() == 1 and score[1] == 1 result = {"ideal": ideal.tolist(), "distance_best": distance_best.tolist(), "score": score.tolist()} print("LAB_RESULT " + json.dumps(result, ensure_ascii=False))