Commit 3a33fcdf authored by Bharat Garhewal's avatar Bharat Garhewal
Browse files

More cleanup

parent 0a5a49b6
......@@ -307,10 +307,7 @@ where
for (q, i) in
Itertools::cartesian_product(basis.iter().copied(), hyp_input_alphabet.iter().copied())
{
if o_tree.get_out(q, i).is_none() {
println!("Something is wrong!");
}
let output = o_tree.get_out(q, i).expect("Safe");
let output = o_tree.get_out(q, i).expect("Something is wrong");
hyp_output_alphabet.insert(output);
let succ = o_tree
.get_succ(q, &[i])
......@@ -367,18 +364,18 @@ where
/// Check if the frontier is consistent with our data structures.
/// CE processing may add a new frontier state that we miss.
fn check_frontier_consistency(&mut self) {
let basis_set = &self.basis;
let input_alph = self.input_size;
let basis_set = self.basis.iter().copied();
let temp = RefCell::borrow(&self.oq_oracle);
let o_tree = temp.borrow_tree();
let ia = toolbox::inputs_iterator(input_alph).collect_vec();
let state_input_iterator = Itertools::cartesian_product(basis_set.iter().copied(), ia);
let ia = toolbox::inputs_iterator(self.input_size).collect_vec();
let state_input_iterator = Itertools::cartesian_product(basis_set, ia);
let new_front = state_input_iterator
.filter_map(|(bs, i)| o_tree.get_succ(bs, &[i]))
.filter(|x| !self.basis.contains(x))
.filter(|x| !self.frontier_to_basis_map.contains_key(x))
.map(|fs| {
let maps_to: Vec<_> = basis_set
let maps_to: Vec<_> = self
.basis
.par_iter()
.copied()
.filter(|&s| !states_are_apart(o_tree, fs, s))
......@@ -386,11 +383,13 @@ where
(fs, maps_to)
})
.collect::<Vec<_>>();
for (fs, mut bs_set) in new_front {
for (fs, bs_set) in new_front {
self.frontier_to_basis_map
.entry(fs)
.and_modify(|bs_vec| bs_set.drain(..).for_each(|x| bs_vec.push(x)))
.or_insert_with(|| bs_set.into_iter().collect());
.or_default()
.extend(bs_set);
// .and_modify(|bs_vec| bs_vec.extend(bs_set))
// .or_insert_with(|| bs_set.into_iter().collect());
}
}
......
......@@ -14,7 +14,7 @@ use crate::{
hads_tree::HadsTree,
incomplete::iads::IadsEO,
sep_seq::SequenceOracle,
soucha::{ConfigBuilder as SouchaConfigBuilder, SouchaOracle},
soucha::{ConfigBuilder as SouchaConfigBuilder, Oracle as SouchaOracle},
},
membership::Oracle as OQOracle,
},
......@@ -26,6 +26,7 @@ use crate::{
};
use fnv::{FnvHashMap, FnvHashSet};
use rand::{prelude::StdRng, Rng, SeedableRng};
use std::collections::HashMap;
use std::{cell::RefCell, hash::BuildHasherDefault, rc::Rc, sync::Arc};
#[derive(derive_builder::Builder)]
......@@ -43,10 +44,10 @@ pub struct Options {
#[allow(clippy::type_complexity)]
#[allow(clippy::too_many_lines)]
#[must_use]
pub fn learn_fsm(
pub fn learn_fsm<S: ::std::hash::BuildHasher>(
sul: &Mealy,
input_map: FnvHashMap<String, InputSymbol>,
output_map: FnvHashMap<String, OutputSymbol>,
input_map: &HashMap<String, InputSymbol, S>,
output_map: &HashMap<String, OutputSymbol, S>,
options: &Options,
logs: Option<Vec<(Box<[InputSymbol]>, Box<[OutputSymbol]>)>>,
) -> LearnResult {
......
......@@ -3,8 +3,8 @@
//! # L# Learning Library
//!
//! This library implements the L# learning algorithm
//! as mentioned in `A New Approach for Active Automata Learning Based on Apartness` at TACAS 2022,
//! [link](<https://rdcu.be/cO36l>).
//! as mentioned in the paper "``A New Approach for Active Automata Learning Based on Apartness``"
//! at TACAS 2022, [link](<https://rdcu.be/cO36l>).
//! Source code is available [here](<https://gitlab.science.ru.nl/sws/lsharp>).
pub mod ads;
......
......@@ -136,7 +136,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let file_name = file_name;
let result_vec: &mut Vec<u8> = &mut result_vec;
let f: &mut fs::File = &mut f;
let learn_results = learn_fsm(&fsm, input_map, output_map, options, fsm_logs);
let learn_results = learn_fsm(&fsm, &input_map, &output_map, options, fsm_logs);
println!("Learning finished!\n{}", learn_results);
writeln!(
result_vec,
......@@ -186,7 +186,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let file_name: &Path = file_name;
let result_vec: &mut Vec<u8> = &mut result_vec;
let f: &mut fs::File = &mut f;
let learn_results = learn_fsm(&fsm, input_map, output_map, options, None);
let learn_results = learn_fsm(&fsm, &input_map, &output_map, options, None);
println!("Learning finished!\n{}", learn_results);
writeln!(
result_vec,
......
......@@ -127,8 +127,8 @@ where
.kill()
.expect("Could not manage to kill H-ADS process.");
let ce_input = input_vec.clone();
let ce_output = sut_output.to_vec();
let ret = Some((ce_input.to_vec(), ce_output));
let ce_output = sut_output;
let ret = Some((ce_input, ce_output));
return ret;
}
}
......
......@@ -64,7 +64,7 @@ impl Display for Method {
}
}
pub struct SouchaOracle<'a, Tree> {
pub struct Oracle<'a, Tree> {
oq_oracle: Rc<RefCell<OQOracle<'a, Tree>>>,
_executable_loc: String,
rev_input_map: FnvHashMap<InputSymbol, String>,
......@@ -73,7 +73,7 @@ pub struct SouchaOracle<'a, Tree> {
config: Config,
}
impl<'a, T> ExternalEquivalenceOracle<'a, T> for SouchaOracle<'a, T>
impl<'a, T> ExternalEquivalenceOracle<'a, T> for Oracle<'a, T>
where
T: ObservationTree + Sync + Send,
{
......@@ -91,24 +91,24 @@ where
fn with_location(
output_oracle: Rc<RefCell<OQOracle<'a, T>>>,
config: Config,
_location: String,
_lookahead: usize,
location: String,
lookahead: usize,
_random_seed: u64,
rev_input_map: FnvHashMap<InputSymbol, String>,
rev_output_map: FnvHashMap<OutputSymbol, String>,
) -> Self {
Self {
oq_oracle: output_oracle,
_executable_loc: _location,
_executable_loc: location,
rev_input_map,
rev_output_map,
_lookahead,
_lookahead: lookahead,
config,
}
}
}
impl<'a, T: ObservationTree + Send + Sync> SouchaOracle<'a, T> {
impl<'a, T: ObservationTree + Send + Sync> Oracle<'a, T> {
fn soucha_process(&self) -> Child {
let fsmlib_path = std::fs::canonicalize(self.config.exec_loc().clone()).expect("Safe");
Command::new(fsmlib_path)
......@@ -210,7 +210,7 @@ impl<'a, T: ObservationTree + Send + Sync> SouchaOracle<'a, T> {
}
}
impl<'a, T> EquivalenceOracle<'a, T> for SouchaOracle<'a, T>
impl<'a, T> EquivalenceOracle<'a, T> for Oracle<'a, T>
where
T: ObservationTree + Sync + Send,
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment