我正在尝试修复我的模型,我有一个应该可行的解决方案。是否可以向求解器提供该解决方案并查看违反了哪些约束以及如何违反约束?
某些求解器具有 iis 选项(或类似 iisfind 的选项来查找“不可约不可行集”)。例如,您可以通过选项
iisfind=1
将问题发送给 Gurobi,或者根据您的问题查看其他求解器选项。
另一种选择是开始“一一”添加约束,直到发现不可行:)您可以通过 get_constraints() 函数轻松自动化此过程...
# read the model...
# ...
# get every constraint
cons = [c for c in ampl.get_constraints()]
# drop all the constraints so you have an "unconstrained problem"
for c in cons: # c[0] is the name of the constraint, c[1] the actual constraint
print("Removing " + c[0] + '...')
c[1].drop()
# restore every constraint so you notice when it becomes infeasible
for c in cons:
print("Adding " + c[0] + '...')
c[1].restore()
ampl.solve()
# print(ampl.solve_result)
if ampl.solve_result == 'infeasible':
print('Infeasible!!')
break