@@ -1559,63 +1559,90 @@ def solve_problem_from_file(
15591559 Result
15601560 """
15611561 CONDITION_MAP = {
1562- "lp_optimal" : "optimal" ,
1563- "mip_optimal" : "optimal" ,
1564- "lp_infeasible" : "infeasible" ,
1565- "lp_infeas" : "infeasible" ,
1566- "mip_infeasible" : "infeasible" ,
1567- "lp_unbounded" : "unbounded" ,
1568- "mip_unbounded" : "unbounded" ,
1562+ xpress .SolStatus .NOTFOUND : "unknown" ,
1563+ xpress .SolStatus .OPTIMAL : "optimal" ,
1564+ xpress .SolStatus .FEASIBLE : "terminated_by_limit" ,
1565+ xpress .SolStatus .INFEASIBLE : "infeasible" ,
1566+ xpress .SolStatus .UNBOUNDED : "unbounded" ,
15691567 }
15701568
15711569 io_api = read_io_api_from_problem_file (problem_fn )
15721570 sense = read_sense_from_problem_file (problem_fn )
15731571
15741572 m = xpress .problem ()
15751573
1576- m .read (path_to_string (problem_fn ))
1577- m .setControl (self .solver_options )
1574+ try : # Try new API first
1575+ m .readProb (path_to_string (problem_fn ))
1576+ except AttributeError : # Fallback to old API
1577+ m .read (path_to_string (problem_fn ))
1578+
1579+ # Set solver options - new API uses setControl per option, old API accepts dict
1580+ if self .solver_options is not None :
1581+ m .setControl (self .solver_options )
15781582
15791583 if log_fn is not None :
1580- m .setlogfile (path_to_string (log_fn ))
1584+ try : # Try new API first
1585+ m .setLogFile (path_to_string (log_fn ))
1586+ except AttributeError : # Fallback to old API
1587+ m .setlogfile (path_to_string (log_fn ))
15811588
15821589 if warmstart_fn is not None :
1583- m .readbasis (path_to_string (warmstart_fn ))
1590+ try : # Try new API first
1591+ m .readBasis (path_to_string (warmstart_fn ))
1592+ except AttributeError : # Fallback to old API
1593+ m .readbasis (path_to_string (warmstart_fn ))
15841594
1585- m .solve ()
1595+ m .optimize ()
15861596
15871597 # if the solver is stopped (timelimit for example), postsolve the problem
1588- if m .getAttrib ("solvestatus" ) == xpress .solvestatus_stopped :
1589- m .postsolve ()
1598+ if m .attributes .solvestatus == xpress .enums .SolveStatus .STOPPED :
1599+ try : # Try new API first
1600+ m .postSolve ()
1601+ except AttributeError : # Fallback to old API
1602+ m .postsolve ()
15901603
15911604 if basis_fn is not None :
15921605 try :
1593- m .writebasis (path_to_string (basis_fn ))
1594- except Exception as err :
1606+ try : # Try new API first
1607+ m .writeBasis (path_to_string (basis_fn ))
1608+ except AttributeError : # Fallback to old API
1609+ m .writebasis (path_to_string (basis_fn ))
1610+ except (xpress .SolverError , xpress .ModelError ) as err :
15951611 logger .info ("No model basis stored. Raised error: %s" , err )
15961612
15971613 if solution_fn is not None :
15981614 try :
1599- m .writebinsol (path_to_string (solution_fn ))
1600- except Exception as err :
1615+ try : # Try new API first
1616+ m .writeBinSol (path_to_string (solution_fn ))
1617+ except AttributeError : # Fallback to old API
1618+ m .writebinsol (path_to_string (solution_fn ))
1619+ except (xpress .SolverError , xpress .ModelError ) as err :
16011620 logger .info ("Unable to save solution file. Raised error: %s" , err )
16021621
1603- condition = m .getProbStatusString ()
1622+ condition = m .attributes . solstatus
16041623 termination_condition = CONDITION_MAP .get (condition , condition )
16051624 status = Status .from_termination_condition (termination_condition )
16061625 status .legacy_status = condition
16071626
16081627 def get_solver_solution () -> Solution :
1609- objective = m .getObjVal ()
1628+ objective = m .attributes . objval
16101629
1611- var = m .getnamelist (xpress_Namespaces .COLUMN , 0 , m .attributes .cols - 1 )
1630+ try : # Try new API first
1631+ var = m .getNameList (xpress_Namespaces .COLUMN , 0 , m .attributes .cols - 1 )
1632+ except AttributeError : # Fallback to old API
1633+ var = m .getnamelist (xpress_Namespaces .COLUMN , 0 , m .attributes .cols - 1 )
16121634 sol = pd .Series (m .getSolution (), index = var , dtype = float )
16131635
16141636 try :
1615- _dual = m .getDual ()
1616- constraints = m .getnamelist (
1617- xpress_Namespaces .ROW , 0 , m .attributes .rows - 1
1618- )
1637+ _dual = m .getDuals ()
1638+ try : # Try new API first
1639+ constraints = m .getNameList (
1640+ xpress_Namespaces .ROW , 0 , m .attributes .rows - 1
1641+ )
1642+ except AttributeError : # Fallback to old API
1643+ constraints = m .getnamelist (
1644+ xpress_Namespaces .ROW , 0 , m .attributes .rows - 1
1645+ )
16191646 dual = pd .Series (_dual , index = constraints , dtype = float )
16201647 except (xpress .SolverError , xpress .ModelError , SystemError ):
16211648 logger .warning ("Dual values of MILP couldn't be parsed" )
0 commit comments