fn compute_solution_value_with_bfs<'a, G>(
        &self,
        variable: usize,
        new_solutions: &'a mut Vec<Option<G>>,
        reduced_solution: &SparseVector<G, G>,
    ) -> &'a G
    where
        G: LinearAlgebraElement<G> + Zero + From<OF> + Sum + Neg<Output=G>,
        for<'r> G: Add<&'r OF, Output=G>,
        for<'r> &'r G: Neg<Output=G> + Mul<&'r OF, Output=G> + Add<&'r OF, Output=G> + Sub<&'r G, Output=G>,
    {
        debug_assert!(variable < new_solutions.len());
        debug_assert_eq!(new_solutions.len(), self.original_variables.len());
        debug_assert_eq!(reduced_solution.len(), self.variables.len());

        if new_solutions[variable].is_some() {
            return new_solutions[variable].as_ref().unwrap();
        }

        let new_solution = match &self.original_variables[variable].1 {
            OriginalVariable::Active(j) => match reduced_solution.get(*j) {
                Some(value) => value.clone(),
                None => G::zero(),
            },
            OriginalVariable::ActiveFree(j_positive, j_negative) => {
                match (reduced_solution.get(*j_positive), reduced_solution.get(*j_negative)) {
                    (None, None) => G::zero(),
                    (Some(positive), None) => positive.clone(),
                    (None, Some(negative)) => -negative,
                    (Some(positive), Some(negative)) => positive - negative,
                }
            },
            OriginalVariable::Removed(Solved(ref v)) => v.clone().into(),
            OriginalVariable::Removed(FunctionOfOthers { constant, coefficients }) => {
                -coefficients.iter()
                    .map(|(j, coefficient)| {
                        self.compute_solution_value_with_bfs::<G>(*j, new_solutions, reduced_solution) * coefficient
                    })
                    .sum::<G>() + constant
            }
        };

        new_solutions[variable] = Some(new_solution);
        new_solutions[variable].as_ref().unwrap()
    }
/// Compute the solution value for a single variable.
///
/// This is a helper method of the `compute_full_solution_with_reduced_solution` function.
///
/// # Arguments
///
/// * `variable`: Index of the variable for which we try to determine an explicit solution.
/// Relative to the original problem with variables solved and unsolved.
/// * `new_solutions`: Collection containing solutions previously computed, that the computed
/// solution value will also be written in to (if it is determined).
/// * `reduced_solution`: Solution to the reduced problem (for all variables still active).
///
/// # Return value
///
/// The solution value for that variable. Can always be determined if the general form is
/// consistent (that is, there are no cycles in the original variables, see the
/// `is_consistent` function).
Compute the solution value for a single variable.
This is a helper method of the `compute_full_solution_with_reduced_solution` function.
Compute the solution value for a single variable . This is a helper method of the ` compute_full_solution_with_reduced_solution ` function .
fn compute_solution_value_with_bfs<'a, G>(
        &self,
        variable: usize,
        new_solutions: &'a mut Vec<Option<G>>,
        reduced_solution: &SparseVector<G, G>,
    ) -> &'a G
    where
        G: LinearAlgebraElement<G> + Zero + From<OF> + Sum + Neg<Output=G>,
        for<'r> G: Add<&'r OF, Output=G>,
        for<'r> &'r G: Neg<Output=G> + Mul<&'r OF, Output=G> + Add<&'r OF, Output=G> + Sub<&'r G, Output=G>,
    {
        debug_assert!(variable < new_solutions.len());
        debug_assert_eq!(new_solutions.len(), self.original_variables.len());
        debug_assert_eq!(reduced_solution.len(), self.variables.len());
        if new_solutions[variable].is_some() {
            return new_solutions[variable].as_ref().unwrap();
        }
        let new_solution = match &self.original_variables[variable].1 {
            OriginalVariable::Active(j) => match reduced_solution.get(*j) {
                Some(value) => value.clone(),
                None => G::zero(),
            },
            OriginalVariable::ActiveFree(j_positive, j_negative) => {
                match (reduced_solution.get(*j_positive), reduced_solution.get(*j_negative)) {
                    (None, None) => G::zero(),
                    (Some(positive), None) => positive.clone(),
                    (None, Some(negative)) => -negative,
                    (Some(positive), Some(negative)) => positive - negative,
                }
            },
            OriginalVariable::Removed(Solved(ref v)) => v.clone().into(),
            OriginalVariable::Removed(FunctionOfOthers { constant, coefficients }) => {
                -coefficients.iter()
                    .map(|(j, coefficient)| {
                        self.compute_solution_value_with_bfs::<G>(*j, new_solutions, reduced_solution) * coefficient
                    })
                    .sum::<G>() + constant
            }
        };
        new_solutions[variable] = Some(new_solution);
        new_solutions[variable].as_ref().unwrap()
    }
fn compute_solution_value_with_bfs < ' a , G > ( & self , variable : usize , new_solutions : & ' a mut Vec < Option < G > > , reduced_solution : & SparseVector < G , G > , ) -> & ' a G where G : LinearAlgebraElement < G > + Zero + From < OF > + Sum + Neg < Output = G > , for < ' r > G : Add < & ' r OF , Output = G > , for < ' r > & ' r G : Neg < Output = G > + Mul < & ' r OF , Output = G > + Add < & ' r OF , Output = G > + Sub < & ' r G , Output = G > , { debug_assert ! ( variable new_solutions len ( ) ) ; debug_assert_eq ! ( new_solutions len ( ) self original_variables len ( ) ) ; debug_assert_eq ! ( reduced_solution len ( ) self variables len ( ) ) ; if new_solutions [ variable ] . is_some ( ) { return new_solutions [ variable ] . as_ref ( ) . unwrap ( ) ; } let new_solution = match & self . original_variables [ variable ] . 1 { OriginalVariable :: Active ( j ) => match reduced_solution . get ( * j ) { Some ( value ) => value . clone ( ) , None => G :: zero ( ) , } , OriginalVariable :: ActiveFree ( j_positive , j_negative ) => { match ( reduced_solution . get ( * j_positive ) , reduced_solution . get ( * j_negative ) ) { ( None , None ) => G :: zero ( ) , ( Some ( positive ) , None ) => positive . clone ( ) , ( None , Some ( negative ) ) => - negative , ( Some ( positive ) , Some ( negative ) ) => positive - negative , } } , OriginalVariable :: Removed ( Solved ( ref v ) ) => v . clone ( ) . into ( ) , OriginalVariable :: Removed ( FunctionOfOthers { constant , coefficients } ) => { - coefficients . iter ( ) . map ( | ( j , coefficient ) | { self . compute_solution_value_with_bfs :: < G > ( * j , new_solutions , reduced_solution ) * coefficient } ) . sum :: < G > ( ) + constant } } ; new_solutions [ variable ] = Some ( new_solution ) ; new_solutions [ variable ] . as_ref ( ) . unwrap ( ) }
Compute the solution value for a single variable.
Compute the solution value for a single variable .
&self
variable
usize
new_solutions
&'a mut Vec<Option<G>>
reduced_solution
&SparseVector<G, G>
&self
variable
usize
new_solutions
&'a mut Vec<Option<G>>
reduced_solution
&SparseVector<G, G>
return value
The solution value for that variable. Can always be determined if the general form is
consistent (that is, there are no cycles in the original variables, see the
`is_consistent` function).
The solution value for that variable . Can always be determined if the general form is consistent ( that is there are no cycles in the original variables see the ` is_consistent ` function ) .