Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Refactor `SolverError::Parameter` |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
c24cf8d06ed9514ca0fd448fbc0ebda6 |
| User & Date: | fifr 2017-11-20 09:02:22.670 |
Context
|
2017-11-20
| ||
| 09:05 | solver: remove remaing `try!` check-in: 40f31dd62c user: fifr tags: trunk | |
| 09:02 | Refactor `SolverError::Parameter` check-in: c24cf8d06e user: fifr tags: trunk | |
| 07:56 | Use `err_msg` instead of `format_err!` check-in: eecfe56bb0 user: fifr tags: trunk | |
Changes
Changes to src/solver.rs.
| ︙ | ︙ | |||
43 44 45 46 47 48 49 |
/// 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.
| | | | 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 |
pub max_updates: usize,
}
impl SolverParams {
/// Verify that all parameters are valid.
fn check(&self) -> Result<(), SolverError> {
if self.max_bundle_size < 2 {
| | | < | | < | | < > < | < | | < < | < | 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 |
self.minorants = Vec::with_capacity(m);
for _ in 0..m {
self.minorants.push(vec![]);
}
self.cur_val = 0.0;
for i in 0..m {
| | > > | 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];
|
| ︙ | ︙ |