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
评论列表
文章目录