python重定向sys.out_Python sys.out方法代碼示例

# 需要導入模塊: import sys [as 別名]

# 或者: from sys import out [as 別名]

def sort_write_lp(self, ph, ObjObject, ConstraintMap, StageToConstraintMap, remaining_lpfile_rows):

try:

#print("\nWrite the LP file for dd in sorted_LPfile.lp\n")

lp = open("sorted_LPfile.lp", "wt")

except IOError:

print("IO Error so that sorted_LPfile.lp cannot be created.")

sys.out(1)

# keep track of input file names

self.input_file_name_list.append('sorted_LPfile.lp')

# for the matrix.sc file we need to know which constraint is

# in which row:

MatrixEntries_ConstrToRow_Map = {}

lp.write(ObjObject[0]+"\n "+ObjObject[1]+":\n")

self.print_coeff_var_from_map(ObjObject[2], lp)

# assume blank line before and after constraint indicator

lp.write("\ns.t.\n")

FirstStage = StageToConstraintMap['FirstStage']

ConstrNames = set(ConstraintMap.keys())

FirstStageConstrOrder = sorted(ConstrNames.intersection(FirstStage))

SecondStageConstrOrder = sorted(ConstrNames - set(FirstStage))

# so that we know in which rows the constraints with

# stochastic data are (first row has index 0)

count_rows = -1

self._num_first_stage_constraints = 0

self._num_second_stage_constraints = 0

for name in FirstStageConstrOrder:

lp.write("\n"+name+":\n")

count_rows += 1

MatrixEntries_ConstrToRow_Map[name] = count_rows

lp_con = ConstraintMap[name]

self.print_coeff_var_from_map(lp_con[0], lp)

lp.write(lp_con[1]+" "+lp_con[2]+"\n")

self._num_first_stage_constraints += 1

for name in SecondStageConstrOrder:

lp.write("\n"+name+":\n")

count_rows += 1

MatrixEntries_ConstrToRow_Map[name] = count_rows

lp_con = ConstraintMap[name]

self.print_coeff_var_from_map(lp_con[0], lp)

lp.write(lp_con[1]+" "+lp_con[2]+"\n")

self._num_second_stage_constraints += 1

# print the remaining rows of the lp file

for row in range(len(remaining_lpfile_rows)):

lp.write("\n")

for i in range(len(remaining_lpfile_rows[row])):

lp.write(remaining_lpfile_rows[row][i]+" ")

lp.close()

return MatrixEntries_ConstrToRow_Map, SecondStageConstrOrder, self._num_first_stage_constraints, self._num_second_stage_constraints

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值