RsBundle  Check-in [9bbb1b8836]

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

Overview
Comment:Solver::solve returns `Error::IterationLimit` if limit has been reached.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9bbb1b8836b417d913649a71f826e5fe123ac48f
User & Date: fifr 2017-04-18 13:04:14.930
Context
2017-04-18
13:08
solver: do not call `init` in `solver_iter`. check-in: fb00b3c18e user: fifr tags: trunk
13:04
Solver::solve returns `Error::IterationLimit` if limit has been reached. check-in: 9bbb1b8836 user: fifr tags: trunk
12:59
solver: add `solver_iter` method. check-in: 10b0be88b8 user: fifr tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/solver.rs.
84
85
86
87
88
89
90






91
92
93
94
95
96
97
        }

        /// The variable index is out of bounds.
        InvalidVariable(index: usize, nvars: usize) {
            description("invalid variable")
            display("Variable index out of bounds, got:{} must be < {}", index, nvars)
        }






    }
}


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








>
>
>
>
>
>







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
        }

        /// The variable index is out of bounds.
        InvalidVariable(index: usize, nvars: usize) {
            description("invalid variable")
            display("Variable index out of bounds, got:{} must be < {}", index, nvars)
        }

        /// Iteration limit has been reached.
        IterationLimit(limit: usize) {
            description("iteration limit reached")
            display("The iteration limit of {} has been reached.", limit)
        }
    }
}


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

556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574

575
576
577
578
579
580
581
582
583
        self.start_time = Instant::now();

        Ok(())
    }

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

        }
        Ok(())
    }

    /// Solve the problem but stop after `niter` iterations.
    ///
    /// The function returns `Ok(true)` if the termination criterion
    /// has been satisfied. Otherwise it returns `Ok(false)` or an
    /// error code.







<
|
<
<
<
<
<
|
|
<
|
|
>

<







562
563
564
565
566
567
568

569





570
571

572
573
574
575

576
577
578
579
580
581
582
        self.start_time = Instant::now();

        Ok(())
    }

    /// Solve the problem.
    pub fn solve(&mut self) -> Result<()> {

        const LIMIT: usize = 10000;






        if self.solve_iter(LIMIT)? {

            Ok(())
        } else {
            Err(Error::IterationLimit(LIMIT))
        }

    }

    /// Solve the problem but stop after `niter` iterations.
    ///
    /// The function returns `Ok(true)` if the termination criterion
    /// has been satisfied. Otherwise it returns `Ok(false)` or an
    /// error code.