RsBundle  Check-in [4cf9ac6c65]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:solver: Add validity check for parameters.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4cf9ac6c650a70717ca5d3e90fd73c1fc267152c
User & Date: fifr 2016-09-28 11:27:43.268
Context
2016-09-28
11:28
solver: Allow larger bundle sizes when compressing bundles. check-in: 1f65b89c9e user: fifr tags: trunk
11:27
solver: Add validity check for parameters. check-in: 4cf9ac6c65 user: fifr tags: trunk
11:26
solver: Make `params` public. check-in: 5fd72003f9 user: fifr tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/solver.rs.
54
55
56
57
58
59
60







61
62
63
64
65
66
67
        }

        /// The dimension of some data is wrong.
        Dimension(msg: &'static str) {
            description("Dimension error")
            display("Dimension error: {}", msg)
        }







    }
}


/// Result type for solvers.
pub type Result<T> = result::Result<T, Error>;








>
>
>
>
>
>
>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        }

        /// The dimension of some data is wrong.
        Dimension(msg: &'static str) {
            description("Dimension error")
            display("Dimension error: {}", msg)
        }

        /// Some parameter has an invalid value.
        Parameter(msg: String) {
            description("Parameter error")
            display("Parameter error: {}", msg)
        }

    }
}


/// Result type for solvers.
pub type Result<T> = result::Result<T, Error>;

218
219
220
221
222
223
224
























225
226
227
228
229
230
231
     * constraints. This is a technical parameter that should probably
     * never be changed. If you experience an unexpectedly high number
     * of inner iterations, consider removing/fixing the corresponding
     * variables.
     */
    pub max_updates : usize,
}

























impl Default for SolverParams {
    fn default() -> SolverParams {
        SolverParams {
            max_bundle_size: 50,
            max_age: 10,








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
     * constraints. This is a technical parameter that should probably
     * never be changed. If you experience an unexpectedly high number
     * of inner iterations, consider removing/fixing the corresponding
     * variables.
     */
    pub max_updates : usize,
}

impl SolverParams {
    /// Verify that all parameters are valid.
    fn check(&self) -> Result<()> {
        if self.max_bundle_size < 2 {
            Err(Error::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(Error::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(Error::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(Error::Parameter(format!("min_weight must be in > 0 (got: {})", self.min_weight)))
        } else if self.max_weight < self.min_weight  {
            Err(Error::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(Error::Parameter(format!("max_updates must be in > 0 (got: {})", self.max_updates)))
        } else {
            Ok(())
        }
    }
}

impl Default for SolverParams {
    fn default() -> SolverParams {
        SolverParams {
            max_bundle_size: 50,
            max_age: 10,

400
401
402
403
404
405
406
407

408
409
410
411
412
413
414

    /// Returns a reference to the solver's current problem.
    pub fn problem(&self) -> &P {
        &self.problem
    }

    /// Initialize the solver.
    fn init(&mut self) {

        if self.cur_y.len() != self.problem.num_variables() {
            self.cur_valid = false;
            self.cur_y.init0(self.problem.num_variables());
        }

        let lb = self.problem.lower_bounds().map(|x| x.to_dense());
        let ub = self.problem.upper_bounds().map(|x| x.to_dense());







|
>







431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446

    /// Returns a reference to the solver's current problem.
    pub fn problem(&self) -> &P {
        &self.problem
    }

    /// Initialize the solver.
    pub fn init(&mut self) -> Result<()> {
        try!(self.params.check());
        if self.cur_y.len() != self.problem.num_variables() {
            self.cur_valid = false;
            self.cur_y.init0(self.problem.num_variables());
        }

        let lb = self.problem.lower_bounds().map(|x| x.to_dense());
        let ub = self.problem.upper_bounds().map(|x| x.to_dense());
427
428
429
430
431
432
433


434
435
436
437
438
439
440
441
442
443
444
445
        let m = self.problem.num_subproblems();
        self.cur_vals.init0(m);
        self.cur_mods.init0(m);
        self.nxt_vals.init0(m);
        self.nxt_mods.init0(m);

        self.start_time = Instant::now();


    }

    /// Solve the problem.
    pub fn solve(&mut self) -> Result<()> {
        self.init();
        for _ in 0..100000 {
            let term = try!(self.step());
            self.show_info(term);
            if term == Step::Term {
                break;
            }
        }







>
>




|







459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
        let m = self.problem.num_subproblems();
        self.cur_vals.init0(m);
        self.cur_mods.init0(m);
        self.nxt_vals.init0(m);
        self.nxt_mods.init0(m);

        self.start_time = Instant::now();

        Ok(())
    }

    /// Solve the problem.
    pub fn solve(&mut self) -> Result<()> {
        try!(self.init());
        for _ in 0..100000 {
            let term = try!(self.step());
            self.show_info(term);
            if term == Step::Term {
                break;
            }
        }