如何在代表不同大小的向量和集合的PYOMO参数中定义?
我有一个具有一组向量的LP作为输入参数,其中包含2至12个元素:
[1,2,0,0,3]
[1,0,0,0,0,1,2]
[5,0,0,1,0,7]
对于每个节点:
model.Nodes = pyo.Set(initialize = range(0, len(nodes))
基本上:
0:[1,2,0,0,3]
1:[1,0,0,0,0,1,2]
2:[5,0,0,1,0,7]
此外,还希望定义一个参数构造如下:
{0,1,2,3,4}
{0,1,2,3,4,5,6}
{0,1,2,3,4,5}
将数字0包含到每个向量中的组件数量。再次与节点链接:
0:{0,1,2,3,4}
1:{0,1,2,3,4,5,6}
2:{0,1,2,3,4,5}
我真的不知道如何处理不同参数的不同大小(节点的数量也无法解决不同问题)。只要设置保持顺序,通常应该充分“链接”。
I have an LP with a set of vectors as input parameter containing 2 to 12 elements:
[1,2,0,0,3]
[1,0,0,0,0,1,2]
[5,0,0,1,0,7]
for each node:
model.Nodes = pyo.Set(initialize = range(0, len(nodes))
so basically:
0:[1,2,0,0,3]
1:[1,0,0,0,0,1,2]
2:[5,0,0,1,0,7]
and additionally would like to define a parameter construct as follows:
{0,1,2,3,4}
{0,1,2,3,4,5,6}
{0,1,2,3,4,5}
containing the numbers 0 to the number of components in each vector. Again linked with the nodes:
0:{0,1,2,3,4}
1:{0,1,2,3,4,5,6}
2:{0,1,2,3,4,5}
I don't really know how to deal with the varying size of the different parameters (the number of nodes is also not fix for different problems). As long as the set stays in order it should in general be "linked" sufficiently.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的某些变化可能是您要寻找的。从您的帖子中不太清楚您想处理整数参数吗?我假设您有(a)节点列表,(b)每个节点的一些任意长度向量,以及(c)一些索引系统(整数)以获取数据。
我认为您缺少的作品是
索引集
,它是使用1集(在这种情况下节点)作为“集合”的索引的构造。在下面的vecs
的打印输出中,这更加清楚。当然,您需要在内部集合中进行索引,在这种情况下,我使用了一组足够长的整数来索引任何内部集合。最后,我不确定一种更好的方法来使用该事物的组合来容纳数据(参数),而不是在下面的工作方式,即“弄平”索引集中的成员资格,并使用它来保持参数。请注意,这具有稀疏集的优点,小于节点X元素的完整X产品的大小,但是进行求和时,您必须使用适当的集合(
vecs_flat
)。 :
Some variation of the below is probably what you are looking for. It isn't too clear from your post what you want to do with the parameter of integers? I'm assuming you have (a) a list of nodes, (b) some arbitrary length vector of data with each node, and (c) some indexing system (integers) to get at the data.
The piece that I think you are missing is an
indexed set
which is a construct to use 1 set (nodes in this case) as an index to a "set of sets". This is more clear in the printout ofvecs
below. Of course, you then need an index into the inner set, in this case I used a set of integers sufficiently long to index any of the internal sets.Lastly, I'm not sure of a better way to use that combination of things to hold data (parameter) other than how I do it below, which is to "flatten out" the membership from the indexed set, and use that to hold the parameters. Note this has the advantage of being a sparse set, less than the size of the full x-product of nodes x elements, but you must use the appropriate set (
vecs_flat
) when doing summations, etc.Yields: