private static int PropagateNodeWeight(AST.Address node, DAG dag) { // if the node is a formula, recursively // compute its weight if (dag.isFormula(node)) { // get input nodes var vector_rngs = dag.getFormulaInputVectors(node); var scinputs = dag.getFormulaSingleCellInputs(node); var inputs = vector_rngs.SelectMany(vrng => vrng.Addresses()).ToList(); inputs.AddRange(scinputs); // call recursively and sum components var weight = 0; foreach (var input in inputs) { weight += PropagateNodeWeight(input, dag); } dag.setWeight(node, weight); return(weight); } // node is an input else { dag.setWeight(node, 1); return(1); } }
// Propagate weights private static void PropagateWeights(DAG dag) { if (dag.containsLoop()) { throw new ContainsLoopException(); } // starting set of functions; roots in the forest var formulas = dag.terminalFormulaNodes(false); // for each forest foreach (AST.Address f in formulas) { dag.setWeight(f, PropagateNodeWeight(f, dag)); } }
private static int PropagateNodeWeight(AST.Address node, DAG dag) { // if the node is a formula, recursively // compute its weight if (dag.isFormula(node)) { // get input nodes var vector_rngs = dag.getFormulaInputVectors(node); var scinputs = dag.getFormulaSingleCellInputs(node); var inputs = vector_rngs.SelectMany(vrng => vrng.Addresses()).ToList(); inputs.AddRange(scinputs); // call recursively and sum components var weight = 0; foreach (var input in inputs) { weight += PropagateNodeWeight(input, dag); } dag.setWeight(node, weight); return weight; } // node is an input else { dag.setWeight(node, 1); return 1; } }