Skip to content

Commit

Permalink
small update to parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreDubray committed Nov 26, 2024
1 parent 2f15e0d commit e1e44b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ impl Solution {
}

pub fn has_converged(&self, epsilon: f64) -> bool {
let conv_factor = F128!((1.0 + epsilon).powf(2.0));
self.upper_bound <= self.lower_bound.clone()*conv_factor //+ FLOAT_CMP_THRESHOLD
let conv_factor = F128!((1.0 + epsilon + 0.0000001).powf(2.0));
self.upper_bound <= self.lower_bound.clone()*conv_factor
}

pub fn print(&self) {
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/pg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ impl Parser for PgParser {
while content_index < content.len() {
let source = content[content_index];
let target = content[content_index + 1];
let proba_up = content[content_index + 2].parse::<f64>().unwrap();
let proba_up = F128!(content[content_index + 2].parse::<f64>().unwrap());
content_index += 3;
distributions.push(vec![F128!(proba_up), F128!(1.0 - proba_up)]);
distributions.push(vec![proba_up.clone(), F128!(1.0) - proba_up]);
let source_id = if !map_node_to_id.contains_key(source) {
map_node_to_id.insert(source, node_index);
node_index += 1;
Expand Down
8 changes: 7 additions & 1 deletion src/parsers/uai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use rustc_hash::FxHashMap;
use malachite::Rational;
use malachite::num::arithmetic::traits::Abs;
use crate::common::F128;

struct CPTConstraint {
Expand Down Expand Up @@ -141,7 +142,12 @@ impl Parser for UaiParser {

let mut choice_idx = 0;
for _ in 0..number_distribution {
let distribution = (0..distribution_size).map(|j| F128!(content[content_index + j].parse::<f64>().unwrap())).collect::<Vec<Rational>>();
let mut distribution = (0..distribution_size).map(|j| F128!(content[content_index + j].parse::<f64>().unwrap())).collect::<Vec<Rational>>();
// Ensures the distributions sums up to 1 in case the string representation is
// wrong (e.g., a distribution with three values 0.333 0.333 0.333, then the first
// one will be 0.334)
let diff = (F128!(1.0) - distribution.iter().sum::<Rational>()).abs();
distribution[0] += diff;
content_index += distribution_size;

let distribution_no_zero = (0..distribution.len()).filter(|j| distribution[*j] != 0.0).map(|j| distribution[j].clone()).collect::<Vec<Rational>>();
Expand Down

0 comments on commit e1e44b9

Please sign in to comment.