【python】用python如何去写lp文件(整数规划约束)

【python】用python如何去写lp文件(整数规划约束),第1张

import math
def write_con(n,path,m):
	f = open(path,"a",encoding = "utf-8")
	for i in range(1,n):
		f.write("x" + str(i) + " + " + "y" + str(i) + " + ")
	f.write("x" + str(n) + " + " + "y" + str(n) + " <= " +str(m) + "\n")
	f.close()

path = r"D:\code\text.txt"
write_con(4,path,5)

执行结果:

import math
def write_con(n,path,m,k):
	f = open(path,"a",encoding = "utf-8")
	for j in range(1,k+1):
		for i in range(1,n):
			f.write("x" + str(i) + " + " + "y" + str(j) + " + ")
		f.write("x" + str(n) + " + " + "y" + str(j) + " <= " +str(m) + "\n")
	f.close()

path = r"D:\code\text.txt"
write_con(4,path,5,4)

运行结果:

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/883725.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-14
下一篇2022-05-14

发表评论

登录后才能评论

评论列表(0条)

    保存