3434
3535type_params (obj:: T ) where {S <: Union{QQFieldElem, Float64} , T <: PolyhedralObject{S} } = TypeParams (T, coefficient_field (obj))
3636
37+ type_params (obj:: T ) where {S <: Union{QQFieldElem, Float64} , T <: LinearProgram{S} } = TypeParams (T, coefficient_field (obj))
38+ type_params (obj:: T ) where {S <: Union{QQFieldElem, Float64} , T <: MixedIntegerLinearProgram{S} } = TypeParams (T, coefficient_field (obj))
39+
3740function type_params (obj:: T ) where {S, T <: PolyhedralObject{S} }
3841 p_dict = _polyhedral_object_as_dict (obj)
3942 field = p_dict[:_coeff ]
@@ -44,15 +47,19 @@ function type_params(obj::T) where {S, T <: PolyhedralObject{S}}
4447 :pm_params => type_params (p_dict))
4548end
4649
50+ function type_params (obj:: T ) where {S, T <: Union{LinearProgram{S}, MixedIntegerLinearProgram{S}} }
51+ par = params (type_params (feasible_region (obj)))
52+ return TypeParams (
53+ T,
54+ par... )
55+ end
56+
57+
4758function save_object (s:: SerializerState , obj:: PolyhedralObject{S} ) where S <: Union{QQFieldElem, Float64}
4859 save_object (s, pm_object (obj))
4960end
5061
5162function save_object (s:: SerializerState , obj:: PolyhedralObject{<:FieldElem} )
52- if typeof (obj) <: Union{MixedIntegerLinearProgram, LinearProgram}
53- T = typeof (obj)
54- error (" Unsupported type $T for serialization" )
55- end
5663 p_dict = _polyhedral_object_as_dict (obj)
5764 delete! (p_dict, :_coeff )
5865 save_data_dict (s) do
@@ -105,6 +112,15 @@ function save_object(s::SerializerState, lp::LinearProgram{QQFieldElem})
105112 end
106113end
107114
115+ function save_object (s:: SerializerState , lp:: LinearProgram{<:FieldElem} )
116+ lpcoeffs = lp. polymake_lp. LINEAR_OBJECTIVE
117+ save_data_dict (s) do
118+ save_object (s, lp. feasible_region, :feasible_region )
119+ save_object (s, lp. convention, :convention )
120+ save_object (s, _pmdata_for_oscar (lpcoeffs, coefficient_field (lp)), :lpcoeffs )
121+ end
122+ end
123+
108124function save_object (s:: SerializerState{<: LPSerializer} , lp:: LinearProgram{QQFieldElem} )
109125 lp_filename = basepath (s. serializer) * " -$(objectid (lp)) .lp"
110126 save_lp (lp_filename, lp)
@@ -134,6 +150,28 @@ function load_object(s::DeserializerState, ::Type{<:LinearProgram}, field::QQFie
134150 return LinearProgram {coeff_type} (fr, lp, Symbol (conv))
135151end
136152
153+ function load_object (s:: DeserializerState , :: Type{<:LinearProgram} , params:: Dict )
154+ if s. obj isa String
155+ error (" Loading this file requires using the LPSerializer" )
156+ end
157+ field = params[:field ]
158+ coeff_type = elem_type (field)
159+ fr = load_object (s, Polyhedron, params, :feasible_region )
160+ conv = load_object (s, String, :convention )
161+ lpcoeffs = load_object (s, Vector{coeff_type}, field, :lpcoeffs )
162+ all = Polymake. _lookup_multi (pm_object (fr), " LP" )
163+ lp = nothing
164+ for i in 1 : length (all)
165+ lo = _pmdata_for_oscar (all[i]. LINEAR_OBJECTIVE, field)
166+ if lpcoeffs == lo
167+ lp = all[i]
168+ break
169+ end
170+ end
171+ @req lp != = nothing " could not identify LP subobject"
172+ return LinearProgram {coeff_type} (fr, lp, Symbol (conv), field)
173+ end
174+
137175function load_object (s:: DeserializerState{LPSerializer} ,
138176 :: Type{<:LinearProgram} , field:: QQField )
139177 load_node (s) do _
@@ -158,7 +196,19 @@ function save_object(s::SerializerState, milp::MixedIntegerLinearProgram{QQField
158196 save_object (s, milp. feasible_region, :feasible_region )
159197 save_object (s, milp. convention, :convention )
160198 save_json (s, coeffs_jsonstr, :milp_coeffs )
161- save_json (s, int_vars_jsonstr, :int_vars )
199+ # we can probably changes this line to just store a vector{Int} but will need upgrade
200+ save_json (s, int_vars_jsonstr, :int_vars )
201+ end
202+ end
203+
204+ function save_object (s:: SerializerState , milp:: MixedIntegerLinearProgram{<:FieldElem} )
205+ milp_coeffs = milp. polymake_milp. LINEAR_OBJECTIVE
206+ int_vars = milp. polymake_milp. INTEGER_VARIABLES
207+ save_data_dict (s) do
208+ save_object (s, milp. feasible_region, :feasible_region )
209+ save_object (s, milp. convention, :convention )
210+ save_object (s, _pmdata_for_oscar (milp_coeffs, coefficient_field (milp)), :milp_coeffs )
211+ save_object (s, _pmdata_for_oscar (int_vars, QQ), :int_vars )
162212 end
163213end
164214
@@ -193,6 +243,26 @@ function load_object(s::DeserializerState, ::Type{<: MixedIntegerLinearProgram},
193243 return MixedIntegerLinearProgram {T} (fr, lp, Symbol (conv), field)
194244end
195245
246+ function load_object (s:: DeserializerState , :: Type{<: MixedIntegerLinearProgram} , params:: Dict )
247+ conv = load_object (s, String, :convention )
248+ field = params[:field ]
249+ coeff_type = elem_type (field)
250+ fr = load_object (s, Polyhedron, params, :feasible_region )
251+ milp_coeffs = load_object (s, Vector{coeff_type}, field, :milp_coeffs )
252+ int_vars = load_object (s, Vector{Int}, :int_vars )
253+
254+ all = Polymake. _lookup_multi (pm_object (fr), " MILP" )
255+ index = 0
256+ for i in 1 : length (all)
257+ if _pmdata_for_oscar (all[i]. LINEAR_OBJECTIVE, field) == milp_coeffs && all[i]. INTEGER_VARIABLES == Set (int_vars)
258+ index = i
259+ break
260+ end
261+ end
262+ milp = Polymake. _lookup_multi (pm_object (fr), " MILP" , index- 1 )
263+ return MixedIntegerLinearProgram {coeff_type} (fr, milp, Symbol (conv), field)
264+ end
265+
196266# use generic serialization for the other types:
197267@register_serialization_type Cone
198268@register_serialization_type PolyhedralComplex
0 commit comments