Basic Tutorial: My First Project
This is a basic and essential tutorial. Must read!
You will learn how to:
- Create a project and put .graph files inside, ready to edit
- Write a simple analysis.
- Show to the user what you just found out
Introduction
Hi, thats the first and essential tutorial you must read to perform graph analysis. The first thing you must know is that the Rox works with projects, and its inside of them you will put your graphs and the routines that processes it to return a result. Those routines are called Analysis. The Rox framework internally works with those same analysis objects, so when you forge an analysis for yourself, you will be able to contribute to a new version of Rox.
But first, as yourself which questions your analysis will answer. "How many connected components the graph has?" or "WHICH connected components this graph has?" or even "This graph is bipartite?". For each question we can model, respectively, an specific result type, which can be a number, an object collection or a true/false affirmation.Said that, each analysis can return a result of those types:
- Boolean (IBooleanResult) - in case of true or false result. like: "This graph is bipartite?"
- Integer (IIntegerResult) - in case of only count something, like: "How many connected components this graph has?"
- Object Collection (ICollectionResult) - when we want the objects that compound the result, usually intercalated nodes and edges. like: "What is the shortest path between n1 and n2?"
In this tutorial, we will build a very simple analysis that counts the nodes of a given graph and show the result.
Basically, a project can contain 4 parts:
- A analysis class, of type AbstractAnalysis
- A class to store the results, of type AbstractAnalysisResult and implementing the sub-types IBooleanResult, ICollectionResult ou IIntegerResult.
- A main class to start the analysis (or many of them) and show it results. It can be a grpahical class, or just a class with public static void main(String[] args) that prints the result on the console.
- The .graph files.
Creating a New Project
- First of all, this is the main screen. Right-click in the Package Explorer view. Choose New->Project
- Now choose Java Project as showed in the next screen.
- Name your project in the field Project and click Finish.
- Now right-click the project we´ve just created and choose Rox Actions -> Update Classpath. This will add to our project all the libraries we need to retrieve information from the graph files.
Creating an Analysis
Let's create an analysis to count the nodes of a graph.- Right-click our brand new project. Choose New->Class.
- Fulfill the New Java Class wizard with this:
- Name: CoundNodeAnalysis
- Superclass: org.projetorox.rox.graphapi.analysis.AbstractAnalysis
- click Finish
- Now you have to create a Result class. Repeat the last step, with
- Name: CoundNodeAnalysisResult
- Superclass: org.projetorox.rox.graphapi.analysis.AbstractAnalysisResult
- Interfaces: Add a new one, called IIntegerAnalysisResult (we want to return a number)
- click Finish.
- Repeat the last step, but now put the name: Main. Thats our main class.
Your Main class should look like this:
public class Main {
public static void main(String[] args) throws Exception{
//we will get the graph using the GraphUtils.
IGraph graph = GraphUtils.getInstance().getGraph("myGraph.graph");
//then we instantiate a Analysis object...
CountNodesAnalysis analysis = new CountNodesAnalysis();
//...adding a graph inside it
analysis.addGraph(myGraph);
//and calling the execute method, retrieving its result:
CountNodesAnalysisResult result = (CountNodesAnalysisResult)analysis.execute();
//now we just print the result.
System.out.println("This graph has "+result.getResult().intValue()+" nodes");
}
Here are the other files we are working on, copy to your rox/workspace/<your_project> directory:
CountNodesAnalysisResult.java
CountNodesAnalysis.java
- After creating the analysis, right-click in the Main class and choose Run As.. -> Java Application. Your analysis will run.
- The result appears at the console view.