Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
QuestionProblem in reading excel from server folder Pin
Krishna Varadharajan9-Mar-09 20:29
Krishna Varadharajan9-Mar-09 20:29 
AnswerRe: Problem in reading excel from server folder Pin
Mycroft Holmes9-Mar-09 21:16
professionalMycroft Holmes9-Mar-09 21:16 
AnswerRe: Problem in reading excel from server folder Pin
Jack Li9-Mar-09 23:06
Jack Li9-Mar-09 23:06 
Questionhow to search a word in word document and capture the immediate next word and insert it into the DB Pin
Ferdin9-Mar-09 19:33
Ferdin9-Mar-09 19:33 
AnswerRe: how to search a word in word document and capture the immediate next word and insert it into the DB Pin
Mycroft Holmes9-Mar-09 21:18
professionalMycroft Holmes9-Mar-09 21:18 
GeneralRe: how to search a word in word document and capture the immediate next word and insert it into the DB Pin
Ferdin9-Mar-09 21:34
Ferdin9-Mar-09 21:34 
GeneralRe: how to search a word in word document and capture the immediate next word and insert it into the DB Pin
Mycroft Holmes9-Mar-09 23:24
professionalMycroft Holmes9-Mar-09 23:24 
QuestionRecursion logic and performance tuning Pin
Mathew Hall9-Mar-09 19:08
Mathew Hall9-Mar-09 19:08 
I have a uni assignment where I need to recursively process a large number of nodes in a dependency graph in order to calculate the ripple impact. I have come up with a solution that I think is correct, however I'm seeking confirmation of whether my logic is correct, and if so, is there any way to make it faster (and yes, I could post this to the forum for this uni subject, but since we'll be put in groups based on how well we do individually I'm reluctant to do so since I could be heading down the right track).

First some background info:

Fan-Out metric is the number of classes that a particular class relies 
on. Fan-In metric is the number of classes that make use of a given class. 
The ripple impact measure counts the total number of classes that might 
have an impact when any single class is changed. Based on the dependency 
graph above, if we were to modify "E", the ripple will impact B directly, 
since B has an impact this will impact A as well. In short any change made 
to ‘E’ can have a potential ripple impact on B and A.

The nodes in the dependency graph that have a Fan-Out of Zero are known as 
a Sink node. Nodes that have a Fan-In of zero are known as Source nodes.

In the dependency graph shown, we can extract the following information:
• A: Fan-out = 1 [B], Fan-In = 0, Impact-Ripple = 0
• B: Fan-Out = 3 [D, E, F], Fan-In = 1 [A], Impact-Ripple = 1 [A]
• C: Fan-Out = 1 [D], Fan-In = 1 [F], Impact-Ripple = 4 [F, D, B, A]
• D: Fan-Out = 1 [F], Fan-In = 2 [C, B], Impact-Ripple = 4 [B,A,C, F]
• E: Fan-Out = 0, Fan-In = 1, Impact-Ripple = 2 [B,A]
• F: Fan-Out = 1, Fan-In = 2, Impact-Ripple = 4 [B,D,A,C]
• Sink nodes: E, Source nodes: A


So in order to calculate the ripple impact you need to recurse through a node's fan-in nodes and add them to a list unless you either a) run into a source node or b) find a node you've already processed.

Here's what I have so far:

public class Node
{
   ...

   public List<Node> FanIn
   {
       get
       {
           return this.fanIn;
       }
   }

   public HashSet<Node> Ripple
   {
       get
       {
            HashSet<Node> rippleSet = new HashSet<Node>();
            
            // add this node for easy cycle checking so we don't
            // process ourself twice
            rippleSet.Add(this);
            
            // call our recursive function
            this.CalcRipple(rippleSet);

            // remember to remove us so we don't skew the result
            rippleSet.Remove(this);

            return rippleSet;
       }
   }

   private void CalcRipple(HashSet<Node> rippleSet)
   {
       // source nodes exit here...
       foreach (Node node in this.FanIn)
       {
            // try and add the node to the set - if it fails then we
            // have already visited it before as it already exists in
            // the set, other wise the node gets added and we need to 
            // process its fan-in nodes. 
            //
            // as far as i can tell this results in us performing a
            // depth first traversal of the graph
            if (rippleSet.Add(node))
            {
                node.CalcRipple(rippleSet);
            }
        }
   }

   ...
}


With a data set of 9,749 nodes (with 1459 source nodes, 1459 sink nodes and a max fan-in count of 1469 nodes), a full ripple impact calculation for each node takes ~26 seconds all up (and another 30 seconds to write it all to the hard drive resulting in a 630 meg file - all references are stored as strings Frown | :( ) on my Athlon XP 2100+

So my questions are:
* Does my ripple-impact calculations look correct, and if so
* Can anyone find any other optimisations I may have missed apart from using a hash collection for speedy lookups?

"I think I speak on behalf of everyone here when I say huh?" - Buffy

QuestionKill the DLL Pin
yesu prakash9-Mar-09 18:47
yesu prakash9-Mar-09 18:47 
AnswerRe: Kill the DLL Pin
User 23822929-Mar-09 19:13
User 23822929-Mar-09 19:13 
GeneralRe: Kill the DLL Pin
yesu prakash9-Mar-09 19:20
yesu prakash9-Mar-09 19:20 
AnswerRe: Kill the DLL Pin
Dragonfly_Lee9-Mar-09 19:31
Dragonfly_Lee9-Mar-09 19:31 
Questionproject doubt Pin
vinithakizhussery9-Mar-09 18:31
vinithakizhussery9-Mar-09 18:31 
AnswerRe: project doubt Pin
Christian Graus9-Mar-09 18:42
protectorChristian Graus9-Mar-09 18:42 
AnswerRe: project doubt Pin
yesu prakash9-Mar-09 18:56
yesu prakash9-Mar-09 18:56 
AnswerRe: project doubt Pin
yesu prakash9-Mar-09 19:14
yesu prakash9-Mar-09 19:14 
AnswerRe: project doubt Pin
Dragonfly_Lee9-Mar-09 19:33
Dragonfly_Lee9-Mar-09 19:33 
AnswerRe: project doubt Pin
0x3c09-Mar-09 20:44
0x3c09-Mar-09 20:44 
AnswerRe: project doubt Pin
#realJSOP10-Mar-09 2:33
mve#realJSOP10-Mar-09 2:33 
AnswerRe: project doubt Pin
Nagy Vilmos10-Mar-09 2:50
professionalNagy Vilmos10-Mar-09 2:50 
AnswerRe: project doubt Pin
Zhat10-Mar-09 3:00
Zhat10-Mar-09 3:00 
GeneralRe: project doubt Pin
vinithakizhussery10-Mar-09 4:59
vinithakizhussery10-Mar-09 4:59 
AnswerRe: project doubt Pin
Wes Aday10-Mar-09 4:36
professionalWes Aday10-Mar-09 4:36 
AnswerRe: project doubt Pin
Rutvik Dave10-Mar-09 4:38
professionalRutvik Dave10-Mar-09 4:38 
GeneralRe: project doubt Pin
vinithakizhussery10-Mar-09 5:10
vinithakizhussery10-Mar-09 5:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.