@@ -118,6 +118,7 @@ impl FormatWithVars for Variable {
118
118
pub struct VariableDefinition {
119
119
pub ( crate ) min : f64 ,
120
120
pub ( crate ) max : f64 ,
121
+ pub ( crate ) initial : Option < f64 > ,
121
122
pub ( crate ) name : String ,
122
123
pub ( crate ) is_integer : bool ,
123
124
}
@@ -128,6 +129,7 @@ impl VariableDefinition {
128
129
VariableDefinition {
129
130
min : f64:: NEG_INFINITY ,
130
131
max : f64:: INFINITY ,
132
+ initial : None ,
131
133
name : String :: new ( ) ,
132
134
is_integer : false ,
133
135
}
@@ -177,6 +179,27 @@ impl VariableDefinition {
177
179
self
178
180
}
179
181
182
+ /// Set the initial value of the variable. This may help the solver to find a solution significantly faster.
183
+ ///
184
+ /// **Warning**: not all solvers support integer variables.
185
+ /// Refer to the documentation of the solver you are using.
186
+ ///
187
+ /// ```
188
+ /// # use good_lp::{ProblemVariables, variable, default_solver, SolverModel, Solution};
189
+ /// let mut problem = ProblemVariables::new();
190
+ /// let x = problem.add(variable().max(3).initial(3));
191
+ /// let y = problem.add(variable().max(5).initial(5));
192
+ /// if cfg!(not(any(feature="clarabel"))) {
193
+ /// let solution = problem.maximise(x + y).using(default_solver).solve().unwrap();
194
+ /// assert_eq!(solution.value(x), 3.);
195
+ /// assert_eq!(solution.value(y), 5.);
196
+ /// }
197
+ /// ```
198
+ pub fn initial < N : Into < f64 > > ( mut self , value : N ) -> Self {
199
+ self . initial = Some ( value. into ( ) ) ;
200
+ self
201
+ }
202
+
180
203
/// Set the name of the variable. This is useful in particular when displaying the problem
181
204
/// for debugging purposes.
182
205
///
0 commit comments