如何使用NPAARRAY PURP PYTHON创建lpvariables

发布于 2025-01-23 01:42:01 字数 727 浏览 2 评论 0原文

我正在使用纸浆求解器来处理数千个变量的优化问题。 变量以阵列(约200个数组)保存,每个Arry均为50 * 50维度。

_t111 = ['xx1', 'xa1', 'xb1', 'xc1', 'xd1', 'xe1', 'xf1', 'xg1', 'xh1', 'xi1', 'xj1', 'xxa1', 'xxb1','xxc1', 'xxd1', 'xxe1', 'xxf1', 'xxg1', 'xxh1', 'xxi1', 'xxj1', 'xxxa1', 'xxxb1', 'xxxc1', 'xxxd1','xxxe1', 'xxxf1', 'xxxg1', 'xxxh1', 'xxxi1', 'xxxj1', 'xxxxa1', 'xxxxb1', 'xxxxc1', 'xxxxd1', 'xxxxe1', 'xxxxf1', 'xxxxg1', 'xxxxh1', 'xxxxi1', 'xxxxj1', 'xxxxxa1', 'xxxxxb1', 'xxxxxc1','xxxxxd1', 'xxxxxe1', 'xxxxxf1', 'xxxxxg1', 'xxxxxh1', 'xxxxxi1', 'xxxxxj1']

t111 = np.array([[LpVariable(f"{i}{j}", cat=LpBinary) for i in _t111] for j in _t111])

我在论坛中找到了这种方法。我声明了所有_t111,_t112 ...在变量T111 T112之前。 更好的方法吗?

我确定有人可以帮助我的

I'm using pulp solver to handle an optimization probleme with thousands of variables.
The variables are held in arrays ( around 200 arrays) and each arry is a 50 * 50 dimensions.

_t111 = ['xx1', 'xa1', 'xb1', 'xc1', 'xd1', 'xe1', 'xf1', 'xg1', 'xh1', 'xi1', 'xj1', 'xxa1', 'xxb1','xxc1', 'xxd1', 'xxe1', 'xxf1', 'xxg1', 'xxh1', 'xxi1', 'xxj1', 'xxxa1', 'xxxb1', 'xxxc1', 'xxxd1','xxxe1', 'xxxf1', 'xxxg1', 'xxxh1', 'xxxi1', 'xxxj1', 'xxxxa1', 'xxxxb1', 'xxxxc1', 'xxxxd1', 'xxxxe1', 'xxxxf1', 'xxxxg1', 'xxxxh1', 'xxxxi1', 'xxxxj1', 'xxxxxa1', 'xxxxxb1', 'xxxxxc1','xxxxxd1', 'xxxxxe1', 'xxxxxf1', 'xxxxxg1', 'xxxxxh1', 'xxxxxi1', 'xxxxxj1']

t111 = np.array([[LpVariable(f"{i}{j}", cat=LpBinary) for i in _t111] for j in _t111])

I have found this method in a forum. I declare all my _t111, _t112... before the variables t111 t112.. the prob is that it takes me a lot to comple it. I'm sure there is a better way

Some one can help me ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文