RsBundle  Diff

Differences From Artifact [9f2e1d5fce]:

  • File src/solver.rs — part of check-in [10b0be88b8] at 2017-04-18 12:59:15 on branch trunk — solver: add `solver_iter` method. (user: fifr size: 35587)

To Artifact [2fb2644257]:

  • File src/solver.rs — part of check-in [9bbb1b8836] at 2017-04-18 13:04:14 on branch trunk — Solver::solve returns `Error::IterationLimit` if limit has been reached. (user: fifr size: 35527)

84
85
86
87
88
89
90






91
92
93
94
95
96
97
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
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<()> {
        try!(self.init());
        for _ in 0..100000 {
        const LIMIT: usize = 10000;
            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 self.solve_iter(LIMIT)? {
            if term == Step::Term {
                break;
            }
            Ok(())
        } else {
            Err(Error::IterationLimit(LIMIT))
        }
        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.