@@ -200,9 +200,80 @@ def _model_run_scenario(
200200 return self .solve (** solve_kwargs )
201201
202202
203+ def _solve_result_records (
204+ self : _arco .SolveResult ,
205+ * ,
206+ table : str = "variables" ,
207+ ) -> list [dict [str , object ]]:
208+ if table == "variables" :
209+ return [
210+ {
211+ "variable_id" : idx ,
212+ "value" : primal ,
213+ "reduced_cost" : reduced_cost ,
214+ }
215+ for idx , (primal , reduced_cost ) in enumerate (
216+ zip (self .primal_values , self .variable_duals , strict = True )
217+ )
218+ ]
219+
220+ if table == "constraints" :
221+ return [
222+ {
223+ "constraint_id" : idx ,
224+ "dual" : dual ,
225+ }
226+ for idx , dual in enumerate (self .constraint_duals )
227+ ]
228+
229+ if table == "summary" :
230+ return [
231+ {
232+ "status" : self .status_string (),
233+ "objective_value" : self .objective_value ,
234+ "solve_time_seconds" : self .solve_time_seconds (),
235+ "is_optimal" : self .is_optimal (),
236+ }
237+ ]
238+
239+ raise ValueError ("table must be one of {'variables', 'constraints', 'summary'}" )
240+
241+
242+ def _solve_result_to_pandas (
243+ self : _arco .SolveResult ,
244+ * ,
245+ table : str = "variables" ,
246+ ) -> object :
247+ try :
248+ import pandas as pd
249+ except ModuleNotFoundError as exc : # pragma: no cover - optional dependency
250+ raise ModuleNotFoundError (
251+ "to_pandas() requires pandas. Install with `uv add pandas` or `pip install pandas`."
252+ ) from exc
253+
254+ return pd .DataFrame .from_records (_solve_result_records (self , table = table ))
255+
256+
257+ def _solve_result_to_polars (
258+ self : _arco .SolveResult ,
259+ * ,
260+ table : str = "variables" ,
261+ ) -> object :
262+ try :
263+ import polars as pl
264+ except ModuleNotFoundError as exc : # pragma: no cover - optional dependency
265+ raise ModuleNotFoundError (
266+ "to_polars() requires polars. Install with `uv add polars` or `pip install polars`."
267+ ) from exc
268+
269+ return pl .DataFrame (_solve_result_records (self , table = table ))
270+
271+
203272setattr (_arco .Model , "control" , _model_control )
204273setattr (_arco .Model , "scenario" , _model_scenario )
205274setattr (_arco .Model , "run_scenario" , _model_run_scenario )
275+ setattr (_arco .SolveResult , "to_pandas" , _solve_result_to_pandas )
276+ setattr (_arco .SolveResult , "to_polars" , _solve_result_to_polars )
206277
207278
208279if "block" not in __all__ :
0 commit comments