用简化的主模型版本实现主模型的算法

时间:2019-04-19 13:02:25

标签: javascript algorithm

例如,存在以下模型:

var mainModel = {
  fulfilledTotal: 0,
  sectionA: {
   fulfilled: false,
   upperLimit: 300,
   expected: 100,
   current: 0
  },
  sectionB: {
   fulfilled: false,
   expected: 20,
   current: 0
  },
  sectionC: {
   fulfilled: false,
   expected: 1000,
   current: 0
  }
  ...
}

此外,遵循主模型结构的较小模型还包含一些值:

var subModelA = {
  sectionA: {
   current: 10
  },
  sectionB: {
   current: 20
  }
}

var subModelB = {
  sectionB: {
   current: 30
  },
  sectionC: {
   current: 400
  }
}

实际上,主模型包含大约140个值,而可能有100多个潜在可用的子模型,每个子模型具有大约40-100个值。所有这些使我想知道什么是实现一种可能的知道的适当方法:

应将子模型组合(例如20)添加到mainModel中多少次,以使值current大致等于expected

P.S:我并不期望实际的解决方案,而是一些可能存在的算法或一般想法,该如何解决此类问题。

任何好的文章都非常值得赞赏:bowing:

更新
感谢trincot问题:
What would be the evaluation formula for choosing the final results?

对于特定情况,在执行之前定义acceptance range是合理的。

可能的示例:
假设我们将acceptance range设置为10%。因此,如果expected = 100current = 105 => 90 < 105 < 110 && 105 < upperLimit,则满足mainModel对象的一部分。并且fulfilledTotal的数量增加。

因此,最后选择fulfilledTotal最多的结果作为最终结果。

0 个答案:

没有答案