寻找针对海军作战中的船只的最佳解决方案

时间:2019-05-07 19:13:17

标签: algorithm optimization

我在n和m舰队的两个舰队之间交战,友军舰队中的每艘舰都有自己的齐射伤害,敌方舰队中的每艘舰都有自己的马力值。该算法的目标是找到最佳解决方案(如果存在这样的解决方案),以如何为您的舰船分配目标(例如:我舰队中的舰船1瞄准您舰队中的舰船3),从而使齐射最大化对敌方舰队造成的损失。

重要。所谓损害,是指一艘被摧毁的敌舰的​​伤害/马力值。如果敌舰的功率为100hp并产生20dmg,则其“值”为100/20 =5。因此,摧毁该舰将获得5分。最后,仅考虑被摧毁舰的分数。如果不可能一次齐射摧毁任何船只,那么分数将包括受损的船只。

我也尝试过贪婪方法,迭代改进方法和爬山方法,但是它们都无法达到最佳解决方案。我还尝试了另一种方法,其中制作了大量随机目标选择集并进行评估,然后从其中的全部中挑选出最佳的。这是产生最佳结果的方法,但是效率极低,几乎永远不会产生最佳结果。

我相信必须有一种计算最佳解决方案的方法,该方法不需要检查每个可能的目标选择,但我找不到这样做的方法。似乎这个问题就像多重背包问题的怪异形式。背包是敌人的hp池,物品是射击的dmg值。除了这次,放入背包的最后一个物品可以超过背包的尺寸限制,但是只有适合背包的物品价值的一部分有用。

即使不是解决问题的方法,也非常感谢您的任何想法或帮助!

3 个答案:

答案 0 :(得分:2)

Linear programming将在这里完美地完成工作。在这种情况下,决策变量是整数,因此我们要处理ILP
这是有关如何将问题建模为线性程序的简短描述。

Data:
F_dmg[n] // an array containing the damage of friendly ships
E_hp[m]  // an array containing the hp points of the ennemy ships
M        // constant, the highest hp among all ships
V[m]     // the 'value' of ennemy ships


Decision variables:
X[n][m]     // a matrix of booleans (0 or 1)
            // X[i][j] = 1 if the ship i attacks the ship j, 0 otherwise
Dmg[m]      // an array of integer, representing the total damage taken by each ennemy ship
IsAlive[m]  // an array of booleans, representing the fact that the ship is destroyed or not (0 if dead, 1 if alive)


Constraints:
// a friend ship can attack at most one ennemy ship
for all i in 1..n, sum(j in 1..m) X[i][j] <= 1
// the damage sustained by a ship cannot exceed its hp
for all j in 1..m, sum(i in 1..n) Dmg[m] <= E_hp[j]
// the damage sustained by a ship has to be coherent with the attacks it receives
for all j in 1..m, sum(i in 1..n) Dmg[j] <= X[i][j] * F_dmg[i]
// a ship is destroyed if the damage sustained is equal to its hp
for all j in 1..m, M * IsAlive[j] >= E_hp[j] - Dmg[j] 


Objective function
maximize sum(j in 1..m) (1 - IsAlive[j]) * V[j]

在OPL中编写该代码,将其输入到ILP求解器中,如果您输入的内容并非绝对巨大,您将很快获得最佳答案。

答案 1 :(得分:1)

这是Weapon Target Assignment Problem或与"Exact and Heuristic Algorithms for the Weapon Target Assignment Problem" (Ahuja, Kumar et al.)非常相似。

不幸的是,这个问题很难解决,根据2003年的论文or use @ConditionalOnProperty,即使只有20个武器和20个目标的实例也无法解决可证明的最优性。 (我只看摘要。)

答案 2 :(得分:0)

我必须非常类似于深度优先算法,该算法将尝试找到最佳路线,然后将为每艘船返回最佳路线并返回。每艘船应瞄准的目标阵列