File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 33//! A solver binary will need to be present on the user's computer at runtime.
44
55use std:: cmp:: Ordering ;
6+ use std:: collections:: HashMap ;
67
78use lp_solvers:: lp_format:: LpObjective ;
89use lp_solvers:: problem:: StrExpression ;
@@ -157,6 +158,42 @@ fn linear_coefficients_str(
157158 )
158159}
159160
161+ impl < T > crate :: solvers:: WithInitialSolution for Model < T >
162+ where
163+ T : WithMipStart < T > ,
164+ {
165+ fn with_initial_solution (
166+ mut self ,
167+ solution : impl IntoIterator < Item = ( Variable , f64 ) > ,
168+ ) -> Self {
169+ let mut start: HashMap < String , f32 > = HashMap :: new ( ) ;
170+
171+ for ( v, val) in solution {
172+ if !val. is_finite ( ) {
173+ continue ;
174+ }
175+
176+ let idx = v. index ( ) ;
177+ let Some ( lp_var) = self . problem . variables . get ( idx) else {
178+ continue ;
179+ } ;
180+
181+ let val_f32 = val as f32 ;
182+ if !val_f32. is_finite ( ) {
183+ continue ;
184+ }
185+
186+ start. insert ( lp_var. name . clone ( ) , val_f32) ;
187+ }
188+
189+ if let Ok ( solver) = self . solver . with_mip_start ( & start) {
190+ self . solver = solver;
191+ }
192+
193+ self
194+ }
195+ }
196+
160197/// A solution
161198pub struct LpSolution {
162199 solution : Vec < f64 > ,
You can’t perform that action at this time.
0 commit comments