简体   繁体   English

根据不同选择的结果约束 optaplanner 的选择 - Constraint Propagation / Local Consistency

[英]Constraining optaplanner's choices based on the result of different choices - Constraint Propagation / Local Consistency

I have an optimization problem that I'm working on in which the optimizer's decision for one variable needs to constrain the available choices for another variable, and I'm wondering about the suitability of different ways of accomplishing this.我有一个正在处理的优化问题,其中优化器对一个变量的决定需要限制另一个变量的可用选择,我想知道实现这一点的不同方法的适用性。 I'll try to pare it down for demonstration purposes (in kotlin).为了演示目的,我将尝试减少它(在 kotlin 中)。

@PlanningEntity
class AuctionBid {
  @PlanningId
  lateinit var entity: String
  
  @PlanningVariable(valueRangeProviderRefs = ["availOptions"])
  var bidNow: Boolean? = null
  @PlanningVariable(valueRangeProviderRefs = ["availOptions"])
  var bidFinal: Boolean? = null
  var forceBid: Boolean? = null

  @ValueRangeProvider(id = "availOptions")
  private fun availOptions(): List<Boolean> {
    return if(this.forceBid != null) {
      listOf(this.forceBid!!)
    } else {
      listOf(true,false)
    }
  }
}

In this scenario, we are trying to determine if we should bid on a given entity in a combinatorial auction (multiple entities being bid on in each round), given a hard budget and various cost/benefit tradeoffs.在这种情况下,考虑到硬预算和各种成本/收益权衡,我们试图确定是否应该在组合拍卖中对给定实体进行竞标(每轮中有多个实体被竞标)。 The bidNow choice is determined by the prices in the current round of the auction, and the bidFinal choice is determined by the anticipated/forecasted final prices in the auction. bidNow选择由本轮拍卖中的价格决定, bidFinal选择由拍卖中预期/预测的最终价格决定。 In order to avoid constantly changing decisions about what to bid on right now (switching bids is penalized in the auction rules), we want to constrain our choices on bidNow based on our decision for bidFinal , such that if we will want to bid on it at our anticipated future price, we will always choose to bid on it now.为了避免不断改变关于现在出价什么的决定(在拍卖规则中改变出价会受到惩罚),我们希望根据我们对bidFinal的决定来限制我们对bidNow的选择,这样如果我们想要出价它以我们预期的未来价格,我们将始终选择现在出价。 A state table seen below:如下所示的状态表:

bidNow现在出价 bidFinal最终投标 possible可能的
Y Y Y
Y N ñ Y
N ñ N ñ Y
N ñ Y N ñ

As seen, we already have a method of constraining choices for situations where we know we don't want the product at all, or where we know we want it at any price.正如所见,我们已经有一种方法可以在我们知道我们根本不想要该产品或我们知道我们不惜任何代价想要它的情况下限制选择。 This is using the availOptions ValueRangeProvider, which only lets the optimizer choose a predetermined option if we know that is our only choice.这是使用availOptions ValueRangeProvider,如果我们知道这是我们唯一的选择,它只会让优化器选择一个预定的选项。

However, this constraint is more dynamic, as it results from a separate choice.但是,此约束更具动态性,因为它来自单独的选择。 If we are wanting to bid at the anticipated final price, our only choice for right now is to continue bidding in the current round.如果我们想以预期的最终价格竞标,我们目前唯一的选择就是在本轮继续竞标。

I've thought of a few ways of doing this, as this is a classic Local Consistency Constraint Propagation example, but without knowing too much about optaplanner's internals, I don't really know the best way to do this.我已经想到了几种方法,因为这是一个经典的局部一致性约束传播示例,但是由于对 optaplanner 的内部结构了解不多,我真的不知道最好的方法。 Some options:一些选项:

  1. Use a separate ValueRangeProvider for bidNow than bidFinal , and constrain the value range for bidNow to True if bidFinal is true.对 bidNow 使用单独的bidNow而不是bidFinal ,如果bidNowTrue ,则将bidFinal的值范围限制为 True。 However, I don't know if optaplanner can even handle a dynamic value range that is determined by another planning variable's value, nor do I know if this is an efficient method.但是,我不知道 optaplanner 是否甚至可以处理由另一个计划变量的值确定的动态值范围,也不知道这是否是一种有效的方法。
  2. Place a hard constraint (using ConstraintStreams, which is super cool BTW) on bidNow to always be True if bidFinal is True .如果bidFinalTrue ,则在bidNow上放置一个硬约束(使用 ConstraintStreams,这是非常酷的 BTW)始终为True I know this is feasible (it's my current solution), but it seems really slow.我知道这是可行的(这是我目前的解决方案),但它似乎真的很慢。
  3. Maybe try to use a Shadow variable which I've never used before, although I'm not sure this is a good fit because bidFinal==True implies bidNow==True , but bidFinal=False doesn't necessarily imply anything about bidNow .也许尝试使用我以前从未使用过的 Shadow 变量,尽管我不确定这是否合适,因为bidFinal==True暗示bidNow==True ,但bidFinal=False不一定暗示任何有关bidNow的内容。

I know I can always just try all the different options and see, but this problem is already big and unwieldy (the demo code is dramatically simplified), and I really would like some insight into how Optaplanner is working behind the scenes because I really like working with it but come across these this-way-or-that-way scenarios all the time and it's difficult to try them all.我知道我总是可以尝试所有不同的选项然后看看,但是这个问题已经很大而且很笨拙(演示代码被大大简化了),我真的很想了解 Optaplanner 如何在幕后工作,因为我真的很喜欢使用它,但总是遇到这些这样或那样的场景,很难全部尝试。 Is there any insight into modeling this constraint propagation problem?对这个约束传播问题的建模有什么见解吗? Or problems like this?或者这样的问题?

Both 1 and 2 should be possible; 1和2都应该可以; 2 being the straightforward way. 2是直截了当的方式。

Another option would be to use filtered move selection to skip the moves that would set bidFinal to Y if bidNow is false (and the opposite corner case).如果bidNowfalse (以及相反的极端情况),另一种选择是使用过滤的移动选择来跳过将bidFinal设置为Y的移动。 The downside of this is that the filter needs to be applied to every move you use, which makes solver configuration verbose.这样做的缺点是过滤器需要应用于您使用的每一个动作,这使得求解器配置变得冗长。 And the moves will still be generated before they are thrown away, so you lose a bit of performance.而且这些招式仍然会在被丢弃之前生成,因此您会损失一些性能。

However, why not make bid an enum with three options: NOTHING , NOW_ONLY , BOTH .但是,为什么不使用以下三个选项对枚举进行bidNOTHINGNOW_ONLYBOTH That way, you have the benefits of only having one planning variable and completely eliminating the original problem.这样一来,您就可以获得只有一个计划变量并完全消除原始问题的好处。 Of course this is only suitable when the number of options is this low, which it may not be in your actual use case.当然,这仅适用于选项数量很少的情况,在您的实际用例中可能不是这样。

This last option is an example of designing your data model in a way to avoid corner cases.最后一个选项是以一种避免极端情况的方式设计数据模型的示例。 If they are impossible because the model precludes them, you do not need to worry about working around them later.如果它们是不可能的,因为模型排除了它们,您不必担心以后要解决它们。 This is always your best bet.这始终是您最好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM