From 03b488bf8a9e7273b5b5a14cf70f7fa45d45ad6c Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Tue, 3 Dec 2024 17:01:42 +0100 Subject: [PATCH 1/4] Xpress python parser update for MathOpt --- ortools/xpress/parse_header_xpress.py | 55 ++++++++++++++++++--------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/ortools/xpress/parse_header_xpress.py b/ortools/xpress/parse_header_xpress.py index fba9fbb..8e0d462 100644 --- a/ortools/xpress/parse_header_xpress.py +++ b/ortools/xpress/parse_header_xpress.py @@ -88,11 +88,17 @@ def __init__(self): self.__int64_parameters_unittest = '' # These are the definitions required for compiling the XPRESS interface, excluding control parameters self.__required_defines = {"XPRS_STOP_USER", "XPRS_TYPE_NOTDEFINED", "XPRS_TYPE_INT", "XPRS_TYPE_INT64", - "XPRS_TYPE_DOUBLE", "XPRS_PLUSINFINITY", "XPRS_MINUSINFINITY", "XPRS_MAXBANNERLENGTH", "XPVERSION", + "XPRS_TYPE_DOUBLE", "XPRS_PLUSINFINITY", "XPRS_MINUSINFINITY", + "XPRS_MAXBANNERLENGTH", "XPVERSION", "XPRS_LPOBJVAL", "XPRS_MIPOBJVAL", "XPRS_BESTBOUND", "XPRS_OBJRHS", "XPRS_OBJSENSE", - "XPRS_ROWS", "XPRS_SIMPLEXITER", "XPRS_LPSTATUS", "XPRS_MIPSTATUS", "XPRS_NODES", - "XPRS_COLS", "XPRS_LP_OPTIMAL", "XPRS_LP_INFEAS", "XPRS_LP_UNBOUNDED", - "XPRS_MIP_SOLUTION", "XPRS_MIP_INFEAS", "XPRS_MIP_OPTIMAL", "XPRS_MIP_UNBOUNDED", + "XPRS_ROWS", "XPRS_SIMPLEXITER", + # LPSTATUS + "XPRS_LPSTATUS", "XPRS_LP_UNSTARTED", "XPRS_LP_OPTIMAL", "XPRS_LP_INFEAS", + "XPRS_LP_CUTOFF", "XPRS_LP_UNFINISHED", "XPRS_LP_UNBOUNDED", + "XPRS_LP_CUTOFF_IN_DUAL", "XPRS_LP_UNSOLVED", "XPRS_LP_NONCONVEX", + # MIP STATUS + "XPRS_MIPSTATUS", "XPRS_MIP_INFEAS", "XPRS_MIP_OPTIMAL", "XPRS_MIP_UNBOUNDED", + "XPRS_COLS", "XPRS_NODES", "XPRS_MIP_SOLUTION", "XPRS_OBJ_MINIMIZE", "XPRS_OBJ_MAXIMIZE", "XPRS_NAMES_ROW", "XPRS_NAMES_COLUMN"} self.__missing_required_defines = self.__required_defines # These enum will detect control parameters that will all be imported @@ -107,13 +113,16 @@ def __init__(self): "XPRSgetdblcontrol", "XPRSgetstringcontrol", "XPRSgetintattrib", "XPRSgetdblattrib", "XPRSloadlp", "XPRSloadlp64", "XPRSgetobj", "XPRSgetrhs", "XPRSgetrhsrange", "XPRSgetlb", "XPRSgetub", "XPRSgetcoef", "XPRSaddrows", - "XPRSdelrows", "XPRSaddcols", "XPRSaddnames", "XPRSgetnames", "XPRSdelcols", "XPRSchgcoltype", "XPRSloadbasis", + "XPRSdelrows", "XPRSaddcols", "XPRSaddnames", "XPRSgetnames", "XPRSdelcols", + "XPRSchgcoltype", "XPRSloadbasis", "XPRSpostsolve", "XPRSchgobjsense", "XPRSgetlasterror", "XPRSgetbasis", "XPRSwriteprob", "XPRSgetrowtype", "XPRSgetcoltype", "XPRSgetlpsol", "XPRSgetmipsol", "XPRSchgbounds", "XPRSchgobj", "XPRSchgcoef", "XPRSchgmcoef", - "XPRSchgrhs", "XPRSchgrhsrange", "XPRSchgrowtype", "XPRSaddcbmessage", "XPRSsetcbmessage", + "XPRSchgrhs", "XPRSchgrhsrange", "XPRSchgrowtype", "XPRSaddcbmessage", + "XPRSsetcbmessage", "XPRSaddmipsol", "XPRSaddcbintsol", "XPRSremovecbintsol", - "XPRSinterrupt", "XPRSlpoptimize", "XPRSmipoptimize", "XPRSsetindicators"} + "XPRSinterrupt", "XPRSlpoptimize", "XPRSmipoptimize", "XPRSsetindicators", + "XPRSgetcontrolinfo"} self.__missing_required_functions = self.__required_functions self.__XPRSprob_section = False @@ -121,6 +130,10 @@ def write_define(self, symbol, value): if symbol in self.__excluded_defines: print('skipping ' + symbol) return + if "deprecated" in value.lower(): + print( + f"WARNING: Skipped defined symbol '{symbol}' because it is deprecated. If it is required, replace it.") + return # If it is a control parameter, import it to expose it to the user # Else import it only if required @@ -186,10 +199,10 @@ def parse(self, filepath): self.__doc_section = XprsDocumentSection.OTHER if self.__state == 0: - match_def = re.match(r'#define ([A-Z0-9_]*)\s+([^/]+)', line, + match_def = re.match(r'#define ([A-Z0-9_]*)\s+([/*]*)([^/]+)([*/]*)\s+([^/]+)', line, re.M) if match_def: - self.write_define(match_def.group(1), match_def.group(2)) + self.write_define(match_def.group(1), match_def.group(match_def.lastindex)) continue # Single line function definition. @@ -279,28 +292,36 @@ def output(self): print('------------------- assign (to copy in the assign part of environment.cc) -------------------') print(self.__assign) - print('------------------- string params (to copy in the "getMapStringControls" function of linear_solver/xpress_interface.cc) -------------------') + print( + '------------------- string params (to copy in the "getMapStringControls" function of linear_solver/xpress_interface.cc) -------------------') print(self.__string_parameters) - print('------------------- string params test (to copy in the "setStringControls" TEST of linear_solver/unittests/xpress_interface.cc) -------------------') + print( + '------------------- string params test (to copy in the "setStringControls" TEST of linear_solver/unittests/xpress_interface.cc) -------------------') print(self.__string_parameters_unittest) - print('------------------- double params (to copy in the "getMapDoubleControls" function of linear_solver/xpress_interface.cc) -------------------') + print( + '------------------- double params (to copy in the "getMapDoubleControls" function of linear_solver/xpress_interface.cc) -------------------') print(self.__double_parameters) - print('------------------- double params test (to copy in the "setDoubleControls" TEST of linear_solver/unittests/xpress_interface.cc) -------------------') + print( + '------------------- double params test (to copy in the "setDoubleControls" TEST of linear_solver/unittests/xpress_interface.cc) -------------------') print(self.__double_parameters_unittest) - print('------------------- int params (to copy in the "getMapIntControls" function of linear_solver/xpress_interface.cc) -------------------') + print( + '------------------- int params (to copy in the "getMapIntControls" function of linear_solver/xpress_interface.cc) -------------------') print(self.__int_parameters) - print('------------------- int params test (to copy in the "setIntControls" TEST of linear_solver/unittests/xpress_interface.cc) -------------------') + print( + '------------------- int params test (to copy in the "setIntControls" TEST of linear_solver/unittests/xpress_interface.cc) -------------------') print(self.__int_parameters_unittest) - print('------------------- int64 params (to copy in the "getMapInt64Controls" function of linear_solver/xpress_interface.cc) -------------------') + print( + '------------------- int64 params (to copy in the "getMapInt64Controls" function of linear_solver/xpress_interface.cc) -------------------') print(self.__int64_parameters) - print('------------------- int64 params test (to copy in the "setInt64Controls" TEST of linear_solver/unittests/xpress_interface.cc) -------------------') + print( + '------------------- int64 params test (to copy in the "setInt64Controls" TEST of linear_solver/unittests/xpress_interface.cc) -------------------') print(self.__int64_parameters_unittest) def print_missing_elements(self): From bcfe582ad995eb7b0ad59147260066befe68ef1c Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Thu, 5 Dec 2024 12:46:10 +0100 Subject: [PATCH 2/4] add XPRS_BARITER --- ortools/xpress/parse_header_xpress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ortools/xpress/parse_header_xpress.py b/ortools/xpress/parse_header_xpress.py index 8e0d462..3b0b7c2 100644 --- a/ortools/xpress/parse_header_xpress.py +++ b/ortools/xpress/parse_header_xpress.py @@ -91,7 +91,7 @@ def __init__(self): "XPRS_TYPE_DOUBLE", "XPRS_PLUSINFINITY", "XPRS_MINUSINFINITY", "XPRS_MAXBANNERLENGTH", "XPVERSION", "XPRS_LPOBJVAL", "XPRS_MIPOBJVAL", "XPRS_BESTBOUND", "XPRS_OBJRHS", "XPRS_OBJSENSE", - "XPRS_ROWS", "XPRS_SIMPLEXITER", + "XPRS_ROWS", "XPRS_SIMPLEXITER", "XPRS_BARITER", # LPSTATUS "XPRS_LPSTATUS", "XPRS_LP_UNSTARTED", "XPRS_LP_OPTIMAL", "XPRS_LP_INFEAS", "XPRS_LP_CUTOFF", "XPRS_LP_UNFINISHED", "XPRS_LP_UNBOUNDED", From 4e8f78cce2c786c2f1ce1b8c2f2518c5d3d36e1f Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Thu, 5 Dec 2024 12:49:11 +0100 Subject: [PATCH 3/4] add XPRS_LPITERLIMIT and XPRS_BARITERLIMIT --- ortools/xpress/parse_header_xpress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ortools/xpress/parse_header_xpress.py b/ortools/xpress/parse_header_xpress.py index 3b0b7c2..50b42c0 100644 --- a/ortools/xpress/parse_header_xpress.py +++ b/ortools/xpress/parse_header_xpress.py @@ -91,7 +91,7 @@ def __init__(self): "XPRS_TYPE_DOUBLE", "XPRS_PLUSINFINITY", "XPRS_MINUSINFINITY", "XPRS_MAXBANNERLENGTH", "XPVERSION", "XPRS_LPOBJVAL", "XPRS_MIPOBJVAL", "XPRS_BESTBOUND", "XPRS_OBJRHS", "XPRS_OBJSENSE", - "XPRS_ROWS", "XPRS_SIMPLEXITER", "XPRS_BARITER", + "XPRS_ROWS", "XPRS_SIMPLEXITER", "XPRS_BARITER", "XPRS_LPITERLIMIT", "XPRS_BARITERLIMIT", # LPSTATUS "XPRS_LPSTATUS", "XPRS_LP_UNSTARTED", "XPRS_LP_OPTIMAL", "XPRS_LP_INFEAS", "XPRS_LP_CUTOFF", "XPRS_LP_UNFINISHED", "XPRS_LP_UNBOUNDED", From c86905f8d1fc240fddb61fc88159a016cc183d32 Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Thu, 5 Dec 2024 12:49:46 +0100 Subject: [PATCH 4/4] remove XPRS_LPITERLIMIT and XPRS_BARITERLIMIT --- ortools/xpress/parse_header_xpress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ortools/xpress/parse_header_xpress.py b/ortools/xpress/parse_header_xpress.py index 50b42c0..3b0b7c2 100644 --- a/ortools/xpress/parse_header_xpress.py +++ b/ortools/xpress/parse_header_xpress.py @@ -91,7 +91,7 @@ def __init__(self): "XPRS_TYPE_DOUBLE", "XPRS_PLUSINFINITY", "XPRS_MINUSINFINITY", "XPRS_MAXBANNERLENGTH", "XPVERSION", "XPRS_LPOBJVAL", "XPRS_MIPOBJVAL", "XPRS_BESTBOUND", "XPRS_OBJRHS", "XPRS_OBJSENSE", - "XPRS_ROWS", "XPRS_SIMPLEXITER", "XPRS_BARITER", "XPRS_LPITERLIMIT", "XPRS_BARITERLIMIT", + "XPRS_ROWS", "XPRS_SIMPLEXITER", "XPRS_BARITER", # LPSTATUS "XPRS_LPSTATUS", "XPRS_LP_UNSTARTED", "XPRS_LP_OPTIMAL", "XPRS_LP_INFEAS", "XPRS_LP_CUTOFF", "XPRS_LP_UNFINISHED", "XPRS_LP_UNBOUNDED",