43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/// The oracle did not return a minorant.
#[fail(display = "The oracle did not return a minorant")]
NoMinorant,
/// The dimension of some data is wrong.
#[fail(display = "Dimension of lower bounds does not match number of variables")]
Dimension,
/// Some parameter has an invalid value.
#[fail(display = "Parameter error: {}", msg)]
Parameter { msg: String },
/// The lower bound of a variable is larger than the upper bound.
#[fail(display = "Invalid bounds, lower:{} upper:{}", lower, upper)]
InvalidBounds { lower: Real, upper: Real },
/// The value of a variable is outside its bounds.
#[fail(display = "Violated bounds, lower:{} upper:{} value:{}", lower, upper, value)]
ViolatedBounds { lower: Real, upper: Real, value: Real },
/// The variable index is out of bounds.
|
|
|
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/// The oracle did not return a minorant.
#[fail(display = "The oracle did not return a minorant")]
NoMinorant,
/// The dimension of some data is wrong.
#[fail(display = "Dimension of lower bounds does not match number of variables")]
Dimension,
/// Some parameter has an invalid value.
#[fail(display = "Parameter error: {}", _0)]
Parameter(String),
/// The lower bound of a variable is larger than the upper bound.
#[fail(display = "Invalid bounds, lower:{} upper:{}", lower, upper)]
InvalidBounds { lower: Real, upper: Real },
/// The value of a variable is outside its bounds.
#[fail(display = "Violated bounds, lower:{} upper:{} value:{}", lower, upper, value)]
ViolatedBounds { lower: Real, upper: Real, value: Real },
/// The variable index is out of bounds.
|
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
pub max_updates: usize,
}
impl SolverParams {
/// Verify that all parameters are valid.
fn check(&self) -> Result<(), SolverError> {
if self.max_bundle_size < 2 {
Err(SolverError::Parameter {
msg: format!("max_bundle_size must be >= 2 (got: {})", self.max_bundle_size),
})
} else if self.acceptance_factor <= 0.0 || self.acceptance_factor >= 1.0 {
Err(SolverError::Parameter {
msg: format!("acceptance_factor must be in (0,1) (got: {})", self.acceptance_factor),
})
} else if self.nullstep_factor <= 0.0 || self.nullstep_factor > self.acceptance_factor {
Err(SolverError::Parameter {
msg: format!("nullstep_factor must be in (0,acceptance_factor] (got: {}, acceptance_factor:{})", self.nullstep_factor, self.acceptance_factor),
})
} else if self.min_weight <= 0.0 {
Err(SolverError::Parameter {
msg: format!("min_weight must be in > 0 (got: {})", self.min_weight),
})
} else if self.max_weight < self.min_weight {
Err(SolverError::Parameter {
msg: format!("max_weight must be in >= min_weight (got: {}, min_weight: {})", self.max_weight, self.min_weight),
})
} else if self.max_updates == 0 {
Err(SolverError::Parameter {
msg: format!("max_updates must be in > 0 (got: {})", self.max_updates),
})
} else {
Ok(())
}
}
}
impl Default for SolverParams {
|
|
|
<
|
|
<
|
|
<
>
<
|
<
|
|
<
<
|
<
|
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
pub max_updates: usize,
}
impl SolverParams {
/// Verify that all parameters are valid.
fn check(&self) -> Result<(), SolverError> {
if self.max_bundle_size < 2 {
Err(SolverError::Parameter(format!("max_bundle_size must be >= 2 (got: {})",
self.max_bundle_size)))
} else if self.acceptance_factor <= 0.0 || self.acceptance_factor >= 1.0 {
Err(SolverError::Parameter(format!("acceptance_factor must be in (0,1) (got: {})",
self.acceptance_factor)))
} else if self.nullstep_factor <= 0.0 || self.nullstep_factor > self.acceptance_factor {
Err(SolverError::Parameter(
format!("nullstep_factor must be in (0,acceptance_factor] (got: {}, acceptance_factor:{})",
self.nullstep_factor, self.acceptance_factor)))
} else if self.min_weight <= 0.0 {
Err(SolverError::Parameter(format!("min_weight must be in > 0 (got: {})", self.min_weight)))
} else if self.max_weight < self.min_weight {
Err(SolverError::Parameter(format!("max_weight must be in >= min_weight (got: {}, min_weight: {})",
self.max_weight, self.min_weight)))
} else if self.max_updates == 0 {
Err(SolverError::Parameter(format!("max_updates must be in > 0 (got: {})", self.max_updates)))
} else {
Ok(())
}
}
}
impl Default for SolverParams {
|
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
|
self.minorants = Vec::with_capacity(m);
for _ in 0..m {
self.minorants.push(vec![]);
}
self.cur_val = 0.0;
for i in 0..m {
let result = self.problem.evaluate(i, &self.cur_y, INFINITY, 0.0).map_err(SolverError::Master)?;
self.cur_vals[i] = result.objective();
self.cur_val += self.cur_vals[i];
let mut minorants = result.into_iter();
if let Some((minorant, primal)) = minorants.next() {
self.cur_mods[i] = minorant.constant;
self.cur_mod += self.cur_mods[i];
|
|
>
>
|
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
|
self.minorants = Vec::with_capacity(m);
for _ in 0..m {
self.minorants.push(vec![]);
}
self.cur_val = 0.0;
for i in 0..m {
let result = self.problem
.evaluate(i, &self.cur_y, INFINITY, 0.0)
.map_err(SolverError::Evaluation)?;
self.cur_vals[i] = result.objective();
self.cur_val += self.cur_vals[i];
let mut minorants = result.into_iter();
if let Some((minorant, primal)) = minorants.next() {
self.cur_mods[i] = minorant.constant;
self.cur_mod += self.cur_mods[i];
|