File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
## 0.14.0 - 2024-05-##
6
6
- Allow assigning values to indexed sets from a dictionary with the lists of members
7
7
for every index.
8
+ - Add AMPL.get_iis() to return dictionaries with variables and constraints in IIS.
8
9
9
10
## 0.13.3 - 2024-02-20
10
11
- Fix issues with AMPL.solve(verbose=False) when the solver argument was not set.
Original file line number Diff line number Diff line change @@ -891,6 +891,45 @@ def solve_result_num(self):
891
891
"""
892
892
return self .get_value ("solve_result_num" )
893
893
894
+ def get_iis (self ):
895
+ """
896
+ Get IIS attributes for all variables and constraints.
897
+
898
+ Returns:
899
+ Tuple with a dictionary for variables in the IIS and another for the constraints.
900
+
901
+ Usage example:
902
+
903
+ .. code-block:: python
904
+
905
+ from amplpy import AMPL
906
+ ampl = AMPL()
907
+ ampl.eval(
908
+ r\" \" \"
909
+ var x >= 0;
910
+ var y >= 0;
911
+ maximize obj: x+y;
912
+ s.t. s: x+y <= -5;
913
+ \" \" \"
914
+ )
915
+ ampl.option["presolve"] = 0 # disable AMPL presolve
916
+ ampl.solve(solver="gurobi", gurobi_options="outlev=1 iis=1")
917
+ if ampl.solve_result == "infeasible":
918
+ var_iis, con_iis = ampl.get_iis()
919
+ print(var_iis, con_iis)
920
+ """
921
+ df_var = dict (
922
+ self .get_data (
923
+ "{i in 1.._nvars: _var[i].iis != 'non'} (_varname[i], _var[i].iis)"
924
+ ).to_list (skip_index = True )
925
+ )
926
+ df_con = dict (
927
+ self .get_data (
928
+ "{i in 1.._ncons: _con[i].iis != 'non'} (_conname[i], _con[i].iis)"
929
+ ).to_list (skip_index = True )
930
+ )
931
+ return df_var , df_con
932
+
894
933
def _start_recording (self , filename ):
895
934
"""
896
935
Start recording the session to a file for debug purposes.
Original file line number Diff line number Diff line change @@ -418,6 +418,23 @@ def test_issue56(self):
418
418
ampl .get_output ("for{i in 0..2} { display i;}" ),
419
419
)
420
420
421
+ def test_iis (self ):
422
+ ampl = self .ampl
423
+ ampl .eval (
424
+ r"""
425
+ var x >= 0;
426
+ var y >= 0;
427
+ maximize obj: x+y;
428
+ s.t. s: x+y <= -5;
429
+ """
430
+ )
431
+ ampl .option ["presolve" ] = 0
432
+ ampl .solve (solver = "gurobi" , gurobi_options = "outlev=0 iis=1" )
433
+ if ampl .solve_result == "infeasible" :
434
+ var_iis , con_iis = ampl .get_iis ()
435
+ self .assertEqual (var_iis , {"x" : "low" , "y" : "low" })
436
+ self .assertEqual (con_iis , {"s" : "mem" })
437
+
421
438
422
439
if __name__ == "__main__" :
423
440
unittest .main ()
You can’t perform that action at this time.
0 commit comments