diff --git a/rust/ommx/src/convert/sample_set.rs b/rust/ommx/src/convert/sample_set.rs index 2f1b84c8..e5405d3e 100644 --- a/rust/ommx/src/convert/sample_set.rs +++ b/rust/ommx/src/convert/sample_set.rs @@ -81,6 +81,14 @@ impl Samples { }) } + pub fn states_mut(&mut self) -> impl Iterator { + self.entries.iter_mut().map(|v| { + v.state + .as_mut() + .expect("ommx.v1.Samples.Entry must has state. Broken Data.") + }) + } + /// Transpose `sample_id -> decision_variable_id -> value` to `decision_variable_id -> sample_id -> value` pub fn transpose(&self) -> HashMap { let mut map: HashMap, Vec>> = HashMap::new(); @@ -113,15 +121,6 @@ impl Samples { .collect::>()?, }) } - - pub fn map_state(&mut self, mut f: impl FnMut(&mut State) -> Result<()>) -> Result<()> { - for v in &mut self.entries { - f(v.state - .as_mut() - .context("ommx.v1.Samples.Entry must has state. Broken Data.")?)?; - } - Ok(()) - } } impl SampleSet { diff --git a/rust/ommx/src/evaluate.rs b/rust/ommx/src/evaluate.rs index a7622d85..a77300fa 100644 --- a/rust/ommx/src/evaluate.rs +++ b/rust/ommx/src/evaluate.rs @@ -466,11 +466,10 @@ impl Evaluate for Instance { // Reconstruct decision variable values let mut samples = samples.clone(); - samples.map_state(|s| { - let mut new = eval_dependencies(&self.decision_variable_dependency, s)?; + for state in samples.states_mut() { + let mut new = eval_dependencies(&self.decision_variable_dependency, state)?; used_ids.append(&mut new); - Ok(()) - })?; + } let mut transposed = samples.transpose(); let decision_variables: Vec = self .decision_variables