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", "w")
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 = list(ConstraintMap.keys())
ConstrNames.sort()
RememberSecStageConstr = []
# so that we know in which rows the constraints with
# stochastic data are (first row has index 0)
count_rows = -1
for name in ConstrNames:
# check if constraint is in first stage
if name in FirstStage:
lp.write("\n"+name+":\n")
count_rows += 1
MatrixEntries_ConstrToRow_Map[name] = count_rows
self.print_coeff_var_from_map(ConstraintMap[name][0], lp)
lp.write(ConstraintMap[name][1]+" "+ConstraintMap[name][2]+"\n")
else:
RememberSecStageConstr.append(name)
MatrixEntries_ConstrToRow_Map = \
self._sort_print_second_stage_constr(ph,
RememberSecStageConstr,
lp,
ConstraintMap,
count_rows,
MatrixEntries_ConstrToRow_Map)
# 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()
#print MatrixEntries_ConstrToRow_Map
return MatrixEntries_ConstrToRow_Map
评论列表
文章目录