Fix & fmt & ci #2
14
.drone.yml
Normal file
14
.drone.yml
Normal file
@ -0,0 +1,14 @@
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: rust
|
||||
commands:
|
||||
- cargo build --verbose --all
|
||||
|
||||
- name: fmt-check
|
||||
image: rust
|
||||
commands:
|
||||
- rustup component add rustfmt
|
||||
- cargo fmt --all -- --check
|
@ -12,10 +12,6 @@ keywords = ["constraint", "finite", "domain", "puzzle", "sudoku"]
|
||||
categories = ["science"]
|
||||
edition = "2021"
|
||||
|
||||
[[bin]]
|
||||
name = "run"
|
||||
path = "./bin/run.rs"
|
||||
|
||||
[dependencies]
|
||||
bit-set = "0.4"
|
||||
num-rational = { version = "0.1", default-features = false }
|
||||
|
@ -4,7 +4,7 @@ use num_rational::Ratio;
|
||||
use num_traits::Zero;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::{Constraint, Error, linexpr::LinExpr, PsResult, PuzzleSearch, Val, VarToken};
|
||||
use crate::{linexpr::LinExpr, Constraint, Error, PsResult, PuzzleSearch, Val, VarToken};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Equality {
|
||||
|
@ -16,7 +16,7 @@ pub trait Constraint: Debug {
|
||||
fn vars(&self) -> Box<dyn Iterator<Item = &'_ VarToken> + '_>;
|
||||
|
||||
/// Applied after a variable has been assigned.
|
||||
fn propagate(&self, _search: &mut PuzzleSearch, _var: VarToken, _val: Val) -> PsResult<()>;
|
||||
fn propagate(&self, _search: &mut PuzzleSearch, _var: VarToken, _val: Val) -> PsResult<()>;
|
||||
|
||||
/// Applied after a variable's candidates has been modified.
|
||||
fn on_updated(&self, _search: &mut PuzzleSearch) -> PsResult<()> {
|
||||
|
@ -13,9 +13,9 @@ use std::ops;
|
||||
|
||||
pub use constraint::Constraint;
|
||||
pub use error::Error;
|
||||
pub use linexpr::LinExpr;
|
||||
pub use puzzle::Puzzle;
|
||||
pub use puzzle::PuzzleSearch;
|
||||
pub use linexpr::LinExpr;
|
||||
|
||||
/// A puzzle variable token.
|
||||
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
|
||||
@ -27,7 +27,6 @@ pub type Val = i32;
|
||||
/// The type of the coefficients in a linear expression.
|
||||
pub type Coef = Rational32;
|
||||
|
||||
|
||||
/// A result during a puzzle solution search (Err = contradiction).
|
||||
pub type PsResult<T> = Result<T, Error>;
|
||||
|
||||
|
@ -38,13 +38,13 @@ impl From<&[Val]> for Candidates {
|
||||
}
|
||||
}
|
||||
|
||||
impl <const N: usize> From<&[Val; N]> for Candidates {
|
||||
impl<const N: usize> From<&[Val; N]> for Candidates {
|
||||
fn from(set: &[Val; N]) -> Self {
|
||||
Candidates::Set(Rc::new(set.iter().copied().collect()))
|
||||
}
|
||||
}
|
||||
|
||||
impl <const N: usize> From<[Val; N]> for Candidates {
|
||||
impl<const N: usize> From<[Val; N]> for Candidates {
|
||||
fn from(set: [Val; N]) -> Self {
|
||||
Candidates::Set(Rc::new(set.into_iter().collect()))
|
||||
}
|
||||
@ -200,7 +200,11 @@ impl Puzzle {
|
||||
/// let mut send_more_money = puzzle_solver::Puzzle::new();
|
||||
/// send_more_money.new_vars(8, &[0,1,2,3,4,5,6,7,8,9]);
|
||||
/// ```
|
||||
pub fn new_vars<C: Into<Candidates> + Clone>(&mut self, n: usize, candidates: C) -> Vec<VarToken> {
|
||||
pub fn new_vars<C: Into<Candidates> + Clone>(
|
||||
&mut self,
|
||||
n: usize,
|
||||
candidates: C,
|
||||
) -> Vec<VarToken> {
|
||||
let mut vars = Vec::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
vars.push(self.new_var(candidates.clone()));
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::ops::{Bound, RangeBounds};
|
||||
use ranges::GenericRange;
|
||||
use crate::Val;
|
||||
use ranges::GenericRange;
|
||||
use std::ops::{Bound, RangeBounds};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Ranges {
|
||||
|
@ -21,7 +21,7 @@ fn make_send_more_money() -> (Puzzle, Vec<VarToken>) {
|
||||
let send = 1000 * s + 100 * e + 10 * n + d;
|
||||
let more = 1000 * m + 100 * o + 10 * r + e;
|
||||
let money = 10000 * m + 1000 * o + 100 * n + 10 * e + y;
|
||||
|
||||
|
||||
sys.equals(send + more, money);
|
||||
|
||||
(sys, vars)
|
||||
@ -61,11 +61,11 @@ fn sendmoremoney_carry() {
|
||||
let (mut sys, vars) = make_send_more_money();
|
||||
let (s, e, n, d) = (vars[0], vars[1], vars[2], vars[3]);
|
||||
let (m, o, r, y) = (vars[4], vars[5], vars[6], vars[7]);
|
||||
|
||||
|
||||
let c1 = sys.new_var(&carry);
|
||||
let c2 = sys.new_var(&carry);
|
||||
let c3 = sys.new_var(&carry);
|
||||
|
||||
|
||||
sys.intersect_candidates(m, &carry); // c4 == m.
|
||||
|
||||
sys.equals(d + e, 10 * c1 + y);
|
||||
|
Loading…
Reference in New Issue
Block a user