Comparing Two Graphs in Run-Time

Visual manipulations and refinements
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
thecoolboy
Posts:51
Joined:12 Oct 2011 23:01
Location:Arkansas,USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Comparing Two Graphs in Run-Time

Post by thecoolboy » 08 Aug 2013 20:26

I wan to try to compare the similarity of two graphs. I have a tree graph of parents and their children. I put them in a Hashtable and while iterating through all of them I am generating a new graph of each one( a parent graph and two children graphs) from an existing gdf file.

After this line
pGraph = GenerateNewGraphFromGDFFile(fileDirParent, key+".gdf");

pGraph is ok, but after

cGraph = GenerateNewGraphFromGDFFile(fileDirChildren, "fs_" + value.get(i)+".gdf");

pGraph is changing to cGraph in the run time(I can see it with debugging), I don't want it to be changed. Actually, all the graph objects are changing to the last generated one. What is going on?

The source code is below, I really need your help.

.........
.........
.........
//Iterate through parent and its children(leaf nodes)
while (itr.hasNext()) {

Map.Entry e = (Map.Entry) itr.next();
key = (Integer) e.getKey();
value = ((List<Integer>) e.getValue());
pGraph = GenerateNewGraphFromGDFFile(fileDirParent, key+".gdf");

for (int i = 0; i < value.size(); i++) {
cGraph = GenerateNewGraphFromGDFFile(fileDirChildren, "fs_" + value.get(i)+".gdf");
cGraphList.add(cGraph);
}

if(cGraphList.size()==2)
{
similarity = Similarity((HierarchicalUndirectedGraph)cGraphList.get(0), (HierarchicalUndirectedGraph) cGraphList.get(1), pGraph);
System.out.println("Similarity: " + similarity);
}
}

public HierarchicalUndirectedGraph GenerateNewGraphFromGDFFile(String fileDir, String fileName){

String line = null;
String[] lineArr;
List<Node> fileNode = new ArrayList<Node>();
List<String> fileEdgeContent = new ArrayList<String>();
HierarchicalUndirectedGraph[] newGraph = new HierarchicalUndirectedGraph[0];

newGraph = new HierarchicalUndirectedGraph[]{graphModel.getHierarchicalUndirectedGraph()};


newGraph[0].clear();
newGraph[0].clearEdges();

Node n;
Node n2;
Node source;
Node target;
Node[] nodes;
Edge newEdge;
try {
if(!fileName.endsWith(".gdf"))
bufReader = new BufferedReader(new FileReader(fileDir+fileName+".gdf"));
else
bufReader = new BufferedReader(new FileReader(fileDir+fileName));

boolean readingNodes = true;
boolean readingEdges = false;

//read the whole file
while ((line = bufReader.readLine()) != null) {
if(line.startsWith("nodedef")){
readingNodes = true;
readingEdges = false;
}
else if(readingNodes && !line.startsWith("edgedef"))
{
lineArr = line.split(",");
n = graphModel.factory().newNode(lineArr[0]);
n.getNodeData().setSize(10);
n.getNodeData().setLabel(lineArr[1]);
newGraph[0].addNode(n);
fileNode.add(n);
}
else if(line.startsWith("edgedef")){
readingNodes = false;
readingEdges = true;
}
else if(readingEdges)
{
lineArr = line.split(",");
source = newGraph[0].getNode(lineArr[0]);
target = newGraph[0].getNode(lineArr[1]);
newEdge = graphModel.factory().newEdge(source, target);
newGraph[0].addEdge(newEdge);
}

}


} catch (IOException x) {
System.err.format("IOException: %s%n", x);
}
finally {
try {
if (bufReader != null)bufReader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}

return (HierarchicalUndirectedGraph)newGraph[0];
}

User avatar
eduramiba
Gephi Code Manager
Posts:1064
Joined:22 Mar 2010 15:30
Location:Madrid, Spain
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Comparing Two Graphs in Run-Time

Post by eduramiba » 14 Aug 2013 15:23

Hi,
It looks like graphModel is a global variable in your program. The problem is probably coming from this.
You need to work with several graph models and workspaces, as each one is associated to a workspace.

Graphs creation should be left to the controller, while working with workspaces (use ProjectController http://gephi.org/docs/api/org/gephi/pro ... oller.html . Examples here http://wiki.gephi.org/index.php/Toolkit ... _Workspace)

Eduardo

thecoolboy
Posts:51
Joined:12 Oct 2011 23:01
Location:Arkansas,USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Comparing Two Graphs in Run-Time

Post by thecoolboy » 14 Aug 2013 17:53

Actually I forgot to tell that I want to avoid using workspaces, because each workspace means a separate thread and that leads to a high memory consumption.

Is there any other way to solve this?

thecoolboy
Posts:51
Joined:12 Oct 2011 23:01
Location:Arkansas,USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Comparing Two Graphs in Run-Time

Post by thecoolboy » 21 Aug 2013 15:39

Well, I think that is a lack of the current gephi version. I came up with a different solution: I implemented my own graph classes, HGraph, HEdges and HNodes

import org.gephi.graph.api.HierarchicalUndirectedGraph;
import java.util.List;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.NodeData;
import org.gephi.graph.api.Edge;
import java.util.ArrayList;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.GraphController;
import org.openide.util.Lookup;

/**
*
* @author Fatih Shen
*/
public class HGraph{
private HierarchicalUndirectedGraph hGraph = null;
private List<Node> nodes = new ArrayList<Node>();
private List<HNode> hNodes = new ArrayList<HNode>();
private List<HEdge> hEdges = new ArrayList<HEdge>();
private Node sourceNode = null;
private Node targetNode = null;
private int nodeCount = 0;
private int edgeCount = 0;
private HEdge hEdge = null;
private HNode hNode = null;
private List<String> strNodeIds;
private List<String> strNodeLabels;
private List<String> strEdges;
private int viewId = -1;//primary key
private String level = "";

private int iterationId = -1;
private int graphId = -1;
private boolean isLeafNode = false;
private String nodeIds = "";
private String nodeLabels = "";
private String edges = "";
private double avgCoeff = 0.0;
private int superGraphNodeCount = 0;
private int superGraphEdgeCount = 0;
private double density = 0.0;

private boolean isMerged = false;

public HGraph(){

}


public HGraph(List<String> strNodeIds, List<String> strEdges){
this.strNodeIds = strNodeIds;
this.strEdges = strEdges;
setupGraphFromText();
}

public HGraph(List<String> strNodeIds, List<String> strNodeLabels, List<String> strEdges){
this.strNodeIds = strNodeIds;
this.strNodeLabels = strNodeLabels;
this.strEdges = strEdges;
setupGraphFromTextWithLabels();
}

public HGraph(HierarchicalUndirectedGraph hGraph){
this.hGraph = hGraph;

setupGraphFromGraph();
}

private void setupGraphFromGraph()
{
for(Node n:this.hGraph.getNodes())
{
hNode = new HNode(n);
hNodes.add(hNode);
}

for(Edge e:this.hGraph.getEdges())
{

sourceNode = e.getSource();
targetNode = e.getTarget();
HEdge hEdge = new HEdge(this,sourceNode, targetNode);
hEdges.add(hEdge);
//edges.put(sourceNode, targetNode);
}

this.nodeCount = this.hNodes.size();//this.hGraph.getNodeCount();
this.edgeCount = this.hEdges.size();//this.hGraph.getEdgeCount();
}

private void setupGraphFromText(){

for(String n:this.strNodeIds){
hNode = new HNode(n,n);
hNodes.add(hNode);
}

String[] EdgeArr;
for(String e:this.strEdges){
EdgeArr = e.split("-");
hEdge = new HEdge(this,EdgeArr[0],EdgeArr[1]);
hEdges.add(hEdge);
}

this.nodeCount = this.hNodes.size();
this.edgeCount = this.hEdges.size();
}

private void setupGraphFromTextWithLabels(){

for(int i=0;i<strNodeIds.size();i++){
hNode = new HNode(strNodeIds.get(i),strNodeLabels.get(i));
hNodes.add(hNode);
}

String[] EdgeArr;
for(String e:this.strEdges){
EdgeArr = e.split("-");
hEdge = new HEdge(this,EdgeArr[0],EdgeArr[1]);
hEdges.add(hEdge);
}

this.nodeCount = this.hNodes.size();
this.edgeCount = this.hEdges.size();
}

public void addNode(HNode n){
hNode = new HNode();
hNode.copyNode(n);
hNodes.add(hNode);
}

public void addEdge(HEdge e){
hEdge = new HEdge();
hEdge.copyEdge(e);
if(!hEdges.contains(hEdge))
hEdges.add(hEdge);
}

public void setNodeCount(int count){
this.nodeCount = count;
}
public int getNodeCount(){
return this.nodeCount;
}

public void setEdgeCount(int count){
this.edgeCount = count;
}
public int getEdgeCount(){
return this.edgeCount;
}

public void setViewId(int vId){
this.viewId = vId;
}
public int getViewId(){
return this.viewId;
}

public void setIterationId(int itId){
this.iterationId = itId;
}
public int getIterationId(){
return this.iterationId;
}

public void setGraphId(int gId){
this.graphId = gId;
}
public int getGraphId(){
return this.graphId;
}

public void setIsLeafNode(boolean isLeafN){
this.isLeafNode = isLeafN;
}
public boolean getIsLeafNode(){
return this.isLeafNode;
}

public void setAvgCoeff(double avgC){
this.avgCoeff = avgC;
}
public double getAvgCoeff(){
return this.avgCoeff;
}

public void setSuperGraphNodeCount(int gNodeCount){
this.superGraphNodeCount = gNodeCount;
}
public int getSuperGraphNodeCount(){
return this.superGraphNodeCount;
}

public void setSuperGraphEdgeCount(int gEdgeCount){
this.superGraphEdgeCount = gEdgeCount;
}
public int getSuperGraphEdgeCount(){
return this.superGraphEdgeCount;
}

public void setDensity(double d){
this.density = d;
}
public double getDensity(){
return this.density;
}

public void setLevel(String l){
this.level = l;
}
public String getLevel(){
return this.level;
}

public void setIsMerged(boolean m){
this.isMerged = m;
}
public boolean getIsMerged(){
return this.isMerged;
}

public List<HNode> getNodes(){
return hNodes;
}

public List<HEdge> getEdges(){
return hEdges;
}

public void setNodeIds(String nIds){
this.nodeIds = nIds;
}
public String getNodeIds(){
return this.nodeIds;
}

public void setNodeLabels(String nLabels){
this.nodeLabels = nLabels;
}
public String getNodeLabels(){
return this.nodeLabels;
}

public void setGraphEdges(String gEdges){
this.edges = gEdges;
}
public String getGraphEdges(){
return this.edges;
}
//Node Ids seperated with commas
public String getNodeIdsAsString(){
String ids = "";
int N = this.getNodeCount();
for(int i=0;i<N;i++){
if(i==(N-1))
ids = ids + getNodes().get(i).getNodeId();
else
ids = ids + getNodes().get(i).getNodeId() + ",";
}

return ids;
}

//Node Labels separated with commas
public String getNodeLabelsAsString(){
String labels = "";
int N = this.getNodeCount();
for(int i=0;i<N;i++){
if(i==(N-1))
labels = labels + this.getNodes().get(i).getNodeLabel();
else
labels = labels + this.getNodes().get(i).getNodeLabel() + ",";
}

return labels;
}

//Edges seperated with commas
public String getEdgesAsString(){
String edges = "";
int E = this.getEdgeCount();
for(int i=0;i<E;i++){
if(i==(E-1))
edges = edges + this.getEdges().get(i).getSourceNode().getNodeId() + "-" + this.getEdges().get(i).getTargetNode().getNodeId();
else
edges = edges + this.getEdges().get(i).getSourceNode().getNodeId() + "-" + this.getEdges().get(i).getTargetNode().getNodeId() + ",";
}

return edges;
}

public HierarchicalUndirectedGraph GenerateNewGraphFromHGraph(){
Node n;
Node source;
Node target;
Edge newEdge;
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel();
HierarchicalUndirectedGraph[] newGraph = new HierarchicalUndirectedGraph[]{graphModel.getHierarchicalUndirectedGraph()};
newGraph[0].clear();
newGraph[0].clearEdges();

for(HNode node:this.getNodes()){

n = graphModel.factory().newNode(String.valueOf(node.getNodeId()));
n.getNodeData().setSize(10);
if(node.getNodeLabel().equals(""))
n.getNodeData().setLabel(String.valueOf(node.getNodeId()));
else
n.getNodeData().setLabel(String.valueOf(node.getNodeLabel()));
newGraph[0].addNode(n);
}

for(HEdge edge:this.getEdges()){

source = newGraph[0].getNode(edge.getSourceNode().getNodeId());
target = newGraph[0].getNode(edge.getTargetNode().getNodeId());
newEdge = graphModel.factory().newEdge(source, target);
newGraph[0].addEdge(newEdge);
}


return (HierarchicalUndirectedGraph)newGraph[0];
}
}

thecoolboy
Posts:51
Joined:12 Oct 2011 23:01
Location:Arkansas,USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Comparing Two Graphs in Run-Time

Post by thecoolboy » 21 Aug 2013 15:40

Here is the HEdge object:

import org.gephi.graph.api.Node;

/**
*
* @author Fatih Shen
*/
public class HEdge {
private HNode sourceNode = null;
private HNode targetNode = null;
private HGraph hGraph = null;

HEdge(){

}

HEdge(HGraph hGraph,Node sNode, Node tNode){
this.hGraph = hGraph;
sourceNode = new HNode(sNode);
targetNode = new HNode(tNode);
}

HEdge(HGraph hGraph,String sNodeId, String tNodeId){
this.hGraph = hGraph;
//checkGraph(this.hGraph,sNodeId,tNodeId);
sourceNode = new HNode(sNodeId,sNodeId);
targetNode = new HNode(tNodeId,tNodeId);
}

public void copyEdge(HEdge e){
this.setSourceNode(e.getSourceNode());
this.setTargetNode(e.getTargetNode());
}

public void setSourceNode(HNode sNode){
this.sourceNode = sNode;
}
public HNode getSourceNode(){
return sourceNode;
}

public void setTargetNode(HNode tNode){
this.targetNode = tNode;
}
public HNode getTargetNode(){
return targetNode;
}

}

thecoolboy
Posts:51
Joined:12 Oct 2011 23:01
Location:Arkansas,USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Comparing Two Graphs in Run-Time

Post by thecoolboy » 21 Aug 2013 15:42

And here is the HNode:

import org.gephi.graph.api.Node;
import org.gephi.graph.api.NodeData;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.GraphController;
import org.openide.util.Lookup;

/**
*
* @author Fatih Shen
*/
public class HNode {
private Node node = null;
private String nodeId = "";
private String nodeLabel = "";
private HGraph hGraph = null;

HNode(){

}


HNode(Node n){
this.node = n;
}

HNode(String nId, String nLabel){
this.nodeId = nId;
this.nodeLabel = nLabel;
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel();
node = graphModel.factory().newNode(this.nodeId);
node.getNodeData().setLabel(this.nodeLabel);
}

HNode(HGraph hGraph,String nId){
this.hGraph = hGraph;
this.nodeId = nId;
}

HNode(HGraph hGraph,Node n){
this.hGraph = hGraph;
this.node = n;
}

public void copyNode(HNode node){
this.setNode(node.getNode());
this.setNodeId(node.getNodeId());
this.setNodeLabel(node.getNodeLabel());
}

public void setNode(Node n){
this.node = n;
}

public Node getNode(){
return node;
}

public void setNodeId(String nId){
this.nodeId = nId;
}

public String getNodeId(){
return nodeId;
}

public void setNodeLabel(String nLabel){
this.nodeLabel = nLabel;
}

public String getNodeLabel(){
return nodeLabel;
}

public NodeData getNodeData(){
return this.node.getNodeData();
}
}

thecoolboy
Posts:51
Joined:12 Oct 2011 23:01
Location:Arkansas,USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Comparing Two Graphs in Run-Time

Post by thecoolboy » 21 Aug 2013 18:03

Also, let me share you its C# code. Just keep in mind that might need to change the classes according to your own purpose! Enjoy it :)

public class HGraph
{
private List<HNode> nodes = new List<HNode>();
private List<HNode> hNodes = new List<HNode>();
private List<HEdge> hEdges = new List<HEdge>();
private List<HEdge> hNodeEdges = new List<HEdge>();
private int nodeCount = 0;
private int edgeCount = 0;
private HEdge hEdge = null;
private HNode hNode = null;
private List<String> strNodeIds;
private List<String> strNodeLabels;
private List<String> strEdges;
private int viewId = -1;//primary key
private int parentViewId = -1;
private String level = "";

private int iterationId = -1;
private int graphId = -1;
private bool isLeafNode = false;
private String nodeIds = "";
private String nodeLabels = "";
private String edges = "";
private double avgCoeff = 0.0;
private int superGraphNodeCount = 0;
private int superGraphEdgeCount = 0;
private double density = 0.0;

private bool isMerged = false;

public HGraph()
{

}


public HGraph(List<String> strNodeIds, List<String> strEdges)
{
this.strNodeIds = strNodeIds;
this.strEdges = strEdges;
setupGraphFromText();
}

public HGraph(List<String> strNodeIds, List<String> strNodeLabels, List<String> strEdges)
{
this.strNodeIds = strNodeIds;
this.strNodeLabels = strNodeLabels;
this.strEdges = strEdges;
setupGraphFromTextWithLabels();
}


public void setNodeCount(int count)
{
this.nodeCount = count;
}
public int getNodeCount()
{
return this.nodeCount;
}

public void setEdgeCount(int count)
{
this.edgeCount = count;
}
public int getEdgeCount()
{
return this.edgeCount;
}

public void setParentViewId(int vId)
{
this.parentViewId = vId;
}
public int getParentViewId(){
return this.parentViewId;
}

public void setViewId(int vId)
{
this.viewId = vId;
}
public int getViewId()
{
return this.viewId;
}

public void setIterationId(int itId)
{
this.iterationId = itId;
}
public int getIterationId()
{
return this.iterationId;
}

public void setGraphId(int gId)
{
this.graphId = gId;
}
public int getGraphId()
{
return this.graphId;
}

public void setIsLeafNode(bool isLeafN)
{
this.isLeafNode = isLeafN;
}
public bool getIsLeafNode()
{
return this.isLeafNode;
}

public void setAvgCoeff(double avgC)
{
this.avgCoeff = avgC;
}
public double getAvgCoeff()
{
return this.avgCoeff;
}

public void setSuperGraphNodeCount(int gNodeCount)
{
this.superGraphNodeCount = gNodeCount;
}
public int getSuperGraphNodeCount()
{
return this.superGraphNodeCount;
}

public void setSuperGraphEdgeCount(int gEdgeCount)
{
this.superGraphEdgeCount = gEdgeCount;
}
public int getSuperGraphEdgeCount()
{
return this.superGraphEdgeCount;
}

public void setDensity(double d)
{
this.density = d;
}
public double getDensity()
{
return this.density;
}

public void setLevel(String l)
{
this.level = l;
}
public String getLevel()
{
return this.level;
}

public void setIsMerged(bool m)
{
this.isMerged = m;
}
public bool getIsMerged()
{
return this.isMerged;
}

public List<HNode> getNodes()
{
return hNodes;
}

public List<HEdge> getEdges()
{
return hEdges;
}

public List<HEdge> getEdges(HNode node)
{
hNodeEdges = new List<HEdge>();
foreach(HEdge e in this.getEdges())
{
if(e.getSourceNode().getNodeId().Equals(node.getNodeId())
|| e.getTargetNode().getNodeId().Equals(node.getNodeId()))
hNodeEdges.Add(e);
}

return hNodeEdges;
}

public HNode getNeighbor(HNode n, HEdge e){
HNode neighborNode = null;
foreach(HEdge edge in this.getEdges())
{
if(edge.getSourceNode().getNodeId().Equals(n.getNodeId()))
neighborNode = edge.getTargetNode();
else if(edge.getTargetNode().getNodeId().Equals(n.getNodeId()))
neighborNode = edge.getSourceNode();
}

return neighborNode;
}

public void setNodeIds(String nIds)
{
this.nodeIds = nIds;
}
public String getNodeIds()
{
return this.nodeIds;
}

public void setNodeLabels(String nLabels)
{
this.nodeLabels = nLabels;
}
public String getNodeLabels()
{
return this.nodeLabels;
}

public void setGraphEdges(String gEdges)
{
this.edges = gEdges;
}
public String getGraphEdges()
{
return this.edges;
}

private void setupGraphFromText()
{

foreach (String n in this.strNodeIds)
{
hNode = new HNode(n, n);
hNodes.Add(hNode);
}

string[] EdgeArr;
foreach (string e in this.strEdges)
{
EdgeArr = e.Split('-');
hEdge = new HEdge(this,EdgeArr[0],EdgeArr[1]);
hEdges.Add(hEdge);
}

this.nodeCount = this.hNodes.Count;
this.edgeCount = this.hEdges.Count;
}

private void setupGraphFromTextWithLabels()
{

for (int i = 0; i < strNodeIds.Count; i++)
{
hNode = new HNode(strNodeIds.ToString(), strNodeLabels.ToString());
hNodes.Add(hNode);
}

String[] EdgeArr;
foreach (String e in this.strEdges)
{
EdgeArr = e.Split('-');
hEdge = new HEdge(this, EdgeArr[0], EdgeArr[1]);
hEdges.Add(hEdge);
}

this.nodeCount = this.hNodes.Count;
this.edgeCount = this.hEdges.Count;
}

//Node Ids seperated with commas
public String getNodeIdsAsString()
{
String ids = "";
int N = this.getNodeCount();
for (int i = 0; i < N; i++)
{
if (i == (N - 1))
ids = ids + getNodes().getNodeId();
else
ids = ids + getNodes().getNodeId() + ",";
}

return ids;
}

//Node Labels separated with commas
public String getNodeLabelsAsString()
{
String labels = "";
int N = this.getNodeCount();
for (int i = 0; i < N; i++)
{
if (i == (N - 1))
labels = labels + this.getNodes().getNodeLabel();
else
labels = labels + this.getNodes().getNodeLabel() + ",";
}

return labels;
}

//Edges seperated with commas
public String getEdgesAsString()
{
String edges = "";
int E = this.getEdgeCount();
for (int i = 0; i < E; i++)
{
if (i == (E - 1))
edges = edges + this.getEdges().getSourceNode().getNodeId() + "-" + this.getEdges().getTargetNode().getNodeId();
else
edges = edges + this.getEdges().getSourceNode().getNodeId() + "-" + this.getEdges().getTargetNode().getNodeId() + ",";
}

return edges;
}

public void addNode(HNode n)
{
hNode = new HNode();
hNode.copyNode(n);
hNodes.Add(hNode);

this.nodeCount = this.hNodes.Count;

}

public void addEdge(HEdge e)
{
hEdge = new HEdge();
hEdge.copyEdge(e);
if (!hEdges.Contains(hEdge)){
hEdges.Add(hEdge);
this.edgeCount = this.hEdges.Count;
}
}

}

thecoolboy
Posts:51
Joined:12 Oct 2011 23:01
Location:Arkansas,USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Comparing Two Graphs in Run-Time

Post by thecoolboy » 21 Aug 2013 18:33

I could of course use properties, but didn't prefer this time.

public class HEdge
{
private HNode sourceNode = null;
private HNode targetNode = null;
private HGraph hGraph = null;

public HEdge()
{

}

public HEdge(HGraph hGraph, String sNodeId, String tNodeId)
{
this.hGraph = hGraph;

sourceNode = new HNode(sNodeId, sNodeId);
targetNode = new HNode(tNodeId, tNodeId);
}

public void setSourceNode(HNode sNode)
{
this.sourceNode = sNode;
}
public HNode getSourceNode()
{
return sourceNode;
}

public void setTargetNode(HNode tNode)
{
this.targetNode = tNode;
}
public HNode getTargetNode()
{
return targetNode;
}

public void copyEdge(HEdge e)
{
this.setSourceNode(e.getSourceNode());
this.setTargetNode(e.getTargetNode());
}
}

public class HNode
{
private String nodeId = "";
private String nodeLabel = "";
private HGraph hGraph = null;
private List<HNode> neighbours = new List<HNode>();

public HNode(){

}

public HNode(String nId, String nLabel){
this.nodeId = nId;
this.nodeLabel = nLabel;

}

public HNode(HGraph hGraph,String nId){
this.hGraph = hGraph;
this.nodeId = nId;
}

public void setNodeId(String nId)
{
this.nodeId = nId;
}

public String getNodeId()
{
return nodeId;
}

public void setNodeLabel(String nLabel)
{
this.nodeLabel = nLabel;
}

public String getNodeLabel()
{
return nodeLabel;
}

public void copyNode(HNode node)
{
this.setNodeId(node.getNodeId());
this.setNodeLabel(node.getNodeLabel());
}
}

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable