我是谷歌或工具的新手,面临以下问题。我正在创建这样的线性解算器-
solver = pywraplp.Solver('my_solver', pywraplp.Solver.GLOP_LINEAR_PROGRAMMING)
# Added 70K variables and 180K constraints in 1.5 hrs
status = solver.Solve()
if status = pywraplp.Solver.OPTIMAL:
# It took 10 min to output an optimal solution
else:
# ...
model = solver.ExportModelToProto()
solution = solver.FillSolutionResponseProto()
model_str = text_format.MessageToString(model)
solution_str = text_format.MessageToString(solution)
# WRITE model_str & solution_str to File using Pickle
问题陈述是能够重用这个预先初始化的解算器,添加新的变量/约束(如果需要)并再次求解()
# Unpickle and READ model_str & solution_str and convert back to proto variables 'model' and 'solution'
new_solver = pywraplp.Solver('new_solver', pywraplp.Solver.GLOP_LINEAR_PROGRAMMING)
new_solver.LoadModelFromProto(model)
new_solver.LoadSolutionFromProto(solution)
# not adding new variables or constraints now
status = new_solver.Solve()
if status = pywraplp.Solver.OPTIMAL:
# goes into an infinite loop
else:
# no solution
但是,此解算器被卡住,看不到任何输出。尽管如此,相同的代码适用于数量较少的3K变量和8K约束。请告知这是否可行,或者如果已经解决了,为什么会很慢
目前没有回答
相关问题 更多 >
编程相关推荐