如何实现“嵌套” Gecode 中的成本函数?
一般来说,我对地理编码和约束编程很陌生。
到目前为止,我在获取地理代码方面没有遇到太多麻烦,这很棒。但我想知道执行“嵌套”成本函数的最佳方法是什么。具体来说,我希望最小化 X,但在 X 相等的解决方案空间内,更喜欢最小化 Y 的解决方案?我可能可以通过定义一个看起来像 X*large_number+Y 的成本函数来破解它,但如果有一个好的解决方案,我更愿意正确地执行此操作。
如果有人能指出我解释如何在 Gecode 中实现这一点,那将非常有帮助。谢谢!
I am new to gecode and constraint programming in general.
So far, I haven't had much trouble picking up gecode, it's great. But I was wondering what is the best way to perform a "nested" cost function. Specifically, I am looking to minimize X, but within the space of solutions for which X is equal, prefer solutions which minimize Y? I could probably hack it by defining a cost function that looks like X*large_number+Y, but I'd prefer to do this properly if there's a good solution.
If anyone can point me to explain how to implement this in Gecode, that would be really helpful. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Gecode 中空间中的 constrain 成员定义任何类型的优化标准。有关示例,请参阅使用 Gecode 建模和编程中的第 2.5 节。在您的情况下,直接的方法是添加一个约束成员,该成员在先前的最佳解决方案答案和当前空间之间添加字典顺序约束。
话虽这么说,一般来说,基于字典顺序的优化可能是浪费的(太多搜索)。首先运行优化第一个组件(在您的情况下为 X)的搜索通常可能更好。之后,使用固定的第一个组件值(X 设置为最佳可能值)重新运行搜索,并优化第二个值(在您的情况下为 Y)。根据需要对成本中的所有元素进行迭代。
You can define any kind of optimization criteria using the constrain member in a space in Gecode. See Section 2.5 in Modeling and Programming with Gecode for an example. In your case, the straight forward way would be to add a constrain member that adds a lexicographic constraint between the previous best solutions answer and the current space.
That being said, in general optimizing based on a lexicographic order can be wasteful (too much searching). It may often be better to first run a search optimizing the first component (X in your case). After that, re-run the search with the first components value fixed (X set to best possible value), and optimize the second value (Y in your case). Iterate as needed for all elements in the cost.