Mathematica 中的整数优化?
我有一个整数规划问题。我有一根10m长的管子。我想切出尽可能多的 1.2 米的片段,然后将管道的其余部分切成 100 毫米的片段。我必须留100毫米给机器抓取。我如何在mathematica中优化它?我想我可以把它作为一个等式来解决,但如果我只是想直接得到答案。 基本上,先有尽可能多的 y,然后是 x:es。
Maximize[{x*100+y*1200, x*100+y*1200<9900},{x,y},Integers]
只是给我一个不等式图。 是的,我已经检查过 Wolfram 的说明。
I have an integer programming problem. I have a pipe, 10m long. I want to cut out as many 1.2meter pieces as I can and then cut the rest of the pipe in 100mm pieces. I have to leave 100mm for the machine to grab. How do I optimize this in mathematica? I can solve it as an equality i guess but if i just want the answer straight out.
Basically, as many y's as possible, then x:es.
Maximize[{x*100+y*1200, x*100+y*1200<9900},{x,y},Integers]
just gives me an inequality plot.
And yes, I have checked instructions at wolfram.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
由于 9900 和 1200 都是 100 的倍数,因此算法就是
您也可以尝试:
As 9900 and 1200 are both multiples of 100, the algorithm is just
You may also try:
使用假设
x,y
等为>0 等
,您最终将能够使用//N
获得一个值Mathematica 不会假设您在现实世界中!
Use assume on
x,y
etc to be>0 etc
and you will finally be able to get a value with//N
Mathematica doesnt assume you are in the Real world!
贝利撒留的解决方案是通过
Maximize
实现的最简单方法。然而,它需要将不平等改为平等,这并不反映你的意图。相反,使用 v.7,我会添加第二个条件新条件 (
y > x > 0
) 反映了您的意图,即首先选择较大的部分更好。另请注意,我将不等式 (<
) 更改为<=
,因为您的除法正好为 9900。Belisarius's solution is the simplest method via
Maximize
. However, it requires changing the inequality to an equality, which does not reflect your intent. Instead, using v. 7, I'd add a second conditionThe new condition (
y > x > 0
) reflects your intent that the larger pieces be chosen first better. Also, note that I changed the inequality (<
) to<=
as your divisions come out to 9900 exactly.为了从表面上回答这个简单的问题,而不是将其推断为优化的玩具示例,这里有一种“统一”数字的方法。
贝利撒留暗示我的回答太天真了,我认为这可能是一种有效的方法,尽管对于更复杂的情况来说效率较低。考虑将 9950 分成长度 12、75 和 1200。
To answer the simple question at face value, rather than inferring it to be a toy example of optimization, here is one method of "unitizing" a number.
Responding to belisarius' implication that my reply was too naive, I think this may be a valid, albeit inefficient method for more complicated cases. Consider splitting 9950 into lengths 12, 75, and 1200.
这是一个开始,但很糟糕,因为不知何故,我需要更好地考虑优先级,并且我需要完成每个管道的数量。不知何故,我认为金额也需要优先考虑。
Thats a start but it is bad because somehow I need to take into account priority better and I need to finish the amount of each pipe. Somehow I guess amount needs to be taken into account into priority as well.