Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
strategy:
matrix:
include:
- os: macos-13
- os: macos-15-intel
name: x86_64-macosx.dylib
path: target/release/librsdd.dylib
- os: macos-14
- os: macos-15
name: aarch64-macosx.dylib
path: target/release/librsdd.dylib
- os: windows-latest
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "Rust decision diagrams."
resolver = "2"

[dependencies]
rand = { version = "0.8.5", features = [ "small_rng" ] }
rand = { version = "0.10" }
dimacs = "0.2.0"
primal = "0.3.0"
pretty = "0.3.3"
Expand All @@ -21,14 +21,14 @@ bit-set = "0.5.3"
segment-tree = "2.0.0"
bumpalo = "3.11.1"
petgraph = "0.5.1"
rand_chacha = "0.3.1"
rand_chacha = "0.10"
rational = "1.2.2"
# optional: only used to build [[bin]]
clap = { version = "4.2.1", features = ["derive"], optional = true }
serde_json = { version = "1.0.81", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }
getrandom = { version = "0.4.2", features = ["wasm_js"] }
serde_json = { version = "1.0.81" }
serde-wasm-bindgen = { version = "0.4" }
wasm-bindgen = { version = "0.2.84" }
Expand Down
6 changes: 3 additions & 3 deletions examples/marginal_map_experiment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, fs};

use clap::Parser;
use rand::Rng;
use rand::RngExt;
use rsdd::{
builder::{bdd::RobddBuilder, cache::AllIteTable, BottomUpBuilder},
repr::{BddPtr, Cnf, VarLabel, WmcParams},
Expand Down Expand Up @@ -37,10 +37,10 @@ fn gen_all_weights(
);
}

let mut rng = rand::thread_rng();
let mut rng = rand::rng();

for index in prev_weights.len()..num_vars {
let weight = rng.gen_range(0.0..1.0);
let weight = rng.random_range(0.0..1.0);
var_to_val.insert(
VarLabel::new(index as u64),
(RealSemiring(weight), RealSemiring(1.0 - weight)),
Expand Down
3 changes: 1 addition & 2 deletions examples/semantic_top_down_experiment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rsdd::{
};

use rand::seq::SliceRandom;
use rand::thread_rng;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
Expand Down Expand Up @@ -120,7 +119,7 @@ impl Iterator for RandomVarOrders {

let mut order: Vec<VarLabel> = (0..self.vars).map(VarLabel::new).collect();

order.shuffle(&mut thread_rng());
order.shuffle(&mut rand::rng());

Some(VarOrder::new(&order))
}
Expand Down
13 changes: 2 additions & 11 deletions src/builder/bdd/robdd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ impl<'a, T: IteTable<'a, BddPtr<'a>> + Default> BddBuilder<'a> for RobddBuilder<
r
}


fn cond_helper(&'a self, bdd: BddPtr<'a>, lbl: VarLabel, value: bool) -> BddPtr<'a> {
// bdd.clear_scratch();
let r = self.cond_with_alloc(bdd, lbl, value, &mut HashMap::new());
Expand Down Expand Up @@ -194,16 +193,8 @@ impl<'a, T: IteTable<'a, BddPtr<'a>> + Default> RobddBuilder<'a, T> {

// check cache
match cache.get(&bdd) {
None => {
()
},
Some(v) => {
return if bdd.is_neg() {
v.neg()
} else {
*v
}
}
None => (),
Some(v) => return if bdd.is_neg() { v.neg() } else { *v },
};

// recurse on the children
Expand Down
7 changes: 4 additions & 3 deletions src/ffi/bdd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,12 @@ unsafe extern "C" fn bdd_eq(

/// free the BDD manager `mgr`
#[no_mangle]
unsafe extern "C" fn free_bdd_manager(mgr : *mut RsddBddBuilder) -> () {
drop(Box::from_raw(mgr.cast::<RobddBuilder<'static, AllIteTable<BddPtr>>>()))
unsafe extern "C" fn free_bdd_manager(mgr: *mut RsddBddBuilder) -> () {
drop(Box::from_raw(
mgr.cast::<RobddBuilder<'static, AllIteTable<BddPtr>>>(),
))
}


#[no_mangle]
unsafe extern "C" fn bdd_topvar(bdd: *mut BddPtr) -> u64 {
match (*bdd).var_safe() {
Expand Down
28 changes: 21 additions & 7 deletions src/ffi/wmc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
// DDNNFPtr is required for the wmc method
repr::{VarLabel, WmcParams, BddPtr, DDNNFPtr},
util::semirings::{Complex, RealSemiring, Semiring},
repr::{BddPtr, DDNNFPtr, VarLabel, WmcParams},
// We import Polynomial and MAX_COEFFS from your implementation file
util::semirings::polynomial_semiring_implementation::{Polynomial, MAX_COEFFS},
util::semirings::{Complex, RealSemiring, Semiring},
};
use std::collections::HashMap;
use std::slice;
Expand Down Expand Up @@ -169,7 +169,9 @@ unsafe extern "C" fn wmc_param_poly_set_weight(
high_coeffs: *const f64,
high_len: usize,
) {
if weights.is_null() { return; }
if weights.is_null() {
return;
}

let low_poly = from_c_parts(low_coeffs, low_len);
let high_poly = from_c_parts(high_coeffs, high_len);
Expand All @@ -183,7 +185,10 @@ unsafe extern "C" fn wmc_param_poly_var_weight(
var: u64,
) -> WeightPoly {
if weights.is_null() {
return WeightPoly { low: std::ptr::null_mut(), high: std::ptr::null_mut() };
return WeightPoly {
low: std::ptr::null_mut(),
high: std::ptr::null_mut(),
};
}

let (l, h) = (*weights).var_weight(VarLabel::new(var));
Expand All @@ -192,12 +197,19 @@ unsafe extern "C" fn wmc_param_poly_var_weight(
let low_ptr = Box::into_raw(Box::new(*l));
let high_ptr = Box::into_raw(Box::new(*h));

WeightPoly { low: low_ptr, high: high_ptr }
WeightPoly {
low: low_ptr,
high: high_ptr,
}
}

#[no_mangle]
unsafe extern "C" fn polynomial_len(p: *mut PolyWeight) -> usize {
if p.is_null() { 0 } else { (*p).len }
if p.is_null() {
0
} else {
(*p).len
}
}

#[no_mangle]
Expand All @@ -206,7 +218,9 @@ unsafe extern "C" fn polynomial_get_coeffs(
buffer: *mut f64,
max_len: usize,
) -> usize {
if p.is_null() || buffer.is_null() { return 0; }
if p.is_null() || buffer.is_null() {
return 0;
}

let poly = &(*p);
let count = poly.len.min(max_len);
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mod plan;
pub mod repr;
pub mod serialize;


#[cfg(target_arch = "wasm32")]
pub mod wasm;

Expand Down
2 changes: 1 addition & 1 deletion src/repr/bdd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ impl<'a> BddPtr<'a> {
};
let l_s = print_bdd_helper(l_p);
let h_s = print_bdd_helper(h_p);
format!("({}, {}, {})", node.var.value(), h_s, l_s)
format!("({}, {}, {})", node.var.value(), h_s, l_s)
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/repr/cnf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
use petgraph::graph::NodeIndex;
use petgraph::prelude::UnGraph;
use quickcheck::{Arbitrary, Gen};
use rand::{self, rngs::ThreadRng, Rng};
use rand::{self, rngs::ThreadRng, RngExt};
use std::{
cmp::{max, min},
collections::HashSet,
Expand Down Expand Up @@ -369,12 +369,12 @@ impl Cnf {
if num_vars > 1 {
let mut var_vec: Vec<Literal> = Vec::new();
for _ in 0..clause_size {
let var = *vars.get(rng.gen_range(0..vars.len())).unwrap();
let var = *vars.get(rng.random_range(0..vars.len())).unwrap();
var_vec.push(var);
}
clause_vec.push(var_vec);
} else {
let var = *vars.get(rng.gen_range(0..vars.len())).unwrap();
let var = *vars.get(rng.random_range(0..vars.len())).unwrap();
clause_vec.push(vec![var]);
}
}
Expand Down Expand Up @@ -552,16 +552,16 @@ impl Cnf {

/// Updates the CNF to a new CNF that results from conditioning on the supplied literal
pub fn condition(&self, lit: Literal) -> Cnf {
let mut new_cnf : Vec<Vec<Literal>> = Vec::new();
let mut new_cnf: Vec<Vec<Literal>> = Vec::new();
'cnf: for clause in self.clauses.iter() {
let mut new_clause = Vec::new();
'clause: for l in clause.iter() {
if l.label() == lit.label() && l.polarity() == lit.polarity() {
// skip over this whole clause
continue 'cnf
continue 'cnf;
} else if l.label() == lit.label() && l.polarity() != lit.polarity() {
// skip over this literal
continue 'clause
// skip over this literal
continue 'clause;
} else {
// push the literal
new_clause.push(*l);
Expand Down Expand Up @@ -726,9 +726,7 @@ fn test_cnf_wmc() {

#[test]
fn test_cond() {
let v = vec![vec![
Literal::new(VarLabel::new(0), false),
]];
let v = vec![vec![Literal::new(VarLabel::new(0), false)]];
let cnf = Cnf::new(&v);
println!("{:?}", cnf.condition(Literal::new(VarLabel::new(0), true)));
}
6 changes: 3 additions & 3 deletions src/repr/ddnnf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
},
util::semirings::{BooleanSemiring, FiniteField, Semiring},
};
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;
use rand::RngExt;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use std::{collections::HashMap, fmt::Debug, hash::Hash};

/// creates a weighting that can be used for semantically hashing a DDNNF node
Expand All @@ -29,7 +29,7 @@ pub fn create_semantic_hash_map<const P: u128>(num_vars: usize) -> WmcParams<Fin

let value_range: Vec<(FiniteField<P>, FiniteField<P>)> = (0..vars.len() as u128)
.map(|_| {
let h = FiniteField::new(rng.gen_range(2..P));
let h = FiniteField::new(rng.random_range(2..P));
let l = FiniteField::new(P - h.value() + 1);
(l, h)
})
Expand Down
6 changes: 3 additions & 3 deletions src/repr/logical_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{repr::VarLabel, serialize::LogicalSExpr};
use dimacs::*;
use rand::{self, rngs::ThreadRng, Rng};
use rand::{self, rngs::ThreadRng, RngExt};
use std::collections::HashMap;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -156,7 +156,7 @@ impl LogicalExpr {
if num_vars > 1 {
let mut var_vec: Vec<LogicalExpr> = Vec::new();
for _ in 0..clause_size {
let var = vars.get(rng.gen_range(0..vars.len())).unwrap().clone();
let var = vars.get(rng.random_range(0..vars.len())).unwrap().clone();
var_vec.push(var);
}
let l1 = var_vec.pop().unwrap();
Expand All @@ -168,7 +168,7 @@ impl LogicalExpr {
});
clause_vec.push(new_expr);
} else {
let var = vars.get(rng.gen_range(0..vars.len())).unwrap().clone();
let var = vars.get(rng.random_range(0..vars.len())).unwrap().clone();
clause_vec.push(var);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/repr/vtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
util::btree::{BTree, LeastCommonAncestor},
};
use quickcheck::{Arbitrary, Gen};
use rand::{rngs::SmallRng, seq::SliceRandom, Rng, SeedableRng};
use rand::{rngs::SmallRng, seq::SliceRandom, RngExt, SeedableRng};
use rand_chacha::ChaCha8Rng;
use std::collections::HashSet;

Expand Down Expand Up @@ -222,11 +222,11 @@ impl VTree {
),
len => {
// clamps so we're guaranteed at least one item in l_s, r_s
let mut rng = ChaCha8Rng::from_entropy();
let mut rng = ChaCha8Rng::from_rng(&mut rand::rng());

// let mut split_index = rng.gen_range(1..(len/2+1));
let weighted_index =
(rng.gen_range(0..len - 1) as f64 * (1.0 - rightness_bias)) as usize;
(rng.random_range(0..len - 1) as f64 * (1.0 - rightness_bias)) as usize;
let split_index = weighted_index + 1;

let (l_s, r_s) = order.split_at(split_index);
Expand Down
6 changes: 3 additions & 3 deletions src/util/semirings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ mod boolean;
mod complex;
mod expectation;
mod finitefield;
pub mod polynomial_semiring_implementation;
mod rational;
mod realsemiring;
mod semiring_traits;
mod tropical;
pub mod polynomial_semiring_implementation;


pub use self::boolean::*;
pub use self::complex::*;
pub use self::expectation::*;
pub use self::finitefield::*;
pub use self::polynomial_semiring_implementation::*;
pub use self::rational::*;
pub use self::realsemiring::*;
pub use self::semiring_traits::*;
pub use self::polynomial_semiring_implementation::*;
pub use self::tropical::*;
7 changes: 4 additions & 3 deletions src/util/semirings/polynomial_semiring_implementation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::util::semirings::Semiring;
use std::ops;
use core::fmt::{self, Debug, Display};
use std::ops;

// Define a maximum degree (e.g., 32 coefficients).
// This makes the struct size predictable and allows 'Copy'.
Expand Down Expand Up @@ -88,7 +88,8 @@ impl<C: Semiring + Copy> ops::Mul for Polynomial<C> {
for i in 0..self.len {
for j in 0..rhs.len {
if i + j < MAX_COEFFS {
new_coeffs[i + j] = new_coeffs[i + j] + (self.coefficients[i] * rhs.coefficients[j]);
new_coeffs[i + j] =
new_coeffs[i + j] + (self.coefficients[i] * rhs.coefficients[j]);
}
}
}
Expand All @@ -98,4 +99,4 @@ impl<C: Semiring + Copy> ops::Mul for Polynomial<C> {
len: new_len,
}
}
}
}
Loading
Loading