Rookie Programming Questions....

Jan 5, 2012 at 11:04 PM

I would like to get started with Programming against the Node XL CLass libraries.  I was able to build the Node XL project in Visual Studio 2008, but I'm not clear as to how to proceed from here.   I am assuming that I need to create a new Visual Studio Solution and then add the appropriate references to any projects within this solution.  What I want to do after running a data mining exercise is to problematically (1) open an instance of the Node XL Template, (2) write the names of the edges (from the data mining project) in columns A and B of the "Edges" sheet and then kick off the creation of a network graph, (3) grab the X and Y co-ordinates for each vertex from the list of vertices and save them in a database.  I've done things like this before using VBA within MS Office applications, so where I need help relates to how to initialize the Node XL template and execute Node XL specific commands in code.  I bought the Node XL Book from Morgan Kaufmann which is great for getting up to speed with using Node XL, but it doesn't go into much detail with regards to programming against the Node XL API.  My thanks for any perspective and guidance with getting started.  Best wishes, Michael

Jan 6, 2012 at 6:55 AM

Michael:

The NodeXL Class Libraries are meant for use in custom applications that manipulate and display network graphs.  The NodeXL Class Libraries won't let you interface to the NodeXL Excel Template, which is our own custom application.  The NodeXL Excel Template uses the NodeXL Class Libraries.  Other applications also use the NodeXL Class Libraries, but those applications have nothing to do with the NodeXL Excel Template.  And an application that uses the NodeXL Class Libraries does not need the NodeXL Source Code, which is a separate download.  I hope you're still with me.

Before I offer advice on a route to take, tell me this: Is your end goal strictly to generate X/Y coordinates for your data-mined vertices?  Do you need a visible graph at all?

(And I hope you meant to say that you want to do things programmatically, not problematically.  We programmers have enough problems as it is.)

-- Tony

Jan 6, 2012 at 6:21 PM

Friday

Hi Tony:

Thanks very much for your reply to my post – which was helpful – I’m a bit clearer as to how the pieces fit together.

In the short term, what I’d like to do is load data-mined vertices into an instance of a “Node XL” enabled XL file and run the appropriate methods to generate a graph (using the appropriate parameters so that I could pick the graph type), access the various graph metrics, including the X/Y axis co-ordinates for each node within the network, and then save these metrics within a data model, and then save the Excel file I have been working with to disk with a dynamically generated file name. As per your question - this short term goal does not actually require a visible graph that I would then manipulate post creating it.

I am assuming that this would (definitely programmatically!) involve stepping through the tasks below from within a calling application:

1. creating an instance of Excel 2007

2. opening a “Node XL enabled” Excel file from within that instance

3. using the Excel Range object to write the data-mined vertices into columns A and B of the Edges Sheet

4. Creating a “Graph” object within the NodeXL enabled XL file and providing parameters to that object as to graph type, etc.

5. Calling the appropriate “showGraph” method

6. Ensuring that the desired graph metrics (X / Y points, betweeness, in-degree, etc.) have been generated in the Vertices sheet.

7. For each Vertex in Vertices sheet:

a. Retrieve get the values of the graph metrics

b. Load these metrics by Vertex into a destination database table

Move on to the next vertex in the Vertices sheet until metrics for all Vertexes have been loaded in the destination database

8. Save the Excel file containing the generated metrics under a dynamically named file for future reference.

I can handle the programming involved with steps 1, 2, 3, 7, and 8. It’s points 4, 5, and 6 that I’m not clear how to do.

In the longer term, I’d like to take a crack at integrating NodeXL functionality into a WPF Application. To do this, am I correct in assuming that I need to insert an “executable” Project type into the Solution containing the class libraries that would be able to call upon the functionality of the class libraries? I ask as post successfully building the Node XL Class library project, I tried to create a new Visual Studio 2008 project and reference the Node XL class libraries, but they were not an available .NET Assembly reference.

I’m not clear as to the role of the NodeXL Source Source Code - and how it differs from the class libraries. They appear to closely resemble each other, so I’m obviously missing something.

I’m an independent consultant who has been interested in network topologies for a while, but I’m still at the beginning stage in terms of figuring out how to design scene graph based applications that normal business users will be able to drive business insight from without being overwhelmed. My compliments to you for the impressive work you have done, and to your patience and dedication. I will make a donation to support the project today.

Thanks for reading this – and for any advice you can provide when you get a chance.

Best Wishes,

Michael

Michael Martin | Managing Partner

Business Information Arts, Inc.

michael@informationarts.ca

416.486.4101

www.informationarts.ca

New_IA_2

See what your business looks like

Jan 6, 2012 at 8:17 PM
Edited Jan 6, 2012 at 8:23 PM

Hello, Michael:

Your idea isn't practical.  As you know, you can "drive" Excel from an external application using the Excel object model, which will allow you to perform steps 1, 2, 3, 7 and 8.  However, steps 4, 5 and 6 all involve custom NodeXL code within the workbook, and that code is not accessible from outside the workbook.  There is nothing in the Excel object model that will let you press NodeXL's "Show Graph" button, for example.  So you can populate the NodeXL workbook with an edge list, but you won't be able to show the graph or access any of the other NodeXL features that are designed for user interaction, not programmatic manipulation.

Do you really need Excel for anything?  If not, you can create your own console, Windows Forms or WPF application that uses NodeXL to populate, show and analyze graphs.  Such an application would use the NodeXL Class Libraries, but not the NodeXL Source Code or the NodeXL Excel Template.  (I'll try to clarify what those downloads are for in a follow-up post.)

If you don't need Excel, I can provide more details on developing your own application.

-- Tony

 

Jan 6, 2012 at 8:22 PM
Edited Jan 6, 2012 at 8:27 PM

Available NodeXL downloads:

* NodeXL Class Libraries:  Precompiled .NET assemblies for adding network graphs to custom applications.  For programmers.  Source code not required.

* NodeXL Excel Template:  Excel template for working with network graphs in the Excel window.  Uses the NodeXL Class Libraries internally.  For non-programmers.  Source code not required.

* NodeXL Source Code:  Complete source code for building the NodeXL Class Libraries and the NodeXL Excel Template.  For programmers who want to customize the NodeXL Class Libraries or the NodeXL Excel Template.  Not required otherwise.

Jan 6, 2012 at 11:07 PM

Friday

Hi Tony:

Thanks for going through my last post and getting back to me. For starters, I don’t think I need XL, nor do I think I absolutely need the Node XL WPF control for manipulating the graph after it has been generated as I use another BI application to render and manipulate scene graphs.

Following your line of thinking, creating a Windows Forms application that utilizes the Class Libraries makes the most sense. What I would like this application to do (at least the initial implementation) is to provide a context in which I can place the “data-mined” vertices (i.e. pairs of associated items), feed in the parameters needed to create a graph and generate the required graph metrics (including the X/Y co-ordinates) , and load these metrics into an external database.

I could very well imagine a later implementation that would allow me to manipulate the scene graph within the WPF control first before invoking code to grab the metrics and load then into the external database – but I’m figuring it’s better to learn to walk (programmatically!) before trying to run.

Any suggestions you’d care to make as to what approach I should follow, or what steps I should follow in what order, would be most appreciated.

Thanks and best wishes,

Michael

Jan 7, 2012 at 9:06 PM
Edited Jan 7, 2012 at 9:07 PM

Hello, Michael:

Okay, now you're in the realm of what NodeXL can accomplish for you.

Here is an outline of an approach you might take:

1. Discard the NodeXL source code, or at least put it in a folder called NotRequiredAndIsDistracting.

2. Download the latest version of the NodeXL Class Libraries if you haven't already done so.

3. In Visual Studio 2008 or 2010, create a new solution with a new Windows Forms project.

4. In your Windows Forms project, add references to the following NodeXL assemblies:

Smrf.NodeXL.Core.dll
Smrf.NodeXL.Layouts.dll
Smrf.NodeXL.Algorithms.dll.

5. In your Form1.cs file, import the following namespaces:

using Smrf.NodeXL.Core;
using Smrf.NodeXL.Layouts;
using Smrf.NodeXL.Algorithms;

6. Create a Graph object and populate it with data-mined vertices.  Note that a Graph object exists independently of its visual representation, so you can create and manipulate a Graph without ever showing it.

Graph oGraph = new Graph(GraphDirectedness.Undirected);
IVertexCollection oVertices = oGraph.Vertices;
IVertex oVertex1 = oVertices.Add();
IVertex oVertex2 = oVertices.Add();
IVertex oVertex3 = oVertices.Add();

7. Connect the vertices with edges:

IEdgeCollection oEdges = oGraph.Edges;
oEdges.Add(oVertex1, oVertex2);
oEdges.Add(oVertex1, oVertex3);

8. Lay out the graph within a 100x100 rectangle..  All the layout classes in NodeXL have one job, which is to set the Location property on each of the graph's vertices.

FruchtermanReingoldLayout oLayout = new FruchtermanReingoldLayout();
LayoutContext oLayoutContext = new LayoutContext(new Rectangle(0, 0, 100, 100));
oLayout.LayOutGraph(oGraph, oLayoutContext);

9. Get the laid-out vertex locations.

Debug.WriteLine("oVertex1.Location = " + oVertex1.Location);
Debug.WriteLine("oVertex2.Location = " + oVertex2.Location);
Debug.WriteLine("oVertex3.Location = " + oVertex3.Location);

10. Calculate some graph metrics; vertex degree, for example.  Note that there is an entire family of "GraphMetricCalculator" classes in the Smrf.NodeXL.Algorithms namespace.

VertexDegreeCalculator oVertexDegreeCalculator = new VertexDegreeCalculator();
Dictionary<Int32, VertexDegrees> oVertexDegreeDictionary = oVertexDegreeCalculator.CalculateGraphMetrics(oGraph);

Debug.WriteLine("Degree of oVertex1 = " + oVertexDegreeDictionary[oVertex1.ID].Degree);
Debug.WriteLine("Degree of oVertex2 = " + oVertexDegreeDictionary[oVertex2.ID].Degree);
Debug.WriteLine("Degree of oVertex3 = " + oVertexDegreeDictionary[oVertex3.ID].Degree);

11. See the NodeXLApi.chm help file for details about all these classes and more.

-- Tony

 


 

Jan 9, 2012 at 10:32 PM

Monday

Hi Tony:

Thanks very much for your last post which is getting me started – I followed your steps - all works quite well and am starting to feel my way around the API.

Can you possibly point me in the right direction towards sample code that describes how to retrieve the various centrality (Closeness, Betweeness, Eigenvector, etc.) metrics using the Brandes or other objects?

I tinkered with various method calls for a few hours today, but could not get them right. I modeled my calls after the call you provided re: the Vertex Degree Calculator, which may not be what I should have tried to do.

I am really enjoying working with the NodeXL API and really appreciate the work that has been done.

Best Wishes,

Michael

Jan 10, 2012 at 5:57 AM
Edited Jan 10, 2012 at 5:58 AM

Michael:

The graph metric calculators do follow the same pattern.  They all return a Dictionary<Int32, Something>, where the Int32 key is a Vertex.ID and the Something value depends on the specific graph metric calculator.

For example, to calculate betweenness and closeness centralities:

// If the SnapGraphMetricCalculator.exe file is not in the same folder as the
// Algorithms.dll assembly, we need to tell NodeXL where to find it.

GraphMetricCalculatorBase.SetSnapGraphMetricCalculatorPath(
 @"C:\SomePath\SnapGraphMetricCalculator.exe");

BrandesFastCentralityCalculator oBrandesFastCentralityCalculator =
 new BrandesFastCentralityCalculator();

Dictionary<Int32, BrandesVertexCentralities>
 oBrandesVertexCentralityDictionary =
 oBrandesFastCentralityCalculator.CalculateGraphMetrics(oGraph);

Debug.WriteLine("Betweenness centrality of oVertex1 = "
 + oBrandesVertexCentralityDictionary[oVertex1.ID].BetweennessCentrality);

Debug.WriteLine("Closeness centrality of oVertex1 = "
 + oBrandesVertexCentralityDictionary[oVertex1.ID].ClosenessCentrality); 



Or to calculate eigenvector centralities:

EigenvectorCentralityCalculator oEigenvectorCentralityCalculator =
 new EigenvectorCentralityCalculator();

Dictionary<Int32, Double> oEigenvectorCentralityDictionary =
 oEigenvectorCentralityCalculator.CalculateGraphMetrics(oGraph);

Debug.WriteLine("Eigenvector centrality of oVertex1 = "
 + oEigenvectorCentralityDictionary[oVertex1.ID]);

-- Tony

 

 

Jan 12, 2012 at 2:31 PM

Thursday

Hi Tony:

Thanks very much for the advice in your last post – which did the trick! I looked through the API help file to find more information about TestGraphDataProviders.exe, NodeXLNetworkServer.exe, RegisterUser.exe, and test TestWpfNodeXLControl.exe, but could not find references to them.

I am assume that like SnapGraphCalculator, each of the exe files above provide specific functionalities you can be called as in the code snippet your forwarded re: the SnapGraphCalculator. Is there documentation that covers these points?

I saw a reference to a document named NodeXLNetworkServerFAQ.docx at http://nodexl.codeplex.com/SourceControl/changeset/view/54291 but there is no link to this document – is it still available?

Thanks and best wishes,

Michael

Jan 12, 2012 at 7:09 PM
Edited Jan 12, 2012 at 7:10 PM

Hello, Michael:

No, wrong assumption.

The SnapGraphMetricCalculator.exe executable ships with the NodeXL Class Libraries because it gets called internally from the Smrf.NodeXL.Algorithms.dll assembly.  It has to be included in your custom application if you use certain classes in that assembly.  (However, you never call the executable directly, you don't need to know how it works, and it is therefore not documented.  It just has to be there.)

The other executables you mentioned are associated with our own applications.  They are not meant for use by your custom application, they do not ship with the NodeXL Class Libraries, and they are therefore not documented in NodeXLApi.chm.  The source code for those executables is included in the NodeXL Source Code and the source code is thoroughly commented, but I don't think it would be of any use to you or other custom application developers.  The executables and their source code can usually just be ignored.

-- Tony

 

Jan 12, 2012 at 7:24 PM

Hi Tony:

Thanks very much for the clarification.

Best Wishes,

Michael

From: tcap479 [email removed]
Sent: January 12, 2012 2:09 PM
To: michael@informationarts.ca
Subject: Re: Rookie Programming Questions.... [NodeXL:285157]

From: tcap479

Hello, Michael:

No, wrong assumption.

The SnapGraphMetricCalculator.exe executable ships with the NodeXL Class Libraries because it gets called internally from the Smrf.NodeXL.Algorithms.dll assembly. It has to be included in your custom application if you use certain classes in that assembly. (However, you never call the executable directly, you don't need to know how it works, and it is therefore not documented. It just has to be there.)

The other executables you mentioned are associated with our own applications. They are not meant for use by your custom application, they do not ship with the NodeXL Class Libraries, and they are therefore not documented in NodeXLApi.chm. The source code for those executables is included in the NodeXL Source Code and the source code is thoroughly commented, but I don't think it would be of any use to you or other custom application developers. Like all the NodeXL source code, it can usually just be ignored.

-- Tony