Merge branch 'master' of github.com:gephi/gephi

Esse commit está contido em:
Eduardo Ramos
2014-01-13 21:15:20 +01:00
88 arquivos alterados com 7384 adições e 2005 exclusões
@@ -217,7 +217,7 @@ public class AppearanceModelImpl implements AppearanceModel {
}
}
public boolean isPartition(Column column) {
private boolean isPartition(Column column) {
Index index;
if (AttributeUtils.isNodeColumn(column)) {
index = localScale ? graphModel.getNodeIndex(graphModel.getVisibleView()) : graphModel.getNodeIndex();
@@ -246,7 +246,7 @@ public class AppearanceModelImpl implements AppearanceModel {
return false;
}
public boolean isRanking(Column column) {
private boolean isRanking(Column column) {
if (column.isNumber()) {
Index index;
if (AttributeUtils.isNodeColumn(column)) {
@@ -165,4 +165,38 @@ public class FunctionImpl implements RankingFunction, PartitionFunction, SimpleF
}
return super.toString();
}
@Override
public int hashCode() {
int hash = 5;
hash = 47 * hash + (this.column != null ? this.column.hashCode() : 0);
hash = 47 * hash + (this.transformer != null ? this.transformer.hashCode() : 0);
hash = 47 * hash + (this.partition != null ? this.partition.hashCode() : 0);
hash = 47 * hash + (this.ranking != null ? this.ranking.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final FunctionImpl other = (FunctionImpl) obj;
if (this.column != other.column && (this.column == null || !this.column.equals(other.column))) {
return false;
}
if (this.transformer != other.transformer && (this.transformer == null || !this.transformer.equals(other.transformer))) {
return false;
}
if (this.partition != other.partition && (this.partition == null || !this.partition.equals(other.partition))) {
return false;
}
if (this.ranking != other.ranking && (this.ranking == null || !this.ranking.equals(other.ranking))) {
return false;
}
return true;
}
}
@@ -104,4 +104,26 @@ public class PartitionImpl implements Partition {
public Column getColumn() {
return column;
}
@Override
public int hashCode() {
int hash = 3;
hash = 23 * hash + (this.column != null ? this.column.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PartitionImpl other = (PartitionImpl) obj;
if (this.column != other.column && (this.column == null || !this.column.equals(other.column))) {
return false;
}
return true;
}
}
@@ -69,7 +69,7 @@ public class RankingImpl implements Ranking {
@Override
public Number getMaxValue() {
return index.getMinValue(column);
return index.getMaxValue(column);
}
@Override
@@ -87,4 +87,26 @@ public class RankingImpl implements Ranking {
float normalizedValue = (float) (value.doubleValue() - getMinValue().doubleValue()) / (float) (getMaxValue().doubleValue() - getMinValue().doubleValue());
return interpolator.interpolate(normalizedValue);
}
@Override
public int hashCode() {
int hash = 3;
hash = 67 * hash + (this.column != null ? this.column.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final RankingImpl other = (RankingImpl) obj;
if (this.column != other.column && (this.column == null || !this.column.equals(other.column))) {
return false;
}
return true;
}
}
+4
Ver Arquivo
@@ -20,6 +20,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>project-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>graph-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>appearance-api</artifactId>
@@ -49,12 +49,17 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import org.gephi.appearance.api.AppearanceController;
import org.gephi.appearance.api.AppearanceModel;
import org.gephi.appearance.api.Function;
import org.gephi.appearance.spi.Transformer;
import org.gephi.appearance.spi.TransformerCategory;
import org.gephi.appearance.spi.TransformerUI;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.TableObserver;
import org.gephi.graph.api.GraphController;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.gephi.project.api.WorkspaceListener;
@@ -79,6 +84,8 @@ public class AppearanceUIController {
private final Set<AppearanceUIModelListener> listeners;
//Model
private AppearanceUIModel model;
//Observer
private ColumnObserver tableObserver;
public AppearanceUIController() {
final ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
@@ -98,6 +105,12 @@ public class AppearanceUIController {
workspace.add(model);
}
model.select();
if (tableObserver != null) {
tableObserver.destroy();
}
tableObserver = new ColumnObserver(workspace);
tableObserver.start();
firePropertyChangeEvent(AppearanceUIModelEvent.MODEL, oldModel, model);
}
@@ -117,6 +130,9 @@ public class AppearanceUIController {
AppearanceUIModel oldModel = model;
model = null;
firePropertyChangeEvent(AppearanceUIModelEvent.MODEL, oldModel, model);
if (tableObserver != null) {
tableObserver.destroy();
}
}
});
@@ -260,4 +276,43 @@ public class AppearanceUIController {
listener.propertyChange(event);
}
}
private class ColumnObserver extends TimerTask {
private final GraphController gc = Lookup.getDefault().lookup(GraphController.class);
private static final int INTERVAL = 500;
private final Timer timer;
private final TableObserver nodeObserver;
private final TableObserver edgeObserver;
public ColumnObserver(Workspace workspace) {
timer = new Timer("RankingColumnObserver", true);
nodeObserver = gc.getAttributeModel(workspace).getNodeTable().getTableObserver();
edgeObserver = gc.getAttributeModel(workspace).getEdgeTable().getTableObserver();
}
@Override
public void run() {
if (nodeObserver.hasTableChanged() || edgeObserver.hasTableChanged()) {
Function oldValue = model.getSelectedFunction();
model.refreshSelectedFunction();
Function newValue = model.getSelectedFunction();
firePropertyChangeEvent(AppearanceUIModelEvent.SELECTED_FUNCTION, oldValue, newValue);
}
}
public void start() {
timer.schedule(this, INTERVAL, INTERVAL);
}
public void stop() {
timer.cancel();
}
public void destroy() {
stop();
nodeObserver.destroy();
edgeObserver.destroy();
}
}
}
@@ -123,6 +123,18 @@ public class AppearanceUIModel {
}
}
public boolean refreshSelectedFunction() {
Function sFunction = getSelectedFunction();
if (sFunction != null && sFunction.isAttribute()) {
for (Function func : getSelectedElementClass().equals(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions() : appearanceModel.getEdgeFunctions()) {
if(func.equals(sFunction)) {
return false;
}
}
}
return true;
}
public void select() {
}
+2 -2
Ver Arquivo
@@ -5,7 +5,7 @@
<artifactId>gephi-parent</artifactId>
<groupId>org.gephi</groupId>
<version>0.9-SNAPSHOT</version>
<relativePath>../..</relativePath>
<relativePath>../..</relativePath>
</parent>
<groupId>org.gephi</groupId>
@@ -18,7 +18,7 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>data-attributes-api</artifactId>
<artifactId>graph-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
@@ -50,11 +50,14 @@ import java.util.concurrent.TimeUnit;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JPanel;
import org.gephi.data.attributes.type.Interval;
import org.gephi.data.attributes.type.TimeInterval;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.TimeFormat;
import org.gephi.attribute.time.Interval;
import org.gephi.dynamic.DynamicUtilities;
import org.gephi.dynamic.api.DynamicController;
import org.gephi.dynamic.api.DynamicModel;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.lib.validation.PositiveNumberValidator;
import org.gephi.statistics.spi.DynamicStatistics;
import org.gephi.ui.components.richtooltip.RichTooltip;
@@ -76,6 +79,7 @@ public class DynamicSettingsPanel extends javax.swing.JPanel {
private TimeUnit windowTimeUnit = TimeUnit.DAYS;
private TimeUnit tickTimeUnit = TimeUnit.DAYS;
private Interval bounds = null;
public DynamicSettingsPanel() {
initComponents();
@@ -107,42 +111,29 @@ public class DynamicSettingsPanel extends javax.swing.JPanel {
}
});
}
Interval bounds = null;
public void setup(DynamicStatistics dynamicStatistics) {
DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
DynamicModel model = dynamicController.getModel();
TimeInterval visibleInterval = model.getVisibleInterval();
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getGraphModel();
AttributeModel attributeModel = graphController.getAttributeModel();
TimeFormat timeFormat = attributeModel.getTimeFormat();
//Bounds
bounds = dynamicStatistics.getBounds();
if (bounds == null) {
double low = visibleInterval.getLow();
if (Double.isInfinite(low)) {
low = model.getMin();
}
double high = visibleInterval.getHigh();
if (Double.isInfinite(high)) {
high = model.getMax();
}
bounds = new Interval(low, high);
}
String boundsStr = "";
if (model.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) {
boundsStr = bounds.getLow() + " - " + bounds.getHigh();
} else {
boundsStr = DynamicUtilities.getXMLDateStringFromDouble(bounds.getLow()) + " - " + DynamicUtilities.getXMLDateStringFromDouble(bounds.getHigh());
bounds = graphModel.getTimeBoundsVisible();
}
String boundsStr = timeFormat.print(bounds.getLow())+" - "+timeFormat.print(bounds.getHigh());
currentIntervalLabel.setText(boundsStr);
//TimeUnit
if (model.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) {
if (timeFormat.equals(TimeFormat.DOUBLE)) {
windowTimeUnitCombo.setVisible(false);
tickTimeUnitCombo.setVisible(false);
}
//Set latest selected item
if (!model.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) {
if (!timeFormat.equals(TimeFormat.DOUBLE)) {
loadDefaultTimeUnits();
}
@@ -151,7 +142,7 @@ public class DynamicSettingsPanel extends javax.swing.JPanel {
if(bounds.getHigh() - bounds.getLow() > 1) {
initValue = 1.;
}
if (model.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) {
if (timeFormat.equals(TimeFormat.DOUBLE)) {
windowTextField.setText(initValue + "");
tickTextField.setText(initValue + "");
} else {
@@ -162,6 +153,7 @@ public class DynamicSettingsPanel extends javax.swing.JPanel {
//Add listeners
windowTimeUnitCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getItem() != windowTimeUnitCombo.getSelectedItem()) {
refreshWindowTimeUnit();
@@ -171,6 +163,7 @@ public class DynamicSettingsPanel extends javax.swing.JPanel {
tickTimeUnitCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getItem() != tickTimeUnitCombo.getSelectedItem()) {
refreshTickTimeUnit();
@@ -43,9 +43,6 @@ package org.gephi.desktop.statistics;
import java.util.ArrayList;
import org.gephi.desktop.statistics.api.StatisticsControllerUI;
import org.gephi.dynamic.api.DynamicController;
import org.gephi.dynamic.api.DynamicModelEvent;
import org.gephi.dynamic.api.DynamicModelListener;
import org.gephi.statistics.api.StatisticsController;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsUI;
@@ -61,23 +58,23 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = StatisticsControllerUI.class)
public class StatisticsControllerUIImpl implements StatisticsControllerUI {
private final DynamicModelListener dynamicModelListener;
// private final DynamicModelListener dynamicModelListener;
private StatisticsModelUIImpl model;
public StatisticsControllerUIImpl() {
dynamicModelListener = new DynamicModelListener() {
public void dynamicModelChanged(DynamicModelEvent event) {
if (event.getEventType().equals(DynamicModelEvent.EventType.IS_DYNAMIC_GRAPH)) {
boolean isDynamic = (Boolean) event.getData();
for (StatisticsUI ui : Lookup.getDefault().lookupAll(StatisticsUI.class)) {
if (ui.getCategory().equals(StatisticsUI.CATEGORY_DYNAMIC)) {
setStatisticsUIVisible(ui, isDynamic);
}
}
}
}
};
// dynamicModelListener = new DynamicModelListener() {
//
// public void dynamicModelChanged(DynamicModelEvent event) {
// if (event.getEventType().equals(DynamicModelEvent.EventType.IS_DYNAMIC_GRAPH)) {
// boolean isDynamic = (Boolean) event.getData();
// for (StatisticsUI ui : Lookup.getDefault().lookupAll(StatisticsUI.class)) {
// if (ui.getCategory().equals(StatisticsUI.CATEGORY_DYNAMIC)) {
// setStatisticsUIVisible(ui, isDynamic);
// }
// }
// }
// }
// };
}
public void setup(StatisticsModelUIImpl model) {
@@ -88,25 +85,25 @@ public class StatisticsControllerUIImpl implements StatisticsControllerUI {
unsetup();
if (model != null) {
DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
boolean isDynamic = dynamicController.getModel(model.getWorkspace()).isDynamicGraph();
if (!isDynamic) {
for (StatisticsUI ui : Lookup.getDefault().lookupAll(StatisticsUI.class)) {
if (ui.getCategory().equals(StatisticsUI.CATEGORY_DYNAMIC)) {
setStatisticsUIVisible(ui, false);
}
}
}
//Add listener
dynamicController.addModelListener(dynamicModelListener);
// DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
// boolean isDynamic = dynamicController.getModel(model.getWorkspace()).isDynamicGraph();
// if (!isDynamic) {
// for (StatisticsUI ui : Lookup.getDefault().lookupAll(StatisticsUI.class)) {
// if (ui.getCategory().equals(StatisticsUI.CATEGORY_DYNAMIC)) {
// setStatisticsUIVisible(ui, false);
// }
// }
// }
// //Add listener
//
// dynamicController.addModelListener(dynamicModelListener);
}
}
public void unsetup() {
if (model != null) {
DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
dynamicController.removeModelListener(dynamicModelListener);
// DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
// dynamicController.removeModelListener(dynamicModelListener);
}
}
@@ -69,15 +69,15 @@ import org.openide.windows.TopComponent;
* @author Patick J. McSweeney
*/
@ConvertAsProperties(dtd = "-//org.gephi.desktop.statistics//Statistics//EN",
autostore = false)
autostore = false)
@TopComponent.Description(preferredID = "StatisticsTopComponent",
iconBase = "org/gephi/desktop/statistics/resources/small.png",
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
iconBase = "org/gephi/desktop/statistics/resources/small.png",
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "filtersmode", openAtStartup = true, roles = {"overview"})
@ActionID(category = "Window", id = "org.gephi.desktop.statistics.StatisticsTopComponent")
@ActionReference(path = "Menu/Window", position = 1200)
@TopComponent.OpenActionRegistration(displayName = "#CTL_StatisticsTopComponent",
preferredID = "StatisticsTopComponent")
preferredID = "StatisticsTopComponent")
public final class StatisticsTopComponent extends TopComponent implements ChangeListener {
//Model
@@ -41,6 +41,8 @@
*/
package org.gephi.io.importer.api;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.TimeFormat;
import org.gephi.io.importer.spi.Importer;
/**
@@ -41,6 +41,7 @@
*/
package org.gephi.io.importer.api;
import org.gephi.attribute.api.TimeFormat;
import org.gephi.io.processor.spi.Processor;
/**
@@ -1,10 +0,0 @@
package org.gephi.io.importer.api;
/**
*
* @author mbastian
*/
public enum TimeFormat {
DATE, DATETIME, DOUBLE, TIMESTAMP
}
@@ -56,6 +56,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.gephi.attribute.api.TimeFormat;
import org.gephi.io.importer.api.ColumnDraft;
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.ContainerLoader;
@@ -69,7 +70,6 @@ import org.gephi.io.importer.api.Issue;
import org.gephi.io.importer.api.Issue.Level;
import org.gephi.io.importer.api.NodeDraft;
import org.gephi.io.importer.api.Report;
import org.gephi.io.importer.api.TimeFormat;
import org.openide.util.NbBundle;
/**
@@ -620,15 +620,13 @@ public class ImportContainerImpl implements Container, ContainerLoader, Containe
//Clean autoNode
if (!allowAutoNode()) {
for (Iterator<NodeDraftImpl> itr = nodeList.iterator(); itr.hasNext();) {
NodeDraftImpl node = itr.next();
for (NodeDraftImpl node : nodeList) {
if (node != null && node.isCreatedAuto()) {
int index = nodeMap.removeInt(node.getId());
nodeList.set(index, null);
}
}
for (Iterator<EdgeDraftImpl> itr = edgeList.iterator(); itr.hasNext();) {
EdgeDraftImpl edge = itr.next();
for (EdgeDraftImpl edge : edgeList) {
if (edge != null && (edge.getSource().isCreatedAuto() || edge.getTarget().isCreatedAuto())) {
int index = edgeMap.remove(edge.getId());
edgeList.set(index, null);
@@ -718,7 +716,7 @@ public class ImportContainerImpl implements Container, ContainerLoader, Containe
} else if (mergeStrategy.equals(EdgeWeightMergeStrategy.MAX)) {
result = Math.max(source.getWeight(), dest.getWeight());
} else if (mergeStrategy.equals(EdgeWeightMergeStrategy.MIN)) {
result = Math.min(source.getWeight(), dest.getWeight());;
result = Math.min(source.getWeight(), dest.getWeight());
} else if (mergeStrategy.equals(EdgeWeightMergeStrategy.SUM)) {
result = source.getWeight() + dest.getWeight();
}
@@ -50,6 +50,7 @@ import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import org.gephi.attribute.api.TimeFormat;
import org.gephi.io.database.drivers.SQLUtils;
import org.gephi.io.importer.api.ColumnDraft;
import org.gephi.io.importer.api.ContainerLoader;
@@ -63,7 +64,6 @@ import org.gephi.io.importer.api.PropertiesAssociations;
import org.gephi.io.importer.api.PropertiesAssociations.EdgeProperties;
import org.gephi.io.importer.api.PropertiesAssociations.NodeProperties;
import org.gephi.io.importer.api.Report;
import org.gephi.io.importer.api.TimeFormat;
import org.gephi.io.importer.spi.DatabaseImporter;
/**
@@ -47,6 +47,7 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import javax.xml.stream.*;
import javax.xml.stream.events.XMLEvent;
import org.gephi.attribute.api.TimeFormat;
import org.gephi.io.importer.api.*;
import org.gephi.io.importer.spi.FileImporter;
import org.gephi.utils.longtask.spi.LongTask;
@@ -232,7 +233,7 @@ public class ImporterGEXF implements FileImporter, LongTask {
} else if ("datetime".equalsIgnoreCase(timeFormat)) {
container.setTimeFormat(TimeFormat.DATETIME);
} else if ("timestamp".equalsIgnoreCase(timeFormat)) {
container.setTimeFormat(TimeFormat.TIMESTAMP);
container.setTimeFormat(TimeFormat.DATETIME);
}
} else if (mode.equalsIgnoreCase("dynamic")) {
container.setTimeFormat(TimeFormat.DOUBLE);
-4
Ver Arquivo
@@ -16,10 +16,6 @@
<name>StatisticsAPI</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>data-attributes-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>dynamic-api</artifactId>
@@ -42,20 +42,18 @@ Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.TimestampIndex;
import org.gephi.attribute.time.Interval;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.api.*;
import org.gephi.data.attributes.api.AttributeController;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.type.Interval;
import org.gephi.data.attributes.type.TimeInterval;
import org.gephi.dynamic.api.DynamicController;
import org.gephi.dynamic.api.DynamicGraph;
import org.gephi.dynamic.api.DynamicModel;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.GraphView;
import org.gephi.graph.api.Node;
import org.gephi.project.api.ProjectController;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.longtask.api.LongTaskExecutor;
@@ -86,10 +84,12 @@ public class StatisticsControllerImpl implements StatisticsController {
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.addWorkspaceListener(new WorkspaceListener() {
@Override
public void initialize(Workspace workspace) {
workspace.add(new StatisticsModelImpl());
}
@Override
public void select(Workspace workspace) {
model = workspace.getLookup().lookup(StatisticsModelImpl.class);
if (model == null) {
@@ -98,12 +98,15 @@ public class StatisticsControllerImpl implements StatisticsController {
}
}
@Override
public void unselect(Workspace workspace) {
}
@Override
public void close(Workspace workspace) {
}
@Override
public void disable() {
model = null;
}
@@ -118,6 +121,7 @@ public class StatisticsControllerImpl implements StatisticsController {
}
}
@Override
public void execute(final Statistics statistics, LongTaskListener listener) {
StatisticsBuilder builder = getBuilder(statistics.getClass());
LongTaskExecutor executor = new LongTaskExecutor(true, "Statistics " + builder.getName(), 10);
@@ -129,6 +133,7 @@ public class StatisticsControllerImpl implements StatisticsController {
final DynamicLongTask dynamicLongTask = new DynamicLongTask((DynamicStatistics) statistics);
executor.execute(dynamicLongTask, new Runnable() {
@Override
public void run() {
executeDynamic((DynamicStatistics) statistics, dynamicLongTask);
}
@@ -137,6 +142,7 @@ public class StatisticsControllerImpl implements StatisticsController {
LongTask task = statistics instanceof LongTask ? (LongTask) statistics : null;
executor.execute(task, new Runnable() {
@Override
public void run() {
execute(statistics);
}
@@ -144,13 +150,14 @@ public class StatisticsControllerImpl implements StatisticsController {
}
}
@Override
public void execute(Statistics statistics) {
if (statistics instanceof DynamicStatistics) {
executeDynamic((DynamicStatistics) statistics, null);
} else {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getModel();
AttributeModel attributeModel = Lookup.getDefault().lookup(AttributeController.class).getModel();
GraphModel graphModel = graphController.getGraphModel();
AttributeModel attributeModel = graphController.getAttributeModel();
statistics.execute(graphModel, attributeModel);
model.addReport(statistics);
}
@@ -158,42 +165,23 @@ public class StatisticsControllerImpl implements StatisticsController {
private void executeDynamic(DynamicStatistics statistics, DynamicLongTask dynamicLongTask) {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getModel();
AttributeController attributeController = Lookup.getDefault().lookup(AttributeController.class);
DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
DynamicModel dynamicModel = dynamicController.getModel();
AttributeModel attributeModel = attributeController.getModel();
if (!dynamicModel.isDynamicGraph()) {
throw new IllegalArgumentException("The current graph must be a dynamic graph");
}
GraphModel graphModel = graphController.getGraphModel();
AttributeModel attributeModel = graphController.getAttributeModel();
double window = statistics.getWindow();
double tick = statistics.getTick();
Interval bounds = statistics.getBounds();
if (bounds == null) {
TimeInterval visibleInterval = dynamicModel.getVisibleInterval();
double low = visibleInterval.getLow();
if (Double.isInfinite(low)) {
low = dynamicModel.getMin();
}
double high = visibleInterval.getHigh();
if (Double.isInfinite(high)) {
high = dynamicModel.getMax();
}
bounds = new Interval(low, high);
bounds = graphModel.getTimeBoundsVisible();
statistics.setBounds(bounds);
}
if (dynamicLongTask != null) {
//Count
int c = (int) ((bounds.getHigh() - window - bounds.getLow()) / tick);
dynamicLongTask.start(c);
}
HierarchicalGraph graph = graphModel.getHierarchicalGraphVisible();
DynamicGraph dynamicGraph = dynamicModel.createDynamicGraph(graph, bounds);
//Init
statistics.execute(graphModel, attributeModel);
@@ -201,7 +189,24 @@ public class StatisticsControllerImpl implements StatisticsController {
for (double low = bounds.getLow(); low <= bounds.getHigh() - window; low += tick) {
double high = low + window;
Graph g = dynamicGraph.getSnapshotGraph(low, high);
// Graph g = dynamicGraph.getSnapshotGraph(low, high);
GraphView currentView = graphModel.getVisibleView();
Graph graph = graphModel.getGraphVisible();
GraphView view = graphModel.createView();
Graph g = graphModel.getGraph(view);
TimestampIndex<Node> nodeIndex = graphModel.getNodeTimestampIndex(currentView);
for(Node node : nodeIndex.get(low, high)) {
g.addNode(node);
}
TimestampIndex<Edge> edgeIndex = graphModel.getEdgeTimestampIndex(currentView);
for(Edge edge : edgeIndex.get(low, high)) {
g.addEdge(edge);
}
statistics.loop(g.getView(), new Interval(low, high));
@@ -45,7 +45,6 @@ package org.gephi.statistics.api;
import org.gephi.project.api.Workspace;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.gephi.statistics.spi.StatisticsUI;
import org.gephi.utils.longtask.api.LongTaskListener;
import org.gephi.utils.longtask.spi.LongTask;
@@ -42,8 +42,8 @@ Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.spi;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.type.Interval;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.time.Interval;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.GraphView;
@@ -42,7 +42,8 @@ Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.spi;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.graph.api.GraphModel;
/**
-4
Ver Arquivo
@@ -16,10 +16,6 @@
<name>StatisticsPlugin</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>data-attributes-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>dynamic-api</artifactId>
@@ -1,43 +1,43 @@
/*
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin;
@@ -47,19 +47,16 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Column;
import org.gephi.attribute.api.Table;
import org.gephi.statistics.spi.Statistics;
import org.gephi.graph.api.Node;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeRow;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.HierarchicalDirectedGraph;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.Progress;
import org.gephi.utils.progress.ProgressTicket;
@@ -68,16 +65,19 @@ import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.openide.util.Lookup;
import org.gephi.graph.api.NodeIterable;
import org.openide.util.Lookup;
/**
* Ref: Matthieu Latapy, Main-memory Triangle Computations for Very Large (Sparse (Power-Law)) Graphs,
* in Theoretical Computer Science (TCS) 407 (1-3), pages 458-473, 2008
* Ref: Matthieu Latapy, Main-memory Triangle Computations for Very Large
* (Sparse (Power-Law)) Graphs, in Theoretical Computer Science (TCS) 407 (1-3),
* pages 458-473, 2008
*
* @author pjmcswee
*/
class Renumbering implements Comparator<EdgeWrapper> {
@Override
public int compare(EdgeWrapper o1, EdgeWrapper o2) {
if (o1.wrapper.getID() < o2.wrapper.getID()) {
return -1;
@@ -114,7 +114,9 @@ class ArrayWrapper implements Comparable {
private int ID;
public Node node;
/** Empty Constructor/ */
/**
* Empty Constructor/
*/
ArrayWrapper() {
}
@@ -183,6 +185,7 @@ class ArrayWrapper implements Comparable {
* @param o
* @return
*/
@Override
public int compareTo(Object o) {
ArrayWrapper aw = (ArrayWrapper) o;
if (aw.length() < length()) {
@@ -202,13 +205,21 @@ class ArrayWrapper implements Comparable {
public class ClusteringCoefficient implements Statistics, LongTask {
public static final String CLUSTERING_COEFF = "clustering";
/** The avergage Clustering Coefficient.*/
/**
* The avergage Clustering Coefficient.
*/
private double avgClusteringCoeff;
/**Indicates should treat graph as undirected.*/
/**
* Indicates should treat graph as undirected.
*/
private boolean isDirected;
/** Indicates statistics should stop processing/*/
/**
* Indicates statistics should stop processing/
*/
private boolean isCanceled;
/** Keeps track of Progress made. */
/**
* Keeps track of Progress made.
*/
private ProgressTicket progress;
private int[] triangles;
private ArrayWrapper[] network;
@@ -219,8 +230,8 @@ public class ClusteringCoefficient implements Statistics, LongTask {
public ClusteringCoefficient() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController != null && graphController.getModel() != null) {
isDirected = graphController.getModel().isDirected();
if (graphController != null && graphController.getGraphModel() != null) {
isDirected = graphController.getGraphModel().isDirected();
}
}
@@ -228,82 +239,133 @@ public class ClusteringCoefficient implements Statistics, LongTask {
return avgClusteringCoeff;
}
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
HierarchicalGraph hgraph = null;
isDirected = graphModel.isDirected();
Graph hgraph = null;
if (isDirected) {
hgraph = graphModel.getHierarchicalDirectedGraphVisible();
hgraph = graphModel.getDirectedGraphVisible();
} else {
hgraph = graphModel.getHierarchicalUndirectedGraphVisible();
hgraph = graphModel.getUndirectedGraphVisible();
}
execute(hgraph, attributeModel);
}
public void execute(HierarchicalGraph hgraph, AttributeModel attributeModel) {
public void execute(Graph hgraph, AttributeModel attributeModel) {
isCanceled = false;
if(isDirected)
bruteForce(hgraph, attributeModel);
else
triangles(hgraph);
HashMap<String, Double> resultValues = new HashMap<String, Double>();
if (isDirected) {
avgClusteringCoeff = bruteForce(hgraph, attributeModel);
} else {
initStartValues(hgraph);
resultValues = computeTriangles(hgraph, network, triangles, nodeClustering, isDirected);
totalTriangles = resultValues.get("triangles").intValue();
avgClusteringCoeff = resultValues.get("clusteringCoefficient");
//Set results in columns
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeColumn clusteringCol = nodeTable.getColumn(CLUSTERING_COEFF);
if (clusteringCol == null) {
clusteringCol = nodeTable.addColumn(CLUSTERING_COEFF, "Clustering Coefficient", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, new Double(0));
}
AttributeColumn triCount = null;
if(!isDirected){
//Set results in columns
Table nodeTable = attributeModel.getNodeTable();
Column clusteringCol = nodeTable.getColumn(CLUSTERING_COEFF);
if (clusteringCol == null) {
clusteringCol = nodeTable.addColumn(CLUSTERING_COEFF, "Clustering Coefficient", Double.class, new Double(0));
}
Column triCount = null;
if (!isDirected) {
triCount = nodeTable.getColumn("Triangles");
if (triCount == null) {
triCount = nodeTable.addColumn("Triangles", "Number of triangles", AttributeType.INT, AttributeOrigin.COMPUTED, new Integer(0));
triCount = nodeTable.addColumn("Triangles", "Number of triangles", Integer.class, new Integer(0));
}
}
for (int v = 0; v < N; v++) {
if (network[v].length() > 1) {
AttributeRow row = (AttributeRow) network[v].node.getNodeData().getAttributes();
row.setValue(clusteringCol, nodeClustering[v]);
if(!isDirected)
row.setValue(triCount, triangles[v]);
network[v].node.setAttribute(clusteringCol, nodeClustering[v]);
if (!isDirected) {
network[v].node.setAttribute(triCount, triangles[v]);
}
}
}
}
private int closest_in_array(int v) {
int right = network[v].length() - 1;
public void triangles(Graph hgraph) {
initStartValues(hgraph);
HashMap<String, Double> resultValues = computeTriangles(hgraph, network, triangles,
nodeClustering, isDirected);
totalTriangles = resultValues.get("triangles").intValue();
avgClusteringCoeff = resultValues.get("clusteringCoefficient");
}
public HashMap<String, Double> computeClusteringCoefficient(Graph hgraph, ArrayWrapper[] currentNetwork,
int[] currentTriangles, double[] currentNodeClustering, boolean directed) {
HashMap<String, Double> resultValues = new HashMap<String, Double>();
if (isDirected) {
double avClusteringCoefficient = bruteForce(hgraph, null);
resultValues.put("clusteringCoefficient", avClusteringCoefficient);
return resultValues;
} else {
initStartValues(hgraph);
resultValues = computeTriangles(hgraph, currentNetwork, currentTriangles, currentNodeClustering, directed);
return resultValues;
}
}
public void initStartValues(Graph hgraph) {
N = hgraph.getNodeCount();
K = (int) Math.sqrt(N);
nodeClustering = new double[N];
network = new ArrayWrapper[N];
triangles = new int[N];
}
public int createIndiciesMapAndInitNetwork(Graph hgraph, HashMap<Node, Integer> indicies, ArrayWrapper[] networks, int currentProgress) {
int index = 0;
for (Node s : hgraph.getNodes()) {
indicies.put(s, index);
networks[index] = new ArrayWrapper();
index++;
Progress.progress(progress, ++currentProgress);
}
return currentProgress;
}
private int closest_in_array(ArrayWrapper[] currentNetwork, int v) {
int right = currentNetwork[v].length() - 1;
/* optimization for extreme cases */
if (right < 0) {
return (-1);
}
if (network[v].get(0) >= v) {
if (currentNetwork[v].get(0) >= v) {
return (-1);
}
if (network[v].get(right) < v) {
if (currentNetwork[v].get(right) < v) {
return (right);
}
if (network[v].get(right) == v) {
if (currentNetwork[v].get(right) == v) {
return (right - 1);
}
int left = 0, mid;
while (right > left) {
mid = (left + right) / 2;
if (v < network[v].get(mid)) {
if (v < currentNetwork[v].get(mid)) {
right = mid - 1;
} else if (v > network[v].get(mid)) {
} else if (v > currentNetwork[v].get(mid)) {
left = mid + 1;
} else {
return (mid - 1);
}
}
if (v > network[v].get(right)) {
if (v > currentNetwork[v].get(right)) {
return (right);
} else {
@@ -315,37 +377,38 @@ public class ClusteringCoefficient implements Statistics, LongTask {
*
* @param v - The specific node to count the triangles on.
*/
private void newVertex(int v) {
int[] A = new int[N];
private void newVertex(ArrayWrapper[] currentNetwork, int[] currentTrianlgles, int v, int n) {
int[] A = new int[n];
for (int i = network[v].length() - 1; (i >= 0) && (network[v].get(i) > v); i--) {
int neighbor = network[v].get(i);
A[neighbor] = network[v].getCount(i);
for (int i = currentNetwork[v].length() - 1; (i >= 0) && (currentNetwork[v].get(i) > v); i--) {
int neighbor = currentNetwork[v].get(i);
A[neighbor] = currentNetwork[v].getCount(i);
}
for (int i = network[v].length() - 1; i >= 0; i--) {
int neighbor = network[v].get(i);
for (int j = closest_in_array(neighbor); j >= 0; j--) {
int next = network[neighbor].get(j);
for (int i = currentNetwork[v].length() - 1; i >= 0; i--) {
int neighbor = currentNetwork[v].get(i);
for (int j = closest_in_array(currentNetwork, neighbor); j >= 0; j--) {
int next = currentNetwork[neighbor].get(j);
if (A[next] > 0) {
triangles[next] += network[v].getCount(i);
triangles[v] += network[v].getCount(i);
triangles[neighbor] += A[next];
currentTrianlgles[next] += currentNetwork[v].getCount(i);
currentTrianlgles[v] += currentNetwork[v].getCount(i);
currentTrianlgles[neighbor] += A[next];
}
}
}
}
private void tr_link_nohigh(int u, int v, int count) {
private void tr_link_nohigh(ArrayWrapper[] currentNetwork, int[] currentTriangles, int u, int v, int count, int k) {
int iu = 0, iv = 0, w;
while ((iu < network[u].length()) && (iv < network[v].length())) {
if (network[u].get(iu) < network[v].get(iv)) {
while ((iu < currentNetwork[u].length()) && (iv < currentNetwork[v].length())) {
if (currentNetwork[u].get(iu) < currentNetwork[v].get(iv)) {
iu++;
} else if (network[u].get(iu) > network[v].get(iv)) {
} else if (currentNetwork[u].get(iu) > currentNetwork[v].get(iv)) {
iv++;
} else { /* neighbor in common */
w = network[u].get(iu);
if (w >= K) {
triangles[w] += count;
w = currentNetwork[u].get(iu);
if (w >= k) {
currentTriangles[w] += count;
}
iu++;
iv++;
@@ -353,203 +416,272 @@ public class ClusteringCoefficient implements Statistics, LongTask {
}
}
public void triangles(HierarchicalGraph hgraph) {
private HashMap<Node, EdgeWrapper> createNeighbourTable(Graph hgraph, Node node, HashMap<Node, Integer> indicies,
ArrayWrapper[] networks, boolean directed) {
HashMap<Node, EdgeWrapper> neighborTable = new HashMap<Node, EdgeWrapper>();
if (!directed) {
for (Edge edge : hgraph.getEdges(node)) {
Node neighbor = hgraph.getOpposite(node, edge);
neighborTable.put(neighbor, new EdgeWrapper(1, networks[indicies.get(neighbor)]));
}
} else {
for (Node neighbor : ((DirectedGraph) hgraph).getPredecessors(node)) {
neighborTable.put(neighbor, new EdgeWrapper(1, networks[indicies.get(neighbor)]));
}
for (Edge out : ((DirectedGraph) hgraph).getOutEdges(node)) {
Node neighbor = out.getTarget();
EdgeWrapper ew = neighborTable.get(neighbor);
if (ew == null) {
neighborTable.put(neighbor, new EdgeWrapper(1, network[indicies.get(neighbor)]));
} else {
ew.count++;
}
}
}
return neighborTable;
}
private EdgeWrapper[] getEdges(HashMap<Node, EdgeWrapper> neighborTable) {
int i = 0;
EdgeWrapper[] edges = new EdgeWrapper[neighborTable.size()];
for (EdgeWrapper e : neighborTable.values()) {
edges[i] = e;
i++;
}
return edges;
}
private int processNetwork(ArrayWrapper[] currentNetwork, int currentProgress) {
Arrays.sort(currentNetwork);
for (int j = 0; j < N; j++) {
currentNetwork[j].setID(j);
Progress.progress(progress, ++currentProgress);
}
for (int j = 0; j < N; j++) {
Arrays.sort(currentNetwork[j].getArray(), new Renumbering());
Progress.progress(progress, ++currentProgress);
}
return currentProgress;
}
private int computeRemainingTrianles(Graph hgraph, ArrayWrapper[] currentNetwork, int[] currentTriangles, int currentProgress) {
int n = hgraph.getNodeCount();
int k = (int) Math.sqrt(n);
for (int v = n - 1; (v >= 0) && (v >= k); v--) {
for (int i = closest_in_array(currentNetwork, v); i >= 0; i--) {
int u = currentNetwork[v].get(i);
if (u >= k) {
tr_link_nohigh(currentNetwork, currentTriangles, u, v, currentNetwork[v].getCount(i), k);
}
}
Progress.progress(progress, ++currentProgress);
if (isCanceled) {
hgraph.readUnlockAll();
return currentProgress;
}
}
return currentProgress;
}
private HashMap<String, Double> computeResultValues(Graph hgraph, ArrayWrapper[] currentNetwork,
int[] currentTriangles, double[] currentNodeClusterig, boolean directed, int currentProgress) {
int n = hgraph.getNodeCount();
HashMap<String, Double> totalValues = new HashMap<String, Double>();
int numNodesDegreeGreaterThanOne = 0;
int trianglesNumber = 0;
double currentClusteringCoefficient = 0;
for (int v = 0; v < n; v++) {
if (currentNetwork[v].length() > 1) {
numNodesDegreeGreaterThanOne++;
double cc = currentTriangles[v];
trianglesNumber += currentTriangles[v];
cc /= (currentNetwork[v].length() * (currentNetwork[v].length() - 1));
if (!directed) {
cc *= 2.0f;
}
currentNodeClusterig[v] = cc;
currentClusteringCoefficient += cc;
}
Progress.progress(progress, ++currentProgress);
if (isCanceled) {
hgraph.readUnlockAll();
return totalValues;
}
}
trianglesNumber /= 3;
currentClusteringCoefficient /= numNodesDegreeGreaterThanOne;
totalValues.put("triangles", (double) trianglesNumber);
totalValues.put("clusteringCoefficient", currentClusteringCoefficient);
return totalValues;
}
private HashMap<String, Double> computeTriangles(Graph hgraph, ArrayWrapper[] currentNetwork, int[] currentTriangles,
double[] nodeClustering, boolean directed) {
HashMap<String, Double> resultValues = new HashMap<String, Double>();
int ProgressCount = 0;
Progress.start(progress, 7 * hgraph.getNodeCount());
hgraph.readLock();
N = hgraph.getNodeCount();
nodeClustering = new double[N];
int n = hgraph.getNodeCount();
/** Create network for processing */
network = new ArrayWrapper[N];
/** */
/**
* Create network for processing
*/
/**
* */
HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
ProgressCount = createIndiciesMapAndInitNetwork(hgraph, indicies, currentNetwork, ProgressCount);
int index = 0;
for (Node s : hgraph.getNodes()) {
indicies.put(s, index);
network[index] = new ArrayWrapper();
index++;
Progress.progress(progress, ++ProgressCount);
}
index = 0;
for (Node node : hgraph.getNodes()) {
HashMap<Node, EdgeWrapper> neighborTable = new HashMap<Node, EdgeWrapper>();
HashMap<Node, EdgeWrapper> neighborTable = createNeighbourTable(hgraph, node, indicies, currentNetwork, directed);
if (!isDirected) {
for (Edge edge : hgraph.getEdgesAndMetaEdges(node)) {
Node neighbor = hgraph.getOpposite(node, edge);
neighborTable.put(neighbor, new EdgeWrapper(1, network[indicies.get(neighbor)]));
}
} else {
for (Edge in : ((HierarchicalDirectedGraph) hgraph).getInEdgesAndMetaInEdges(node)) {
Node neighbor = in.getSource().getNodeData().getNode(hgraph.getView().getViewId());
neighborTable.put(neighbor, new EdgeWrapper(1, network[indicies.get(neighbor)]));
}
for (Edge out : ((HierarchicalDirectedGraph) hgraph).getOutEdgesAndMetaOutEdges(node)) {
Node neighbor = out.getTarget().getNodeData().getNode(hgraph.getView().getViewId());
EdgeWrapper ew = neighborTable.get(neighbor);
if (ew == null) {
neighborTable.put(neighbor, new EdgeWrapper(1, network[indicies.get(neighbor)]));
} else {
ew.count++;
}
}
}
EdgeWrapper[] edges = new EdgeWrapper[neighborTable.size()];
int i = 0;
for (EdgeWrapper e : neighborTable.values()) {
edges[i] = e;
i++;
}
network[index].node = node;
network[index].setArray(edges);
EdgeWrapper[] edges = getEdges(neighborTable);
currentNetwork[index].node = node;
currentNetwork[index].setArray(edges);
index++;
Progress.progress(progress, ++ProgressCount);
if (isCanceled) {
hgraph.readUnlockAll();
return;
return resultValues;
}
}
Arrays.sort(network);
for (int j = 0; j < N; j++) {
network[j].setID(j);
Progress.progress(progress, ++ProgressCount);
}
ProgressCount = processNetwork(currentNetwork, ProgressCount);
for (int j = 0; j < N; j++) {
Arrays.sort(network[j].getArray(), new Renumbering());
Progress.progress(progress, ++ProgressCount);
}
int k = (int) Math.sqrt(n);
triangles = new int[N];
K = (int) Math.sqrt(N);
for (int v = 0; v < K && v < N; v++) {
newVertex(v);
for (int v = 0; v < k && v < n; v++) {
newVertex(currentNetwork, currentTriangles, v, n);
Progress.progress(progress, ++ProgressCount);
}
/* remaining links */
for (int v = N - 1; (v >= 0) && (v >= K); v--) {
for (int i = closest_in_array(v); i >= 0; i--) {
int u = network[v].get(i);
if (u >= K) {
tr_link_nohigh(u, v, network[v].getCount(i));
}
}
Progress.progress(progress, ++ProgressCount);
ProgressCount = computeRemainingTrianles(hgraph, currentNetwork, currentTriangles, ProgressCount);
if (isCanceled) {
hgraph.readUnlockAll();
return;
}
}
//Results and average
avgClusteringCoeff = 0;
totalTriangles = 0;
int numNodesDegreeGreaterThanOne = 0;
for (int v = 0; v < N; v++) {
if (network[v].length() > 1) {
numNodesDegreeGreaterThanOne++;
double cc = triangles[v];
totalTriangles += triangles[v];
cc /= (network[v].length() * (network[v].length() - 1));
if (!isDirected) {
cc *= 2.0f;
}
nodeClustering[v] = cc;
avgClusteringCoeff += cc;
}
Progress.progress(progress, ++ProgressCount);
if (isCanceled) {
hgraph.readUnlockAll();
return;
}
}
totalTriangles /= 3;
avgClusteringCoeff /= numNodesDegreeGreaterThanOne;
resultValues = computeResultValues(hgraph, currentNetwork, currentTriangles, nodeClustering, directed, ProgressCount);
hgraph.readUnlock();
return resultValues;
}
private void bruteForce(HierarchicalGraph hgraph, AttributeModel attributeModel) {
//The atrributes computed by the statistics
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeColumn clusteringCol = nodeTable.getColumn("clustering");
if (clusteringCol == null) {
clusteringCol = nodeTable.addColumn("clustering", "Clustering Coefficient", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, new Double(0));
private double bruteForce(Graph hgraph, AttributeModel attributeModel) {
//The atrributes computed by the statistics
Column clusteringColumn = initializeAttributeColunms(attributeModel);
float totalCC = 0;
hgraph.readLock();
Progress.start(progress, hgraph.getNodeCount());
int node_count = 0;
for (Node node : hgraph.getNodes()) {
float nodeClusteringCoefficient = computeNodeClusteringCoefficient(hgraph, node, isDirected);
if (nodeClusteringCoefficient > -1) {
saveCalculatedValue(node, clusteringColumn, nodeClusteringCoefficient);
totalCC += nodeClusteringCoefficient;
}
if (isCanceled) {
break;
}
node_count++;
Progress.progress(progress, node_count);
}
double clusteringCoeff = totalCC / hgraph.getNodeCount();
hgraph.readUnlockAll();
return clusteringCoeff;
}
float totalCC = 0;
hgraph.readLock();
Progress.start(progress, hgraph.getNodeCount());
int node_count = 0;
for (Node node : hgraph.getNodes()) {
float nodeCC = 0;
int neighborhood = 0;
NodeIterable neighbors1 = hgraph.getNeighbors(node);
for (Node neighbor1 : neighbors1) {
neighborhood++;
NodeIterable neighbors2 = hgraph.getNeighbors(node);
for (Node neighbor2 : neighbors2) {
if (neighbor1 == neighbor2) {
continue;
private float increaseCCifNesessary(Graph hgraph, Node neighbor1, Node neighbor2, boolean directed, float nodeCC) {
if (neighbor1 == neighbor2) {
return nodeCC;
}
if (directed) {
if (hgraph.isAdjacent(neighbor1, neighbor2)) {
nodeCC++;
}
if (hgraph.isAdjacent(neighbor2, neighbor1)) {
nodeCC++;
}
} else {
if (hgraph.isAdjacent(neighbor1, neighbor2)) {
nodeCC++;
}
}
return nodeCC;
}
if (isDirected) {
if (((HierarchicalDirectedGraph) hgraph).getEdge(neighbor1, neighbor2) != null) {
nodeCC++;
private float computeNodeClusteringCoefficient(Graph hgraph, Node node, boolean directed) {
float nodeCC = 0;
int neighborhood = 0;
NodeIterable neighbors1 = hgraph.getNeighbors(node);
for (Node neighbor1 : neighbors1) {
neighborhood++;
NodeIterable neighbors2 = hgraph.getNeighbors(node);
for (Node neighbor2 : neighbors2) {
nodeCC = increaseCCifNesessary(hgraph, neighbor1, neighbor2, directed, nodeCC);
}
}
nodeCC /= 2.0;
if (neighborhood > 1) {
float cc = nodeCC / (.5f * neighborhood * (neighborhood - 1));
if (directed) {
cc = nodeCC / (neighborhood * (neighborhood - 1));
}
return cc;
} else {
return -1.f;
}
}
if (((HierarchicalDirectedGraph) hgraph).getEdge(neighbor2, neighbor1) != null) {
nodeCC++;
private Column initializeAttributeColunms(AttributeModel attributeModel) {
if (attributeModel == null) {
return null;
}
Table nodeTable = attributeModel.getNodeTable();
Column clusteringCol = nodeTable.getColumn("clustering");
if (clusteringCol == null) {
clusteringCol = nodeTable.addColumn("clustering", "Clustering Coefficient", Double.class, new Double(0));
}
return clusteringCol;
}
} else {
if (hgraph.isAdjacent(neighbor1, neighbor2)) {
nodeCC++;
}
}
}
}
nodeCC /= 2.0;
if (neighborhood > 1) {
float cc = nodeCC / (.5f * neighborhood * (neighborhood - 1));
if (isDirected) {
cc = nodeCC / (neighborhood * (neighborhood - 1));
}
AttributeRow row = (AttributeRow) node.getNodeData().getAttributes();
row.setValue(clusteringCol, cc);
totalCC += cc;
}
if (isCanceled) {
break;
}
node_count++;
Progress.progress(progress, node_count);
}
avgClusteringCoeff = totalCC / hgraph.getNodeCount();
hgraph.readUnlockAll();
private void saveCalculatedValue(Node node, Column clusteringColumn,
float nodeClusteringCoefficient) {
if (clusteringColumn == null) {
return;
}
node.setAttribute(clusteringColumn, nodeClusteringCoefficient);
}
@Override
public String getReport() {
//distribution of values
Map<Double, Integer> dist = new HashMap<Double, Integer>();
@@ -584,20 +716,20 @@ public class ClusteringCoefficient implements Statistics, LongTask {
NumberFormat f = new DecimalFormat("#0.000");
if(isDirected){
if (isDirected) {
return "<HTML> <BODY> <h1> Clustering Coefficient Metric Report </h1> "
+ "<hr>"
+ "<br />" + "<h2> Parameters: </h2>"
+ "Network Interpretation: " + (isDirected ? "directed" : "undirected") + "<br />"
+ "<br>" + "<h2> Results: </h2>"
+ "Average Clustering Coefficient: " + f.format(avgClusteringCoeff) + "<br />"
+ "The Average Clustering Coefficient is the mean value of individual coefficients.<br /><br />"
+ imageFile
+ "<br /><br />" + "<h2> Algorithm: </h2>"
+ "Simple and slow brute force.<br />"
+ "</BODY> </HTML>";
+ "<hr>"
+ "<br />" + "<h2> Parameters: </h2>"
+ "Network Interpretation: " + (isDirected ? "directed" : "undirected") + "<br />"
+ "<br>" + "<h2> Results: </h2>"
+ "Average Clustering Coefficient: " + f.format(avgClusteringCoeff) + "<br />"
+ "The Average Clustering Coefficient is the mean value of individual coefficients.<br /><br />"
+ imageFile
+ "<br /><br />" + "<h2> Algorithm: </h2>"
+ "Simple and slow brute force.<br />"
+ "</BODY> </HTML>";
} else {
return "<HTML> <BODY> <h1> Clustering Coefficient Metric Report </h1> "
+ "<hr>"
+ "<br />" + "<h2> Parameters: </h2>"
@@ -610,7 +742,7 @@ public class ClusteringCoefficient implements Statistics, LongTask {
+ "<br /><br />" + "<h2> Algorithm: </h2>"
+ "Matthieu Latapy, <i>Main-memory Triangle Computations for Very Large (Sparse (Power-Law)) Graphs</i>, in Theoretical Computer Science (TCS) 407 (1-3), pages 458-473, 2008<br />"
+ "</BODY> </HTML>";
}
}
}
public void setDirected(boolean isDirected) {
@@ -621,11 +753,13 @@ public class ClusteringCoefficient implements Statistics, LongTask {
return isDirected;
}
@Override
public boolean cancel() {
isCanceled = true;
return true;
}
@Override
public void setProgressTicket(ProgressTicket ProgressTicket) {
this.progress = ProgressTicket;
}
@@ -1,67 +1,63 @@
/*
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeRow;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Column;
import org.gephi.attribute.api.Table;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.EdgeIterable;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.HierarchicalDirectedGraph;
import org.gephi.graph.api.HierarchicalUndirectedGraph;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.NodeIterable;
import org.gephi.graph.api.UndirectedGraph;
import org.gephi.statistics.spi.Statistics;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.Progress;
@@ -91,49 +87,57 @@ public class ConnectedComponents implements Statistics, LongTask {
public ConnectedComponents() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController != null && graphController.getModel() != null) {
isDirected = graphController.getModel().isDirected();
if (graphController != null && graphController.getGraphModel() != null) {
isDirected = graphController.getGraphModel().isDirected();
}
}
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
isDirected = graphModel.isDirected();
isCanceled = false;
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraphVisible();
undirectedGraph.readLock();
HierarchicalUndirectedGraph undirectedGraph = graphModel.getHierarchicalUndirectedGraphVisible();
weaklyConnected(undirectedGraph, attributeModel);
if (isDirected) {
HierarchicalDirectedGraph directedGraph = graphModel.getHierarchicalDirectedGraphVisible();
top_tarjans(directedGraph, attributeModel);
DirectedGraph directedGraph = graphModel.getDirectedGraphVisible();
stronglyConnected(directedGraph, attributeModel);
}
undirectedGraph.readUnlock();
}
public void weaklyConnected(HierarchicalUndirectedGraph hgraph, AttributeModel attributeModel) {
public void weaklyConnected(UndirectedGraph graph, AttributeModel attributeModel) {
isCanceled = false;
componentCount = 0;
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeColumn componentCol = nodeTable.getColumn(WEAKLY);
if (componentCol == null) {
componentCol = nodeTable.addColumn(WEAKLY, "Component ID", AttributeType.INT, AttributeOrigin.COMPUTED, new Integer(0));
}
List<Integer> sizeList = new ArrayList<Integer>();
Column componentCol = initializeWeeklyConnectedColumn(attributeModel);
hgraph.readLock();
HashMap<Node, Integer> indicies = createIndiciesMap(graph);
HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
int index = 0;
for (Node s : hgraph.getNodes()) {
indicies.put(s, index);
index++;
}
LinkedList<LinkedList<Node>> components = computeWeeklyConnectedComponents(graph, indicies);
saveComputedComponents(components, componentCol);
int N = hgraph.getNodeCount();
fillComponentSizeList(components);
componentCount = components.size();
}
public LinkedList<LinkedList<Node>> computeWeeklyConnectedComponents(Graph graph, HashMap<Node, Integer> indicies) {
int N = graph.getNodeCount();
//Keep track of which nodes have been seen
int[] color = new int[N];
Progress.start(progress, hgraph.getNodeCount());
Progress.start(progress, N);
int seenCount = 0;
LinkedList<LinkedList<Node>> components = new LinkedList<LinkedList<Node>>();
while (seenCount < N) {
//The search Q
LinkedList<Node> Q = new LinkedList<Node>();
@@ -141,7 +145,7 @@ public class ConnectedComponents implements Statistics, LongTask {
LinkedList<Node> component = new LinkedList<Node>();
//Seed the seach Q
NodeIterable iter = hgraph.getNodes();
NodeIterable iter = graph.getNodes();
for (Node first : iter) {
if (color[indicies.get(first)] == 0) {
Q.add(first);
@@ -153,19 +157,19 @@ public class ConnectedComponents implements Statistics, LongTask {
//While there are more nodes to search
while (!Q.isEmpty()) {
if (isCanceled) {
hgraph.readUnlock();
return;
graph.readUnlock();
return new LinkedList<LinkedList<Node>>();
}
//Get the next Node and add it to the component list
Node u = Q.removeFirst();
component.add(u);
//Iterate over all of u's neighbors
EdgeIterable edgeIter = hgraph.getEdgesAndMetaEdges(u);
EdgeIterable edgeIter = graph.getEdges(u);
//For each neighbor
for (Edge edge : edgeIter) {
Node reachable = hgraph.getOpposite(u, edge);
Node reachable = graph.getOpposite(u, edge);
int id = indicies.get(reachable);
//If this neighbor is unvisited
if (color[id] == 0) {
@@ -180,39 +184,79 @@ public class ConnectedComponents implements Statistics, LongTask {
color[indicies.get(u)] = 2;
seenCount++;
}
for (Node s : component) {
AttributeRow row = (AttributeRow) s.getNodeData().getAttributes();
row.setValue(componentCol, componentCount);
}
sizeList.add(component.size());
componentCount++;
components.add(component);
}
hgraph.readUnlock();
return components;
}
componentsSize = new int[sizeList.size()];
for (int i = 0; i < sizeList.size(); i++) {
componentsSize[i] = sizeList.get(i);
private Column initializeWeeklyConnectedColumn(AttributeModel attributeModel) {
Table nodeTable = attributeModel.getNodeTable();
Column componentCol = nodeTable.getColumn(WEAKLY);
if (componentCol == null) {
componentCol = nodeTable.addColumn(WEAKLY, "Component ID", Integer.class, new Integer(0));
}
return componentCol;
}
public HashMap<Node, Integer> createIndiciesMap(Graph hgraph) {
HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
int index = 0;
for (Node s : hgraph.getNodes()) {
indicies.put(s, index);
index++;
}
return indicies;
}
private void saveComputedComponents(LinkedList<LinkedList<Node>> components, Column componentCol) {
int i = 0;
for (LinkedList<Node> component : components) {
for (Node s : component) {
s.setAttribute(componentCol, i);
}
i++;
}
}
public void top_tarjans(HierarchicalDirectedGraph hgraph, AttributeModel attributeModel) {
void fillComponentSizeList(LinkedList<LinkedList<Node>> components) {
componentsSize = new int[components.size()];
for (int i = 0; i < components.size(); i++) {
componentsSize[i] = components.get(i).size();
}
}
private Column initializeStronglyConnectedColumn(AttributeModel attributeModel) {
Table nodeTable = attributeModel.getNodeTable();
Column componentCol = nodeTable.getColumn(STRONG);
if (componentCol == null) {
componentCol = nodeTable.addColumn(STRONG, "Strongly-Connected ID", Integer.class, new Integer(0));
}
return componentCol;
}
public void stronglyConnected(DirectedGraph hgraph, AttributeModel attributeModel) {
count = 1;
stronglyCount = 0;
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeColumn componentCol = nodeTable.getColumn(STRONG);
if (componentCol == null) {
componentCol = nodeTable.addColumn(STRONG, "Strongly-Connected ID", AttributeType.INT, AttributeOrigin.COMPUTED, new Integer(0));
}
hgraph.readLock();
Column componentCol = initializeStronglyConnectedColumn(attributeModel);
HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
int v = 0;
for (Node s : hgraph.getNodes()) {
indicies.put(s, v);
v++;
}
int N = hgraph.getNodeCount();
HashMap<Node, Integer> indicies = createIndiciesMap(hgraph);
LinkedList<LinkedList<Node>> components = top_tarjans(hgraph, indicies);
saveComputedComponents(components, componentCol);
stronglyCount = components.size();
}
public LinkedList<LinkedList<Node>> top_tarjans(DirectedGraph graph, HashMap<Node, Integer> indicies) {
LinkedList<LinkedList<Node>> allComponents = new LinkedList<LinkedList<Node>>();
count = 1;
stronglyCount = 0;
int N = graph.getNodeCount();
int[] index = new int[N];
int[] low_index = new int[N];
@@ -223,7 +267,7 @@ public class ConnectedComponents implements Statistics, LongTask {
//LinkedList<Node> component = new LinkedList<Node>();
//Seed the seach Q
Node first = null;
NodeIterable iter = hgraph.getNodes();
NodeIterable iter = graph.getNodes();
for (Node u : iter) {
if (index[indicies.get(u)] == 0) {
first = u;
@@ -232,39 +276,44 @@ public class ConnectedComponents implements Statistics, LongTask {
}
}
if (first == null) {
hgraph.readUnlockAll();
return;
return allComponents;
}
LinkedList<LinkedList<Node>> components = new LinkedList<LinkedList<Node>>();
components = tarjans(components, S, graph, first, index, low_index, indicies);
for (LinkedList<Node> component : components) {
allComponents.add(component);
}
tarjans(componentCol, S, hgraph, first, index, low_index, indicies);
}
}
private void tarjans(AttributeColumn col, LinkedList<Node> S, HierarchicalDirectedGraph hgraph, Node f, int[] index, int[] low_index, HashMap<Node, Integer> indicies) {
private LinkedList<LinkedList<Node>> tarjans(LinkedList<LinkedList<Node>> components, LinkedList<Node> S, DirectedGraph graph, Node f, int[] index, int[] low_index, HashMap<Node, Integer> indicies) {
int id = indicies.get(f);
index[id] = count;
low_index[id] = count;
count++;
S.addFirst(f);
EdgeIterable edgeIter = hgraph.getOutEdgesAndMetaOutEdges(f);
EdgeIterable edgeIter = graph.getOutEdges(f);
for (Edge e : edgeIter) {
Node u = hgraph.getOpposite(f, e);
Node u = graph.getOpposite(f, e);
int x = indicies.get(u);
if (index[x] == 0) {
tarjans(col, S, hgraph, u, index, low_index, indicies);
tarjans(components, S, graph, u, index, low_index, indicies);
low_index[id] = Math.min(low_index[x], low_index[id]);
} else if (S.contains(u)) {
low_index[id] = Math.min(low_index[id], index[x]);
}
}
LinkedList<Node> currentComponent = new LinkedList<Node>();
if (low_index[id] == index[id]) {
Node v = null;
while (v != f) {
v = S.removeFirst();
AttributeRow row = (AttributeRow) v.getNodeData().getAttributes();
row.setValue(col, stronglyCount);
currentComponent.add(v);
}
stronglyCount++;
components.add(currentComponent);
}
return components;
}
public int getConnectedComponentsCount() {
@@ -296,15 +345,29 @@ public class ConnectedComponents implements Statistics, LongTask {
return maxIndex;
}
public int getComponentNumber(LinkedList<LinkedList<Node>> components, Node node) {
int i = 0;
for (LinkedList<Node> component : components) {
for (Node currentNode : component) {
if (currentNode.equals(node)) {
return i;
}
}
i++;
}
return 0;
}
@Override
public String getReport() {
Map<Integer, Integer> sizeDist = new HashMap<Integer, Integer>();
for(int v : componentsSize) {
if(!sizeDist.containsKey(v)) {
for (int v : componentsSize) {
if (!sizeDist.containsKey(v)) {
sizeDist.put(v, 0);
}
sizeDist.put(v, sizeDist.get(v) + 1);
}
//Distribution series
XYSeries dSeries = ChartUtils.createXYSeries(sizeDist, "Size Distribution");
@@ -327,7 +390,6 @@ public class ConnectedComponents implements Statistics, LongTask {
NumberFormat f = new DecimalFormat("#0.000");
String report = "<HTML> <BODY> <h1>Connected Components Report </h1> "
+ "<hr>"
+ "<br>"
@@ -336,7 +398,7 @@ public class ConnectedComponents implements Statistics, LongTask {
+ "<br> <h2> Results: </h2>"
+ "Number of Weakly Connected Components: " + componentCount + "<br>"
+ (isDirected ? "Number of Stronlgy Connected Components: " + stronglyCount + "<br>" : "")
+ "<br /><br />"+imageFile
+ "<br /><br />" + imageFile
+ "<br />" + "<h2> Algorithm: </h2>"
+ "Robert Tarjan, <i>Depth-First Search and Linear Graph Algorithms</i>, in SIAM Journal on Computing 1 (2): 146–160 (1972)<br />"
+ "</BODY> </HTML>";
@@ -344,11 +406,13 @@ public class ConnectedComponents implements Statistics, LongTask {
return report;
}
@Override
public boolean cancel() {
isCanceled = true;
return true;
}
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
progress = progressTicket;
}
@@ -1,43 +1,43 @@
/*
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin;
@@ -45,16 +45,11 @@ import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeRow;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Table;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.HierarchicalDirectedGraph;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.Node;
import org.gephi.statistics.spi.Statistics;
import org.gephi.utils.longtask.spi.LongTask;
@@ -74,11 +69,17 @@ public class Degree implements Statistics, LongTask {
public static final String DEGREE = "degree";
public static final String AVERAGE_DEGREE = "avgdegree";
private boolean isDirected; // only set inside this class
/** Remembers if the Cancel function has been called. */
/**
* Remembers if the Cancel function has been called.
*/
private boolean isCanceled;
/** Keep track of the work done. */
/**
* Keep track of the work done.
*/
private ProgressTicket progress;
/** */
/**
*
*/
private double avgDegree;
private Map<Integer, Integer> inDegreeDist;
private Map<Integer, Integer> outDegreeDist;
@@ -96,92 +97,134 @@ public class Degree implements Statistics, LongTask {
*
* @param graphModel
*/
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
HierarchicalGraph graph = graphModel.getHierarchicalGraphVisible();
Graph graph = graphModel.getGraphVisible();
execute(graph, attributeModel);
}
public void execute(HierarchicalGraph graph, AttributeModel attributeModel) {
isDirected = graph instanceof DirectedGraph;
public void execute(Graph graph, AttributeModel attributeModel) {
isDirected = graph.isDirected();
isCanceled = false;
inDegreeDist = new HashMap<Integer, Integer>();
outDegreeDist = new HashMap<Integer, Integer>();
degreeDist = new HashMap<Integer, Integer>();
//Attributes cols
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeTable graphTable = attributeModel.getGraphTable();
AttributeColumn inCol = nodeTable.getColumn(INDEGREE);
AttributeColumn outCol = nodeTable.getColumn(OUTDEGREE);
AttributeColumn degCol = nodeTable.getColumn(DEGREE);
AttributeColumn avgDegreeCol = graphTable.getColumn(AVERAGE_DEGREE);
if (isDirected) {
if (inCol == null) {
inCol = nodeTable.addColumn(INDEGREE, NbBundle.getMessage(Degree.class, "Degree.nodecolumn.InDegree"), AttributeType.INT, AttributeOrigin.COMPUTED, 0);
}
if (outCol == null) {
outCol = nodeTable.addColumn(OUTDEGREE, NbBundle.getMessage(Degree.class, "Degree.nodecolumn.OutDegree"), AttributeType.INT, AttributeOrigin.COMPUTED, 0);
}
}
if (degCol == null) {
degCol = nodeTable.addColumn(DEGREE, NbBundle.getMessage(Degree.class, "Degree.nodecolumn.Degree"), AttributeType.INT, AttributeOrigin.COMPUTED, 0);
}
if(avgDegreeCol == null) {
avgDegreeCol = graphTable.addColumn(AVERAGE_DEGREE, NbBundle.getMessage(Degree.class, "Degree.graphcolumn.AverageDegree"), AttributeType.DOUBLE, AttributeOrigin.COMPUTED, 0.0);
}
int i = 0;
initializeDegreeDists();
initializeAttributeColunms(attributeModel);
graph.readLock();
Progress.start(progress, graph.getNodeCount());
HierarchicalDirectedGraph directedGraph = null;
if(isDirected) {
directedGraph = graph.getGraphModel().getHierarchicalDirectedGraphVisible();
avgDegree = calculateAverageDegree(graph, isDirected, true);
graph.setAttribute(AVERAGE_DEGREE, avgDegree);
graph.readUnlockAll();
}
protected int calculateInDegree(DirectedGraph directedGraph, Node n) {
return directedGraph.getInDegree(n);
}
protected int calculateOutDegree(DirectedGraph directedGraph, Node n) {
return directedGraph.getOutDegree(n);
}
protected int calculateDegree(Graph graph, Node n) {
return graph.getDegree(n);
}
protected double calculateAverageDegree(Graph graph, boolean isDirected, boolean updateAttributes) {
double averageDegree = 0;
DirectedGraph directedGraph = null;
if (isDirected) {
directedGraph = (DirectedGraph) graph;
}
Progress.start(progress, graph.getNodeCount());
for (Node n : graph.getNodes()) {
AttributeRow row = (AttributeRow) n.getNodeData().getAttributes();
int inDegree = 0;
int outDegree = 0;
int degree = 0;
if (isDirected) {
int inDegree = directedGraph.getTotalInDegree(n);
int outDegree = directedGraph.getTotalOutDegree(n);
row.setValue(inCol, inDegree);
row.setValue(outCol, outDegree);
if (!inDegreeDist.containsKey(inDegree)) {
inDegreeDist.put(inDegree, 0);
}
inDegreeDist.put(inDegree, inDegreeDist.get(inDegree) + 1);
if (!outDegreeDist.containsKey(outDegree)) {
outDegreeDist.put(outDegree, 0);
}
outDegreeDist.put(outDegree, outDegreeDist.get(outDegree) + 1);
inDegree = calculateInDegree(directedGraph, n);
outDegree = calculateOutDegree(directedGraph, n);
}
int degree = graph.getTotalDegree(n);
row.setValue(degCol, degree);
avgDegree += degree;
if (!degreeDist.containsKey(degree)) {
degreeDist.put(degree, 0);
degree = calculateDegree(graph, n);
if (updateAttributes) {
n.setAttribute(DEGREE, degree);
if (isDirected) {
n.setAttribute(INDEGREE, inDegree);
n.setAttribute(OUTDEGREE, outDegree);
updateDegreeDists(inDegree, outDegree, degree);
} else {
updateDegreeDists(degree);
}
}
degreeDist.put(degree, degreeDist.get(degree) + 1);
averageDegree += degree;
if (isCanceled) {
break;
}
i++;
Progress.progress(progress, i);
Progress.progress(progress);
}
avgDegree /= graph.getNodeCount();
graph.getAttributes().setValue(avgDegreeCol.getIndex(), avgDegree);
averageDegree /= graph.getNodeCount();
graph.readUnlockAll();
return averageDegree;
}
private void initializeAttributeColunms(AttributeModel attributeModel) {
Table nodeTable = attributeModel.getNodeTable();
if (isDirected) {
if (!nodeTable.hasColumn(INDEGREE)) {
nodeTable.addColumn(INDEGREE, NbBundle.getMessage(Degree.class, "Degree.nodecolumn.InDegree"), Integer.class, 0);
}
if (!nodeTable.hasColumn(OUTDEGREE)) {
nodeTable.addColumn(OUTDEGREE, NbBundle.getMessage(Degree.class, "Degree.nodecolumn.OutDegree"), Integer.class, 0);
}
}
if (!nodeTable.hasColumn(DEGREE)) {
nodeTable.addColumn(DEGREE, NbBundle.getMessage(Degree.class, "Degree.nodecolumn.Degree"), Integer.class, 0);
}
}
private void initializeDegreeDists() {
inDegreeDist = new HashMap<Integer, Integer>();
outDegreeDist = new HashMap<Integer, Integer>();
degreeDist = new HashMap<Integer, Integer>();
}
private void updateDegreeDists(int inDegree, int outDegree, int degree) {
if (!inDegreeDist.containsKey(inDegree)) {
inDegreeDist.put(inDegree, 0);
}
inDegreeDist.put(inDegree, inDegreeDist.get(inDegree) + 1);
if (!outDegreeDist.containsKey(outDegree)) {
outDegreeDist.put(outDegree, 0);
}
outDegreeDist.put(outDegree, outDegreeDist.get(outDegree) + 1);
if (!degreeDist.containsKey(degree)) {
degreeDist.put(degree, 0);
}
degreeDist.put(degree, degreeDist.get(degree) + 1);
}
private void updateDegreeDists(int degree) {
if (!degreeDist.containsKey(degree)) {
degreeDist.put(degree, 0);
}
degreeDist.put(degree, degreeDist.get(degree) + 1);
}
/**
*
* @return
*/
@Override
public String getReport() {
String report = "";
if (isDirected) {
@@ -213,7 +256,7 @@ public class Degree implements Statistics, LongTask {
+ "<hr>"
+ "<br> <h2> Results: </h2>"
+ "Average Degree: " + f.format(avgDegree)
+ "<br /><br />"+degreeImageFile
+ "<br /><br />" + degreeImageFile
+ "</BODY></HTML>";
}
return report;
@@ -275,18 +318,18 @@ public class Degree implements Statistics, LongTask {
ChartUtils.decorateChart(chart3);
ChartUtils.scaleChart(chart3, dSeries, false);
String outdegreeImageFile = ChartUtils.renderChart(chart3, "outdegree-distribution.png");
NumberFormat f = new DecimalFormat("#0.000");
String report = "<HTML> <BODY> <h1>Degree Report </h1> "
+ "<hr>"
+ "<br> <h2> Results: </h2>"
+ "Average Degree: " + f.format(avgDegree)
+ "<br /><br />"+degreeImageFile
+ "<br /><br />"+indegreeImageFile
+ "<br /><br />"+outdegreeImageFile
+ "<br /><br />" + degreeImageFile
+ "<br /><br />" + indegreeImageFile
+ "<br /><br />" + outdegreeImageFile
+ "</BODY></HTML>";
return report;
}
@@ -294,6 +337,7 @@ public class Degree implements Statistics, LongTask {
*
* @return
*/
@Override
public boolean cancel() {
this.isCanceled = true;
return true;
@@ -303,6 +347,7 @@ public class Degree implements Statistics, LongTask {
*
* @param progressTicket
*/
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progress = progressTicket;
}
@@ -1,61 +1,57 @@
/*
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin;
import java.util.HashMap;
import java.util.Map;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeRow;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Column;
import org.gephi.attribute.api.Table;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.EdgeIterable;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.HierarchicalDirectedGraph;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.HierarchicalUndirectedGraph;
import org.gephi.graph.api.Node;
import org.gephi.statistics.spi.Statistics;
import org.gephi.utils.longtask.spi.LongTask;
@@ -79,14 +75,16 @@ public class EigenvectorCentrality implements Statistics, LongTask {
private double[] centralities;
private double sumChange;
private ProgressTicket progress;
/** */
/**
*
*/
private boolean isCanceled;
private boolean isDirected;
public EigenvectorCentrality() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController != null && graphController.getModel() != null) {
isDirected = graphController.getModel().isDirected();
if (graphController != null && graphController.getGraphModel() != null) {
isDirected = graphController.getGraphModel().isDirected();
}
}
@@ -95,7 +93,7 @@ public class EigenvectorCentrality implements Statistics, LongTask {
}
/**
*
*
* @return
*/
public int getNumRuns() {
@@ -103,7 +101,7 @@ public class EigenvectorCentrality implements Statistics, LongTask {
}
/**
*
*
* @return
*/
public boolean isDirected() {
@@ -111,7 +109,7 @@ public class EigenvectorCentrality implements Statistics, LongTask {
}
/**
*
*
* @param isDirected
*/
public void setDirected(boolean isDirected) {
@@ -123,97 +121,151 @@ public class EigenvectorCentrality implements Statistics, LongTask {
* @param graphModel
* @param attributeModel
*/
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
HierarchicalGraph graph = null;
isDirected = graphModel.isDirected();
isCanceled = false;
Graph graph;
if (isDirected) {
graph = graphModel.getHierarchicalDirectedGraphVisible();
graph = graphModel.getDirectedGraphVisible();
} else {
graph = graphModel.getHierarchicalUndirectedGraphVisible();
graph = graphModel.getUndirectedGraphVisible();
}
execute(graph, attributeModel);
}
public void execute(HierarchicalGraph hgraph, AttributeModel attributeModel) {
public void execute(Graph hgraph, AttributeModel attributeModel) {
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeColumn eigenCol = nodeTable.getColumn(EIGENVECTOR);
if (eigenCol == null) {
eigenCol = nodeTable.addColumn(EIGENVECTOR, "Eigenvector Centrality", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, new Double(0));
}
Column column = initializeAttributeColunms(attributeModel);
int N = hgraph.getNodeCount();
hgraph.readLock();
double[] tmp = new double[N];
centralities = new double[N];
Progress.start(progress, numRuns);
HashMap<Integer, Node> indicies = new HashMap<Integer, Node>();
HashMap<Node, Integer> invIndicies = new HashMap<Node, Integer>();
int count = 0;
for (Node u : hgraph.getNodes()) {
indicies.put(count, u);
invIndicies.put(u, count);
centralities[count] = 1;
count++;
}
for (int s = 0; s < numRuns; s++) {
double max = 0;
for (int i = 0; i < N; i++) {
Node u = indicies.get(i);
EdgeIterable iter = null;
if (isDirected) {
iter = ((HierarchicalDirectedGraph) hgraph).getInEdgesAndMetaInEdges(u);
} else {
iter = ((HierarchicalUndirectedGraph) hgraph).getEdgesAndMetaEdges(u);
}
fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
for (Edge e : iter) {
Node v = hgraph.getOpposite(u, e);
Integer id = invIndicies.get(v);
tmp[i] += centralities[id];
}
max = Math.max(max, tmp[i]);
if (isCanceled) {
return;
}
}
sumChange = 0;
for (int k = 0; k < N; k++) {
if (max != 0) {
sumChange += Math.abs(centralities[k] - (tmp[k] / max));
centralities[k] = tmp[k] / max;
//tmp[k] = 0;
}
if (isCanceled) {
return;
}
}
if (isCanceled) {
return;
}
sumChange = calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, isDirected, numRuns);
Progress.progress(progress);
}
saveCalculatedValues(hgraph, column, indicies, centralities);
for (int i = 0; i < N; i++) {
Node s = indicies.get(i);
AttributeRow row = (AttributeRow) s.getNodeData().getAttributes();
row.setValue(eigenCol, centralities[i]);
if (isCanceled) {
return;
}
}
hgraph.readUnlock();
Progress.finish(progress);
}
private Column initializeAttributeColunms(AttributeModel attributeModel) {
Table nodeTable = attributeModel.getNodeTable();
Column eigenCol = nodeTable.getColumn(EIGENVECTOR);
if (eigenCol == null) {
eigenCol = nodeTable.addColumn(EIGENVECTOR, "Eigenvector Centrality", Double.class, new Double(0));
}
return eigenCol;
}
private void saveCalculatedValues(Graph hgraph, Column attributeColumn, HashMap<Integer, Node> indicies,
double[] eigCenrtalities) {
int N = hgraph.getNodeCount();
for (int i = 0; i < N; i++) {
Node s = indicies.get(i);
s.setAttribute(attributeColumn, eigCenrtalities[i]);
}
}
public void fillIndiciesMaps(Graph hgraph, double[] eigCentralities, HashMap<Integer, Node> indicies, HashMap<Node, Integer> invIndicies) {
if (indicies == null || invIndicies == null) {
return;
}
int count = 0;
for (Node u : hgraph.getNodes()) {
indicies.put(count, u);
invIndicies.put(u, count);
eigCentralities[count] = 1;
count++;
}
}
private double computeMaxValueAndTempValues(Graph hgraph, HashMap<Integer, Node> indicies, HashMap<Node, Integer> invIndicies,
double[] tempValues, double[] centralityValues, boolean directed) {
double max = 0.;
int N = hgraph.getNodeCount();
for (int i = 0; i < N; i++) {
Node u = indicies.get(i);
EdgeIterable iter = null;
if (directed) {
iter = ((DirectedGraph) hgraph).getInEdges(u);
} else {
iter = hgraph.getEdges(u);
}
for (Edge e : iter) {
Node v = hgraph.getOpposite(u, e);
Integer id = invIndicies.get(v);
tempValues[i] += centralityValues[id];
}
max = Math.max(max, tempValues[i]);
if (isCanceled) {
return max;
}
}
return max;
}
private double updateValues(Graph hgraph, double[] tempValues, double[] centralityValues, double max) {
double sumChanged = 0.;
int N = hgraph.getNodeCount();
for (int k = 0; k < N; k++) {
if (max != 0) {
sumChanged += Math.abs(centralityValues[k] - (tempValues[k] / max));
centralityValues[k] = tempValues[k] / max;
}
if (isCanceled) {
return sumChanged;
}
}
return sumChanged;
}
public double calculateEigenvectorCentrality(Graph hgraph, double[] eigCentralities,
HashMap<Integer, Node> indicies, HashMap<Node, Integer> invIndicies,
boolean directed, int numIterations) {
int N = hgraph.getNodeCount();
double sumChanged = 0.;
double[] tmp = new double[N];
for (int s = 0; s < numIterations; s++) {
double max = computeMaxValueAndTempValues(hgraph, indicies, invIndicies, tmp, eigCentralities, directed);
sumChanged = updateValues(hgraph, tmp, eigCentralities, max);
if (isCanceled) {
return sumChanged;
}
Progress.progress(progress);
}
return sumChanged;
}
/**
*
*
* @return
*/
@Override
public String getReport() {
//distribution of values
Map<Double, Integer> dist = new HashMap<Double, Integer>();
@@ -246,7 +298,7 @@ public class EigenvectorCentrality implements Statistics, LongTask {
ChartUtils.decorateChart(chart);
ChartUtils.scaleChart(chart, dSeries, true);
String imageFile = ChartUtils.renderChart(chart, "eigenvector-centralities.png");
String report = "<HTML> <BODY> <h1>Eigenvector Centrality Report</h1> "
+ "<hr>"
+ "<h2> Parameters: </h2>"
@@ -261,11 +313,13 @@ public class EigenvectorCentrality implements Statistics, LongTask {
}
@Override
public boolean cancel() {
this.isCanceled = true;
return true;
}
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progress = progressTicket;
@@ -43,10 +43,10 @@ package org.gephi.statistics.plugin;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.statistics.spi.Statistics;
import org.openide.util.Lookup;
@@ -63,8 +63,8 @@ public class GraphDensity implements Statistics {
public GraphDensity() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController != null && graphController.getModel() != null) {
isDirected = graphController.getModel().isDirected();
if (graphController != null && graphController.getGraphModel()!= null) {
isDirected = graphController.getGraphModel().isDirected();
}
}
@@ -80,29 +80,37 @@ public class GraphDensity implements Statistics {
return density;
}
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
HierarchicalGraph hgraph;
Graph graph;
if (isDirected) {
hgraph = graphModel.getHierarchicalDirectedGraphVisible();
graph = graphModel.getDirectedGraphVisible();
} else {
hgraph = graphModel.getHierarchicalUndirectedGraphVisible();
graph = graphModel.getUndirectedGraphVisible();
}
density = calculateDensity(graph, isDirected);
}
public double calculateDensity(Graph graph, boolean isGraphDirected) {
double result;
double edgesCount = hgraph.getTotalEdgeCount();
double nodesCount = hgraph.getNodeCount();
double edgesCount = graph.getEdgeCount();
double nodesCount = graph.getNodeCount();
double multiplier = 1;
if (!isDirected) {
if (!isGraphDirected) {
multiplier = 2;
}
density = (multiplier * edgesCount) / (nodesCount * nodesCount - nodesCount);
result = (multiplier * edgesCount) / (nodesCount * nodesCount - nodesCount);
return result;
}
/**
*
* @return
*/
@Override
public String getReport() {
NumberFormat f = new DecimalFormat("#0.000");
@@ -1,44 +1,44 @@
/*
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin;
import java.io.IOException;
@@ -49,12 +49,9 @@ import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map;
import java.util.Stack;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeRow;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Column;
import org.gephi.attribute.api.Table;
import org.gephi.utils.TempDirUtils;
import org.gephi.utils.TempDirUtils.TempDir;
import org.gephi.utils.longtask.spi.LongTask;
@@ -67,10 +64,11 @@ import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
/**
* Ref: Ulrik Brandes, A Faster Algorithm for Betweenness Centrality,
* in Journal of Mathematical Sociology 25(2):163-177, (2001)
* Ref: Ulrik Brandes, A Faster Algorithm for Betweenness Centrality, in Journal
* of Mathematical Sociology 25(2):163-177, (2001)
*
* @author pjmcswee
*/
@@ -79,113 +77,129 @@ public class GraphDistance implements Statistics, LongTask {
public static final String BETWEENNESS = "betweenesscentrality";
public static final String CLOSENESS = "closnesscentrality";
public static final String ECCENTRICITY = "eccentricity";
/** */
/**
* */
private double[] betweenness;
/** */
/**
* */
private double[] closeness;
/** */
/**
* */
private double[] eccentricity;
/** */
/**
* */
private int diameter;
private int radius;
/** */
/**
* */
private double avgDist;
/** */
/**
* */
private int N;
/** */
/**
* */
private boolean isDirected;
/** */
/**
* */
private ProgressTicket progress;
/** */
/**
* */
private boolean isCanceled;
private int shortestPaths;
private boolean isNormalized;
public GraphDistance() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController != null && graphController.getModel() != null) {
isDirected = graphController.getModel().isDirected();
}
}
public double getPathLength() {
return avgDist;
}
/**
*
*
* @return
*/
public double getDiameter() {
return diameter;
}
public double getRadius() {
return radius;
}
public GraphDistance() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController != null && graphController.getGraphModel() != null) {
isDirected = graphController.getGraphModel().isDirected();
}
}
/**
*
* @param graphModel
* @param attributeModel
*/
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
HierarchicalGraph graph = null;
isDirected = graphModel.isDirected();
Graph graph = null;
if (isDirected) {
graph = graphModel.getHierarchicalDirectedGraphVisible();
graph = graphModel.getDirectedGraphVisible();
} else {
graph = graphModel.getHierarchicalUndirectedGraphVisible();
graph = graphModel.getUndirectedGraphVisible();
}
execute(graph, attributeModel);
}
public void execute(HierarchicalGraph hgraph, AttributeModel attributeModel) {
public void execute(Graph hgraph, AttributeModel attributeModel) {
isCanceled = false;
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeColumn eccentricityCol = nodeTable.getColumn(ECCENTRICITY);
AttributeColumn closenessCol = nodeTable.getColumn(CLOSENESS);
AttributeColumn betweenessCol = nodeTable.getColumn(BETWEENNESS);
if (eccentricityCol == null) {
eccentricityCol = nodeTable.addColumn(ECCENTRICITY, "Eccentricity", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, new Double(0));
}
if (closenessCol == null) {
closenessCol = nodeTable.addColumn(CLOSENESS, "Closeness Centrality", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, new Double(0));
}
if (betweenessCol == null) {
betweenessCol = nodeTable.addColumn(BETWEENNESS, "Betweenness Centrality", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, new Double(0));
}
initializeAttributeColunms(attributeModel);
hgraph.readLock();
N = hgraph.getNodeCount();
initializeStartValues();
HashMap<Node, Integer> indicies = createIndiciesMap(hgraph);
betweenness = new double[N];
eccentricity = new double[N];
closeness = new double[N];
diameter = 0;
avgDist = 0;
shortestPaths = 0;
radius = Integer.MAX_VALUE;
HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
int index = 0;
for (Node s : hgraph.getNodes()) {
indicies.put(s, index);
index++;
}
Map<String, double[]> metrics = calculateDistanceMetrics(hgraph, indicies, isDirected, isNormalized);
eccentricity = metrics.get(ECCENTRICITY);
closeness = metrics.get(CLOSENESS);
betweenness = metrics.get(BETWEENNESS);
saveCalculatedValues(hgraph, indicies, eccentricity, betweenness, closeness);
hgraph.readUnlock();
}
public Map<String, double[]> calculateDistanceMetrics(Graph hgraph, HashMap<Node, Integer> indicies, boolean directed, boolean normalized) {
int n = hgraph.getNodeCount();
HashMap<String, double[]> metrics = new HashMap<String, double[]>();
double[] nodeEccentricity = new double[n];
double[] nodeBetweenness = new double[n];
double[] nodeCloseness = new double[n];
metrics.put(ECCENTRICITY, nodeEccentricity);
metrics.put(CLOSENESS, nodeCloseness);
metrics.put(BETWEENNESS, nodeBetweenness);
Progress.start(progress, hgraph.getNodeCount());
int count = 0;
for (Node s : hgraph.getNodes()) {
Stack<Node> S = new Stack<Node>();
LinkedList<Node>[] P = new LinkedList[N];
double[] theta = new double[N];
int[] d = new int[N];
for (int j = 0; j < N; j++) {
P[j] = new LinkedList<Node>();
theta[j] = 0;
d[j] = -1;
}
LinkedList<Node>[] P = new LinkedList[n];
double[] theta = new double[n];
int[] d = new int[n];
int s_index = indicies.get(s);
theta[s_index] = 1;
d[s_index] = 0;
setInitParametetrsForNode(s, P, theta, d, s_index, n);
LinkedList<Node> Q = new LinkedList<Node>();
Q.addLast(s);
@@ -194,12 +208,7 @@ public class GraphDistance implements Statistics, LongTask {
S.push(v);
int v_index = indicies.get(v);
EdgeIterable edgeIter = null;
if (isDirected) {
edgeIter = ((HierarchicalDirectedGraph) hgraph).getOutEdgesAndMetaOutEdges(v);
} else {
edgeIter = hgraph.getEdgesAndMetaEdges(v);
}
EdgeIterable edgeIter = getEdgeIter(hgraph, v, directed);
for (Edge edge : edgeIter) {
Node reachable = hgraph.getOpposite(v, edge);
@@ -216,25 +225,25 @@ public class GraphDistance implements Statistics, LongTask {
}
}
double reachable = 0;
for (int i = 0; i < N; i++) {
for (int i = 0; i < n; i++) {
if (d[i] > 0) {
avgDist += d[i];
eccentricity[s_index] = (int) Math.max(eccentricity[s_index], d[i]);
closeness[s_index] += d[i];
nodeEccentricity[s_index] = (int) Math.max(nodeEccentricity[s_index], d[i]);
nodeCloseness[s_index] += d[i];
diameter = Math.max(diameter, d[i]);
reachable++;
}
}
radius = (int) Math.min(eccentricity[s_index], radius);
radius = (int) Math.min(nodeEccentricity[s_index], radius);
if (reachable != 0) {
closeness[s_index] /= reachable;
nodeCloseness[s_index] /= reachable;
}
shortestPaths += reachable;
double[] delta = new double[N];
double[] delta = new double[n];
while (!S.empty()) {
Node w = S.pop();
int w_index = indicies.get(w);
@@ -245,35 +254,105 @@ public class GraphDistance implements Statistics, LongTask {
delta[u_index] += (theta[u_index] / theta[w_index]) * (1 + delta[w_index]);
}
if (w != s) {
betweenness[w_index] += delta[w_index];
nodeBetweenness[w_index] += delta[w_index];
}
}
count++;
if (isCanceled) {
hgraph.readUnlockAll();
return;
return metrics;
}
Progress.progress(progress, count);
}
avgDist /= shortestPaths;//mN * (mN - 1.0f);
calculateCorrection(hgraph, indicies, nodeBetweenness, nodeCloseness, directed, normalized);
return metrics;
}
private void setInitParametetrsForNode(Node s, LinkedList<Node>[] P, double[] theta, int[] d, int index, int n) {
for (int j = 0; j < n; j++) {
P[j] = new LinkedList<Node>();
theta[j] = 0;
d[j] = -1;
}
theta[index] = 1;
d[index] = 0;
}
private EdgeIterable getEdgeIter(Graph hgraph, Node v, boolean directed) {
EdgeIterable edgeIter = null;
if (directed) {
edgeIter = ((DirectedGraph) hgraph).getOutEdges(v);
} else {
edgeIter = hgraph.getEdges(v);
}
return edgeIter;
}
private void initializeAttributeColunms(AttributeModel attributeModel) {
Table nodeTable = attributeModel.getNodeTable();
if (!nodeTable.hasColumn(ECCENTRICITY)) {
nodeTable.addColumn(ECCENTRICITY, "Eccentricity", Double.class, new Double(0));
}
if (!nodeTable.hasColumn(CLOSENESS)) {
nodeTable.addColumn(CLOSENESS, "Closeness Centrality", Double.class, new Double(0));
}
if (!nodeTable.hasColumn(BETWEENNESS)) {
nodeTable.addColumn(BETWEENNESS, "Betweenness Centrality", Double.class, new Double(0));
}
}
public HashMap<Node, Integer> createIndiciesMap(Graph hgraph) {
HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
int index = 0;
for (Node s : hgraph.getNodes()) {
indicies.put(s, index);
index++;
}
return indicies;
}
public void initializeStartValues() {
betweenness = new double[N];
eccentricity = new double[N];
closeness = new double[N];
diameter = 0;
avgDist = 0;
shortestPaths = 0;
radius = Integer.MAX_VALUE;
}
private void calculateCorrection(Graph hgraph, HashMap<Node, Integer> indicies,
double[] nodeBetweenness, double[] nodeCloseness, boolean directed, boolean normalized) {
int n = hgraph.getNodeCount();
for (Node s : hgraph.getNodes()) {
int s_index = indicies.get(s);
if (!directed) {
nodeBetweenness[s_index] /= 2;
}
if (normalized) {
nodeCloseness[s_index] = (nodeCloseness[s_index] == 0) ? 0 : 1.0 / nodeCloseness[s_index];
nodeBetweenness[s_index] /= directed ? (n - 1) * (n - 2) : (n - 1) * (n - 2) / 2;
}
}
}
private void saveCalculatedValues(Graph hgraph, HashMap<Node, Integer> indicies,
double[] nodeEccentricity, double[] nodeBetweenness, double[] nodeCloseness) {
for (Node s : hgraph.getNodes()) {
AttributeRow row = (AttributeRow) s.getNodeData().getAttributes();
int s_index = indicies.get(s);
if (!isDirected) {
betweenness[s_index] /= 2;
}
if (isNormalized) {
closeness[s_index] = (closeness[s_index] == 0) ? 0 : 1.0 / closeness[s_index];
betweenness[s_index] /= isDirected ? (N - 1) * (N - 2) : (N - 1) * (N - 2) / 2;
}
row.setValue(eccentricityCol, eccentricity[s_index]);
row.setValue(closenessCol, closeness[s_index]);
row.setValue(betweenessCol, betweenness[s_index]);
s.setAttribute(ECCENTRICITY, nodeEccentricity[s_index]);
s.setAttribute(CLOSENESS, nodeCloseness[s_index]);
s.setAttribute(BETWEENNESS, nodeBetweenness[s_index]);
}
hgraph.readUnlock();
}
public void setNormalized(boolean isNormalized) {
@@ -330,6 +409,7 @@ public class GraphDistance implements Statistics, LongTask {
*
* @return
*/
@Override
public String getReport() {
String htmlIMG1 = "";
String htmlIMG2 = "";
@@ -364,9 +444,10 @@ public class GraphDistance implements Statistics, LongTask {
}
/**
*
*
* @return
*/
@Override
public boolean cancel() {
this.isCanceled = true;
return true;
@@ -376,6 +457,7 @@ public class GraphDistance implements Statistics, LongTask {
*
* @param progressTicket
*/
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progress = progressTicket;
}
@@ -1,63 +1,60 @@
/*
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeRow;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Column;
import org.gephi.attribute.api.Table;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.EdgeIterable;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.HierarchicalDirectedGraph;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.HierarchicalUndirectedGraph;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.NodeIterable;
import org.gephi.statistics.spi.Statistics;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.Progress;
@@ -70,8 +67,8 @@ import org.jfree.data.xy.XYSeriesCollection;
import org.openide.util.Lookup;
/**
* Ref: Jon M. Kleinberg, Authoritative Sources in a Hyperlinked Environment,
* in Journal of the ACM 46 (5): 604–632 (1999)
* Ref: Jon M. Kleinberg, Authoritative Sources in a Hyperlinked Environment, in
* Journal of the ACM 46 (5): 604–632 (1999)
*
* @author pjmcswee
*/
@@ -85,14 +82,11 @@ public class Hits implements Statistics, LongTask {
private double[] hubs;
private boolean useUndirected;
private double epsilon = 0.0001;
private LinkedList<Node> hub_list;
private LinkedList<Node> auth_list;
private HashMap<Node, Integer> indicies;
public Hits() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController != null && graphController.getModel() != null) {
useUndirected = graphController.getModel().isUndirected();
if (graphController != null && graphController.getGraphModel() != null) {
useUndirected = graphController.getGraphModel().isUndirected();
}
}
@@ -101,173 +95,194 @@ public class Hits implements Statistics, LongTask {
}
/**
*
*
* @return
*/
public boolean getUndirected() {
return useUndirected;
}
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
HierarchicalGraph graph = null;
Graph graph = null;
if (useUndirected) {
graph = graphModel.getHierarchicalUndirectedGraphVisible();
graph = graphModel.getUndirectedGraphVisible();
} else {
graph = graphModel.getHierarchicalDirectedGraphVisible();
graph = graphModel.getDirectedGraphVisible();
}
execute(graph, attributeModel);
}
public void execute(HierarchicalGraph hgraph, AttributeModel attributeModel) {
public void execute(Graph hgraph, AttributeModel attributeModel) {
initializeAttributeColunms(attributeModel);
hgraph.readLock();
int N = hgraph.getNodeCount();
authority = new double[N];
hubs = new double[N];
Map<Node, Integer> indicies = createIndiciesMap(hgraph);
calculateHits(hgraph, hubs, authority, indicies, !useUndirected, epsilon);
saveCalculatedValues(hgraph, authority, hubs);
hgraph.readUnlockAll();
}
public void calculateHits(Graph hgraph, double[] hubValues, double[] authorityValues, Map<Node, Integer> indicies, boolean isDirected, double eps) {
int N = hgraph.getNodeCount();
double[] temp_authority = new double[N];
double[] temp_hubs = new double[N];
hub_list = new LinkedList<Node>();
auth_list = new LinkedList<Node>();
initializeStartValues(hubValues, authorityValues);
Progress.start(progress);
indicies = new HashMap<Node, Integer>();
int index = 0;
for (Node node : hgraph.getNodes()) {
indicies.put(node, new Integer(index));
index++;
if (!useUndirected) {
if (((HierarchicalDirectedGraph) hgraph).getTotalOutDegree(node) > 0) {
hub_list.add(node);
}
if (((HierarchicalDirectedGraph) hgraph).getTotalInDegree(node) > 0) {
auth_list.add(node);
}
} else {
if (((HierarchicalUndirectedGraph) hgraph).getTotalDegree(node) > 0) {
hub_list.add(node);
auth_list.add(node);
}
}
}
for (Node node : hub_list) {
int n_index = indicies.get(node);
hubs[n_index] = 1.0f;
}
for (Node node : auth_list) {
int n_index = indicies.get(node);
authority[n_index] = 1.0f;
}
while (true) {
boolean done = true;
double auth_sum = 0;
for (Node node : auth_list) {
int n_index = indicies.get(node);
temp_authority[n_index] = authority[n_index];
EdgeIterable edge_iter;
if (!useUndirected) {
edge_iter = ((HierarchicalDirectedGraph) hgraph).getInEdgesAndMetaInEdges(node);
} else {
edge_iter = ((HierarchicalUndirectedGraph) hgraph).getEdgesAndMetaEdges(node);
}
for (Edge edge : edge_iter) {
Node target = hgraph.getOpposite(node, edge);
int target_index = indicies.get(target);
temp_authority[n_index] += hubs[target_index];
}
updateAutorithy(hgraph, temp_authority, hubValues, isDirected, indicies);
updateHub(hgraph, temp_hubs, temp_authority, isDirected, indicies);
auth_sum += temp_authority[n_index];
if (isCanceled) {
break;
}
done = checkDiff(authorityValues, temp_authority, eps) && checkDiff(hubValues, temp_hubs, eps);
}
System.arraycopy(temp_authority, 0, authorityValues, 0, N);
System.arraycopy(temp_hubs, 0, hubValues, 0, N);
double hub_sum = 0;
for (Node node : hub_list) {
int n_index = indicies.get(node);
temp_hubs[n_index] = hubs[n_index];
EdgeIterable edge_iter;
if (!useUndirected) {
edge_iter = ((HierarchicalDirectedGraph) hgraph).getInEdgesAndMetaInEdges(node);
} else {
edge_iter = ((HierarchicalUndirectedGraph) hgraph).getEdgesAndMetaEdges(node);
}
for (Edge edge : edge_iter) {
Node target = hgraph.getOpposite(node, edge);
int target_index = indicies.get(target);
temp_hubs[n_index] += authority[target_index];
}
hub_sum += temp_hubs[n_index];
if (isCanceled) {
break;
}
}
for (Node node : auth_list) {
int n_index = indicies.get(node);
temp_authority[n_index] /= auth_sum;
if (((temp_authority[n_index] - authority[n_index]) / authority[n_index]) >= epsilon) {
done = false;
}
}
for (Node node : hub_list) {
int n_index = indicies.get(node);
temp_hubs[n_index] /= hub_sum;
if (((temp_hubs[n_index] - hubs[n_index]) / hubs[n_index]) >= epsilon) {
done = false;
}
}
authority = temp_authority;
hubs = temp_hubs;
temp_authority = new double[N];
temp_hubs = new double[N];
// temp_authority = new double[N];
// temp_hubs = new double[N]
if ((done) || (isCanceled)) {
break;
}
}
}
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeColumn authorityCol = nodeTable.getColumn(AUTHORITY);
AttributeColumn hubsCol = nodeTable.getColumn(HUB);
if (authorityCol == null) {
authorityCol = nodeTable.addColumn(AUTHORITY, "Authority", AttributeType.FLOAT, AttributeOrigin.COMPUTED, new Float(0));
}
if (hubsCol == null) {
hubsCol = nodeTable.addColumn(HUB, "Hub", AttributeType.FLOAT, AttributeOrigin.COMPUTED, new Float(0));
}
private void initializeAttributeColunms(AttributeModel attributeModel) {
Table nodeTable = attributeModel.getNodeTable();
if (!nodeTable.hasColumn(AUTHORITY)) {
nodeTable.addColumn(AUTHORITY, "Authority", Float.class, new Float(0));
}
if (!nodeTable.hasColumn(HUB)) {
nodeTable.addColumn(HUB, "Hub", Float.class, new Float(0));
}
}
private void initializeStartValues(double[] hubValues, double[] authorityValues) {
for (int i = 0; i < authorityValues.length; i++) {
authorityValues[i] = 1.0;
hubValues[i] = 1.0;
}
}
void updateAutorithy(Graph hgraph, double[] newValues, double[] hubValues, boolean isDirected, Map<Node, Integer> indicies) {
double norm = 0;
int j = 0;
for (Node node : hgraph.getNodes()) {
double auth = 0;
EdgeIterable edge_iter;
if (isDirected) {
edge_iter = ((DirectedGraph) hgraph).getInEdges(node);
} else {
edge_iter = hgraph.getEdges(node);
}
for (Edge edge : edge_iter) {
Node target = hgraph.getOpposite(node, edge);
auth += hubValues[indicies.get(target)];
}
if (auth > 0) {
newValues[j] = auth;
}
norm += newValues[j++];
if (isCanceled) {
return;
}
}
// norm = Math.sqrt(norm);
if (norm > 0) {
for (int i = 0; i < newValues.length; i++) {
newValues[i] = newValues[i] / norm;
}
}
}
void updateHub(Graph hgraph, double[] newValues, double[] authValues, boolean isDirected, Map<Node, Integer> indicies) {
double norm = 0;
int j = 0;
for (Node node : hgraph.getNodes()) {
double hub = 0;
EdgeIterable edge_iter;
if (isDirected) {
edge_iter = ((DirectedGraph) hgraph).getOutEdges(node);
} else {
edge_iter = hgraph.getEdges(node);
}
for (Edge edge : edge_iter) {
Node target = hgraph.getOpposite(node, edge);
hub += authValues[indicies.get(target)];
}
if(hub > 0) {
newValues[j] = hub;
}
norm += newValues[j++];
if (isCanceled) {
return;
}
}
if (norm > 0) {
for (int i = 0; i < newValues.length; i++) {
newValues[i] = newValues[i] / norm;
}
}
}
private boolean checkDiff(double[] oldValues, double[] newValues, double epsilon) {
for (int i = 0; i < oldValues.length; i++) {
if (oldValues[i] > 0 && ((newValues[i] - oldValues[i]) / oldValues[i]) >= epsilon) {
return false;
}
}
return true;
}
private void saveCalculatedValues(Graph hgraph, double[] nodeAuthority, double[] nodeHubs) {
int i = 0;
for (Node s : hgraph.getNodes()) {
int s_index = indicies.get(s);
AttributeRow row = (AttributeRow) s.getNodeData().getAttributes();
row.setValue(authorityCol, (float) authority[s_index]);
row.setValue(hubsCol, (float) hubs[s_index]);
}
int s_index = i++;
hgraph.readUnlockAll();
s.setAttribute(AUTHORITY, (float) nodeAuthority[s_index]);
s.setAttribute(HUB, (float) nodeHubs[s_index]);
}
}
public HashMap<Node, Integer> createIndiciesMap(Graph hgraph) {
HashMap<Node, Integer> newIndicies = new HashMap<Node, Integer>();
int index = 0;
for (Node s : hgraph.getNodes()) {
newIndicies.put(s, index);
index++;
}
return newIndicies;
}
/**
*
* @return
*/
@Override
public String getReport() {
//distribution of hub values
Map<Double, Integer> distHubs = new HashMap<Double, Integer>();
for (Node node : hub_list) {
int n_index = indicies.get(node);
Double d = hubs[n_index];
for (int i = 0; i < hubs.length; i++) {
Double d = hubs[i];
if (distHubs.containsKey(d)) {
Integer v = distHubs.get(d);
distHubs.put(d, v + 1);
@@ -278,9 +293,8 @@ public class Hits implements Statistics, LongTask {
//distribution of authority values
Map<Double, Integer> distAuthorities = new HashMap<Double, Integer>();
for (Node node : auth_list) {
int n_index = indicies.get(node);
Double d = authority[n_index];
for (int i = 0; i < authority.length; i++) {
Double d = authority[i];
if (distAuthorities.containsKey(d)) {
Integer v = distAuthorities.get(d);
distAuthorities.put(d, v + 1);
@@ -329,7 +343,6 @@ public class Hits implements Statistics, LongTask {
ChartUtils.scaleChart(chart2, dAuthsSeries, true);
String imageFile2 = ChartUtils.renderChart(chart2, "authorities.png");
String report = "<HTML> <BODY> <h1> HITS Metric Report </h1>"
+ "<hr>"
+ "<br />"
@@ -347,6 +360,7 @@ public class Hits implements Statistics, LongTask {
*
* @return
*/
@Override
public boolean cancel() {
isCanceled = true;
return true;
@@ -356,6 +370,7 @@ public class Hits implements Statistics, LongTask {
*
* @param progressTicket
*/
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
progress = progressTicket;
}
@@ -1,52 +1,54 @@
/*
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s): Thomas Aynaud <taynaud@gmail.com>
Contributor(s): Thomas Aynaud <taynaud@gmail.com>
Portions Copyrighted 2011 Gephi Consortium.
*/
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;
import org.gephi.data.attributes.api.*;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Column;
import org.gephi.attribute.api.Table;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.HierarchicalUndirectedGraph;
import org.gephi.graph.api.Node;
import org.gephi.statistics.spi.Statistics;
import org.gephi.utils.longtask.spi.LongTask;
@@ -73,7 +75,7 @@ public class Modularity implements Statistics, LongTask {
private boolean isRandomized = false;
private boolean useWeight = true;
private double resolution = 1.;
public void setRandom(boolean isRandomized) {
this.isRandomized = isRandomized;
}
@@ -81,15 +83,15 @@ public class Modularity implements Statistics, LongTask {
public boolean getRandom() {
return isRandomized;
}
public void setUseWeight(boolean useWeight) {
public void setUseWeight(boolean useWeight) {
this.useWeight = useWeight;
}
public boolean getUseWeight() {
return useWeight;
}
public void setResolution(double resolution) {
this.resolution = resolution;
}
@@ -98,11 +100,13 @@ public class Modularity implements Statistics, LongTask {
return resolution;
}
@Override
public boolean cancel() {
this.isCanceled = true;
return true;
}
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progress = progressTicket;
}
@@ -126,7 +130,7 @@ public class Modularity implements Statistics, LongTask {
HashMap<Modularity.Community, Integer>[] nodeConnectionsCount;
HashMap<Node, Integer> map;
Community[] nodeCommunities;
HierarchicalUndirectedGraph graph;
Graph graph;
double[] weights;
double graphWeightSum;
LinkedList<ModEdge>[] topology;
@@ -134,7 +138,7 @@ public class Modularity implements Statistics, LongTask {
int N;
HashMap<Integer, Community> invMap;
CommunityStructure(HierarchicalUndirectedGraph hgraph) {
CommunityStructure(Graph hgraph) {
this.graph = hgraph;
N = hgraph.getNodeCount();
invMap = new HashMap<Integer, Community>();
@@ -156,12 +160,12 @@ public class Modularity implements Statistics, LongTask {
Community hidden = new Community(structure);
hidden.nodes.add(index);
invMap.put(index, hidden);
communities.add(nodeCommunities[index]);
communities.add(nodeCommunities[index]);
index++;
if (isCanceled) {
return;
}
}
}
for (Node node : hgraph.getNodes()) {
int node_index = map.get(node);
@@ -173,10 +177,10 @@ public class Modularity implements Statistics, LongTask {
}
int neighbor_index = map.get(neighbor);
float weight = 1;
if(useWeight) {
weight = hgraph.getEdge(node, neighbor).getWeight();
}
if (useWeight) {
weight = (float) hgraph.getEdge(node, neighbor).getWeight();
}
weights[node_index] += weight;
Modularity.ModEdge me = new ModEdge(node_index, neighbor_index, weight);
topology[node_index].add(me);
@@ -221,9 +225,6 @@ public class Modularity implements Statistics, LongTask {
nodeConnectionsCount[neighbor].put(to, neighCountEdgesTo + 1);
}
///////////////////
Modularity.Community adjCom = nodeCommunities[neighbor];
Float wEdgesto = adjCom.connectionsWeight.get(to);
@@ -232,7 +233,7 @@ public class Modularity implements Statistics, LongTask {
} else {
adjCom.connectionsWeight.put(to, wEdgesto + e.weight);
}
Integer cEdgesto = adjCom.connectionsCount.get(to);
if (cEdgesto == null) {
adjCom.connectionsCount.put(to, 1);
@@ -246,7 +247,7 @@ public class Modularity implements Statistics, LongTask {
} else {
nodeConnectionsWeight[node].put(adjCom, nodeEdgesTo + e.weight);
}
Integer nodeCountEdgesTo = nodeConnectionsCount[node].get(adjCom);
if (nodeCountEdgesTo == null) {
nodeConnectionsCount[node].put(adjCom, 1);
@@ -261,21 +262,20 @@ public class Modularity implements Statistics, LongTask {
} else {
to.connectionsWeight.put(adjCom, comEdgesto + e.weight);
}
Integer comCountEdgesto = to.connectionsCount.get(adjCom);
if (comCountEdgesto == null) {
to.connectionsCount.put(adjCom, 1);
} else {
to.connectionsCount.put(adjCom, comCountEdgesto + 1);
}
}
}
}
private void removeNodeFrom(int node, Community from) {
Community community = nodeCommunities[node];
for (ModEdge e : topology[node]) {
int neighbor = e.target;
@@ -304,9 +304,7 @@ public class Modularity implements Statistics, LongTask {
adjCom.connectionsWeight.put(community, oEdgesto - e.weight);
adjCom.connectionsCount.put(community, oCountEdgesto - 1);
}
if (node == neighbor) {
continue;
}
@@ -333,7 +331,6 @@ public class Modularity implements Statistics, LongTask {
nodeConnectionsCount[node].put(adjCom, nodeCountEgesTo - 1);
}
}
from.remove(new Integer(node));
}
@@ -367,13 +364,14 @@ public class Modularity implements Statistics, LongTask {
hidden.nodes.addAll(oldHidden.nodes);
}
newInvMap.put(index, hidden);
for(Modularity.Community adjCom : iter) {
for (Modularity.Community adjCom : iter) {
int target = communities.indexOf(adjCom);
float weight = com.connectionsWeight.get(adjCom);
if(target == index)
weightSum += 2.*weight;
else
if (target == index) {
weightSum += 2. * weight;
} else {
weightSum += weight;
}
ModEdge e = new ModEdge(index, target, weight);
newTopology[index].add(e);
}
@@ -403,6 +401,7 @@ public class Modularity implements Statistics, LongTask {
}
class Community {
double weightSum;
CommunityStructure structure;
LinkedList<Integer> nodes;
@@ -449,22 +448,44 @@ public class Modularity implements Statistics, LongTask {
}
}
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
HierarchicalUndirectedGraph hgraph = graphModel.getHierarchicalUndirectedGraphVisible();
Graph hgraph = graphModel.getUndirectedGraphVisible();
execute(hgraph, attributeModel);
}
public void execute(HierarchicalUndirectedGraph hgraph, AttributeModel attributeModel) {
public void execute(Graph hgraph, AttributeModel attributeModel) {
isCanceled = false;
hgraph.readLock();
structure = new Modularity.CommunityStructure(hgraph);
int[] comStructure = new int[hgraph.getNodeCount()];
HashMap<String, Double> computedModularityMetrics = computeModularity(hgraph, structure, comStructure, resolution, isRandomized, useWeight);
modularity = computedModularityMetrics.get("modularity");
modularityResolution = computedModularityMetrics.get("modularityResolution");
saveValues(comStructure, hgraph, attributeModel, structure);
hgraph.readUnlock();
}
protected HashMap<String, Double> computeModularity(Graph hgraph, CommunityStructure theStructure, int[] comStructure,
double currentResolution, boolean randomized, boolean weighted) {
isCanceled = false;
Progress.start(progress);
Random rand = new Random();
hgraph.readLock();
structure = new Modularity.CommunityStructure(hgraph);
double totalWeight = structure.graphWeightSum;
double[] nodeDegrees = structure.weights.clone();
double totalWeight = theStructure.graphWeightSum;
double[] nodeDegrees = theStructure.weights.clone();
HashMap<String, Double> results = new HashMap<String, Double>();
if (isCanceled) {
hgraph.readUnlockAll();
return;
return results;
}
boolean someChange = true;
while (someChange) {
@@ -473,92 +494,105 @@ public class Modularity implements Statistics, LongTask {
while (localChange) {
localChange = false;
int start = 0;
if (isRandomized) {
start = Math.abs(rand.nextInt()) % structure.N;
if (randomized) {
start = Math.abs(rand.nextInt()) % theStructure.N;
}
int step = 0;
for (int i = start; step < structure.N; i = (i + 1) % structure.N) {
for (int i = start; step < theStructure.N; i = (i + 1) % theStructure.N) {
step++;
double best = 0.;
Community bestCommunity = null;
Community nodecom = structure.nodeCommunities[i];
Set<Community> iter = structure.nodeConnectionsWeight[i].keySet();
for(Community com : iter) {
double qValue = q(i, com);
if (qValue > best) {
best = qValue;
bestCommunity = com;
}
}
if ((structure.nodeCommunities[i] != bestCommunity) && (bestCommunity != null)) {
structure.moveNodeTo(i, bestCommunity);
Community bestCommunity = updateBestCommunity(theStructure, i, currentResolution);
if ((theStructure.nodeCommunities[i] != bestCommunity) && (bestCommunity != null)) {
theStructure.moveNodeTo(i, bestCommunity);
localChange = true;
}
if (isCanceled) {
hgraph.readUnlockAll();
return;
return results;
}
}
someChange = localChange || someChange;
if (isCanceled) {
hgraph.readUnlockAll();
return;
return results;
}
}
if (someChange) {
structure.zoomOut();
theStructure.zoomOut();
}
}
int[] comStructure = new int[hgraph.getNodeCount()];
fillComStructure(hgraph, theStructure, comStructure);
double[] degreeCount = fillDegreeCount(hgraph, theStructure, comStructure, nodeDegrees, weighted);
double computedModularity = finalQ(comStructure, degreeCount, hgraph, theStructure, totalWeight, 1., weighted);
double computedModularityResolution = finalQ(comStructure, degreeCount, hgraph, theStructure, totalWeight, currentResolution, weighted);
results.put("modularity", computedModularity);
results.put("modularityResolution", computedModularityResolution);
return results;
}
Community updateBestCommunity(CommunityStructure theStructure, int i, double currentResolution) {
double best = 0.;
Community bestCommunity = null;
Set<Community> iter = theStructure.nodeConnectionsWeight[i].keySet();
for (Community com : iter) {
double qValue = q(i, com, theStructure, currentResolution);
if (qValue > best) {
best = qValue;
bestCommunity = com;
}
}
return bestCommunity;
}
int[] fillComStructure(Graph hgraph, CommunityStructure theStructure, int[] comStructure) {
// int[] comStructure = new int[hgraph.getNodeCount()];
int count = 0;
double[] degreeCount = new double[structure.communities.size()];
for (Community com : structure.communities) {
for (Community com : theStructure.communities) {
for (Integer node : com.nodes) {
Community hidden = structure.invMap.get(node);
Community hidden = theStructure.invMap.get(node);
for (Integer nodeInt : hidden.nodes) {
comStructure[nodeInt] = count;
}
}
count++;
}
for (Node node : hgraph.getNodes()) {
int index = structure.map.get(node);
if(useWeight) {
degreeCount[comStructure[index]] += nodeDegrees[index];
} else {
degreeCount[comStructure[index]] += hgraph.getTotalDegree(node);
}
}
modularity = finalQ(comStructure, degreeCount, hgraph, attributeModel, totalWeight, 1.);
modularityResolution = finalQ(comStructure, degreeCount, hgraph, attributeModel, totalWeight, resolution);
hgraph.readUnlock();
return comStructure;
}
private double finalQ(int[] struct, double[] degrees, HierarchicalUndirectedGraph hgraph, AttributeModel attributeModel, double totalWeight, double usedResolution) {
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeColumn modCol = nodeTable.getColumn(MODULARITY_CLASS);
if (modCol == null) {
modCol = nodeTable.addColumn(MODULARITY_CLASS, "Modularity Class", AttributeType.INT, AttributeOrigin.COMPUTED, new Integer(0));
double[] fillDegreeCount(Graph hgraph, CommunityStructure theStructure, int[] comStructure, double[] nodeDegrees, boolean weighted) {
double[] degreeCount = new double[theStructure.communities.size()];
for (Node node : hgraph.getNodes()) {
int index = theStructure.map.get(node);
if (weighted) {
degreeCount[comStructure[index]] += nodeDegrees[index];
} else {
degreeCount[comStructure[index]] += hgraph.getDegree(node);
}
}
return degreeCount;
}
private double finalQ(int[] struct, double[] degrees, Graph hgraph,
CommunityStructure theStructure, double totalWeight, double usedResolution, boolean weighted) {
double res = 0;
double[] internal = new double[degrees.length];
for (Node n : hgraph.getNodes()) {
int n_index = structure.map.get(n);
AttributeRow row = (AttributeRow) n.getNodeData().getAttributes();
row.setValue(modCol, struct[n_index]);
int n_index = theStructure.map.get(n);
for (Node neighbor : hgraph.getNeighbors(n)) {
if (n == neighbor) {
continue;
}
int neigh_index = structure.map.get(neighbor);
int neigh_index = theStructure.map.get(neighbor);
if (struct[neigh_index] == struct[n_index]) {
if(useWeight) {
if (weighted) {
internal[struct[neigh_index]] += hgraph.getEdge(n, neighbor).getWeight();
} else {
internal[struct[neigh_index]]++;
@@ -573,21 +607,34 @@ public class Modularity implements Statistics, LongTask {
return res;
}
private void saveValues(int[] struct, Graph hgraph, AttributeModel attributeModel, CommunityStructure theStructure) {
Table nodeTable = attributeModel.getNodeTable();
Column modCol = nodeTable.getColumn(MODULARITY_CLASS);
if (modCol == null) {
modCol = nodeTable.addColumn(MODULARITY_CLASS, "Modularity Class", Integer.class, new Integer(0));
}
for (Node n : hgraph.getNodes()) {
int n_index = theStructure.map.get(n);;
n.setAttribute(modCol, struct[n_index]);
}
}
public double getModularity() {
return modularity;
}
@Override
public String getReport() {
//Distribution series
Map<Integer, Integer> sizeDist = new HashMap<Integer, Integer>();
for(Node n : structure.graph.getNodes()) {
Integer v = (Integer) n.getNodeData().getAttributes().getValue(MODULARITY_CLASS);
if(!sizeDist.containsKey(v)) {
for (Node n : structure.graph.getNodes()) {
Integer v = (Integer) n.getAttribute(MODULARITY_CLASS);
if (!sizeDist.containsKey(v)) {
sizeDist.put(v, 0);
}
sizeDist.put(v, sizeDist.get(v) + 1);
}
XYSeries dSeries = ChartUtils.createXYSeries(sizeDist, "Size Distribution");
XYSeriesCollection dataset1 = new XYSeriesCollection();
@@ -607,20 +654,19 @@ public class Modularity implements Statistics, LongTask {
ChartUtils.scaleChart(chart, dSeries, false);
String imageFile = ChartUtils.renderChart(chart, "communities-size-distribution.png");
NumberFormat f = new DecimalFormat("#0.000");
String report = "<HTML> <BODY> <h1>Modularity Report </h1> "
+ "<hr>"
+ "<h2> Parameters: </h2>"
+ "Randomize: " + (isRandomized ? "On" : "Off") + "<br>"
+ "Use edge weights: " + (useWeight ? "On" : "Off") + "<br>"
+ "Resolution: " + (resolution) + "<br>"
+ "Use edge weights: " + (useWeight ? "On" : "Off") + "<br>"
+ "Resolution: " + (resolution) + "<br>"
+ "<br> <h2> Results: </h2>"
+ "Modularity: " + f.format(modularity) + "<br>"
+ "Modularity with resolution: " + f.format(modularityResolution) + "<br>"
+ "Number of Communities: " + structure.communities.size()
+ "<br /><br />"+imageFile
+ "<br /><br />" + imageFile
+ "<br /><br />" + "<h2> Algorithm: </h2>"
+ "Vincent D Blondel, Jean-Loup Guillaume, Renaud Lambiotte, Etienne Lefebvre, <i>Fast unfolding of communities in large networks</i>, in Journal of Statistical Mechanics: Theory and Experiment 2008 (10), P1000<br />"
+ "<br /><br />" + "<h2> Resolution: </h2>"
@@ -630,19 +676,19 @@ public class Modularity implements Statistics, LongTask {
return report;
}
private double q(int node, Community community) {
Float edgesToFloat = structure.nodeConnectionsWeight[node].get(community);
private double q(int node, Community community, CommunityStructure theStructure, double currentResolution) {
Float edgesToFloat = theStructure.nodeConnectionsWeight[node].get(community);
double edgesTo = 0;
if (edgesToFloat != null) {
edgesTo = edgesToFloat.doubleValue();
}
double weightSum = community.weightSum;
double nodeWeight = structure.weights[node];
double qValue = resolution * edgesTo - (nodeWeight * weightSum) / (2.0 * structure.graphWeightSum);
if ((structure.nodeCommunities[node] == community) && (structure.nodeCommunities[node].size() > 1)) {
qValue = resolution * edgesTo - (nodeWeight * (weightSum - nodeWeight)) / (2.0 * structure.graphWeightSum);
double nodeWeight = theStructure.weights[node];
double qValue = currentResolution * edgesTo - (nodeWeight * weightSum) / (2.0 * theStructure.graphWeightSum);
if ((theStructure.nodeCommunities[node] == community) && (theStructure.nodeCommunities[node].size() > 1)) {
qValue = currentResolution * edgesTo - (nodeWeight * (weightSum - nodeWeight)) / (2.0 * theStructure.graphWeightSum);
}
if ((structure.nodeCommunities[node] == community) && (structure.nodeCommunities[node].size() == 1)) {
if ((theStructure.nodeCommunities[node] == community) && (theStructure.nodeCommunities[node].size() == 1)) {
qValue = 0.;
}
return qValue;
@@ -1,62 +1,59 @@
/*
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
Copyright 2008-2011 Gephi
Authors : Patick J. McSweeney <pjmcswee@syr.edu>, Sebastien Heymann <seb@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin;
import java.util.HashMap;
import java.util.Map;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeRow;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Column;
import org.gephi.attribute.api.Table;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.EdgeIterable;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.HierarchicalDirectedGraph;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.HierarchicalUndirectedGraph;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.UndirectedGraph;
import org.gephi.statistics.spi.Statistics;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.Progress;
@@ -69,32 +66,45 @@ import org.jfree.data.xy.XYSeriesCollection;
import org.openide.util.Lookup;
/**
* Ref: Sergey Brin, Lawrence Page, The Anatomy of a Large-Scale Hypertextual Web Search Engine,
* in Proceedings of the seventh International Conference on the World Wide Web (WWW1998):107-117
* Ref: Sergey Brin, Lawrence Page, The Anatomy of a Large-Scale Hypertextual
* Web Search Engine, in Proceedings of the seventh International Conference on
* the World Wide Web (WWW1998):107-117
*
* @author pjmcswee
*/
public class PageRank implements Statistics, LongTask {
public static final String PAGERANK = "pageranks";
/** */
/**
*
*/
private ProgressTicket progress;
/** */
/**
*
*/
private boolean isCanceled;
/** */
/**
*
*/
private double epsilon = 0.001;
/** */
/**
*
*/
private double probability = 0.85;
private boolean useEdgeWeight = false;
/** */
/**
*
*/
private double[] pageranks;
/** */
/**
*
*/
private boolean isDirected;
public PageRank() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController != null && graphController.getModel() != null) {
isDirected = graphController.getModel().isDirected();
if (graphController != null && graphController.getGraphModel() != null) {
isDirected = graphController.getGraphModel().isDirected();
}
}
@@ -110,43 +120,65 @@ public class PageRank implements Statistics, LongTask {
return isDirected;
}
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
HierarchicalGraph graph;
Graph graph;
if (isDirected) {
graph = graphModel.getHierarchicalDirectedGraphVisible();
graph = graphModel.getDirectedGraphVisible();
} else {
graph = graphModel.getHierarchicalUndirectedGraphVisible();
graph = graphModel.getUndirectedGraphVisible();
}
execute(graph, attributeModel);
}
public void execute(HierarchicalGraph hgraph, AttributeModel attributeModel) {
public void execute(Graph hgraph, AttributeModel attributeModel) {
isCanceled = false;
Column column = initializeAttributeColunms(attributeModel);
hgraph.readLock();
int N = hgraph.getNodeCount();
pageranks = new double[N];
double[] temp = new double[N];
HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
int index = 0;
HashMap<Node, Integer> indicies = createIndiciesMap(hgraph);
Progress.start(progress);
double[] weights = null;
if (useEdgeWeight) {
weights = new double[N];
pageranks = calculatePagerank(hgraph, indicies, isDirected, useEdgeWeight, epsilon, probability);
saveCalculatedValues(hgraph, column, indicies, pageranks);
hgraph.readUnlockAll();
}
private Column initializeAttributeColunms(AttributeModel attributeModel) {
Table nodeTable = attributeModel.getNodeTable();
Column pagerankCol = nodeTable.getColumn(PAGERANK);
if (pagerankCol == null) {
pagerankCol = nodeTable.addColumn(PAGERANK, "PageRank", Double.class, new Double(0));
}
return pagerankCol;
}
private void saveCalculatedValues(Graph hgraph, Column attributeColumn, HashMap<Node, Integer> indicies,
double[] nodePagrank) {
for (Node s : hgraph.getNodes()) {
indicies.put(s, index);
pageranks[index] = 1.0f / N;
if (useEdgeWeight) {
int s_index = indicies.get(s);
s.setAttribute(attributeColumn, nodePagrank[s_index]);
}
}
private void setInitialValues(Graph hgraph, double[] pagerankValues, double[] weights, boolean directed, boolean useWeights) {
int N = hgraph.getNodeCount();
int index = 0;
for (Node s : hgraph.getNodes()) {
pagerankValues[index] = 1.0f / N;
if (useWeights) {
double sum = 0;
EdgeIterable eIter;
if (isDirected) {
eIter = ((HierarchicalDirectedGraph) hgraph).getOutEdgesAndMetaOutEdges(s);
if (directed) {
eIter = ((DirectedGraph) hgraph).getOutEdges(s);
} else {
eIter = ((HierarchicalUndirectedGraph) hgraph).getEdgesAndMetaEdges(s);
eIter = ((UndirectedGraph) hgraph).getEdges(s);
}
for (Edge edge : eIter) {
sum += edge.getWeight();
@@ -155,96 +187,116 @@ public class PageRank implements Statistics, LongTask {
}
index++;
}
}
private double calculateR(Graph hgraph, double[] pagerankValues, HashMap<Node, Integer> indicies, boolean directed, double prob) {
int N = hgraph.getNodeCount();
double r = 0;
for (Node s : hgraph.getNodes()) {
int s_index = indicies.get(s);
boolean out;
if (directed) {
out = ((DirectedGraph) hgraph).getOutDegree(s) > 0;
} else {
out = hgraph.getDegree(s) > 0;
}
if (out) {
r += (1.0 - prob) * (pagerankValues[s_index] / N);
} else {
r += (pagerankValues[s_index] / N);
}
if (isCanceled) {
hgraph.readUnlockAll();
return r;
}
}
return r;
}
private double updateValueForNode(Graph hgraph, Node s, double[] pagerankValues, double[] weights,
HashMap<Node, Integer> indicies, boolean directed, boolean useWeights, double r, double prob) {
double res = r;
EdgeIterable eIter;
if (directed) {
eIter = ((DirectedGraph) hgraph).getInEdges(s);
} else {
eIter = hgraph.getEdges(s);
}
for (Edge edge : eIter) {
Node neighbor = hgraph.getOpposite(s, edge);
int neigh_index = indicies.get(neighbor);
int normalize;
if (directed) {
normalize = ((DirectedGraph) hgraph).getOutDegree(neighbor);
} else {
normalize = hgraph.getDegree(neighbor);
}
if (useWeights) {
double weight = edge.getWeight() / weights[neigh_index];
res += prob * pagerankValues[neigh_index] * weight;
} else {
res += prob * (pagerankValues[neigh_index] / normalize);
}
}
return res;
}
double[] calculatePagerank(Graph hgraph, HashMap<Node, Integer> indicies,
boolean directed, boolean useWeights, double eps, double prob) {
int N = hgraph.getNodeCount();
double[] pagerankValues = new double[N];
double[] temp = new double[N];
Progress.start(progress);
double[] weights = new double[N];
setInitialValues(hgraph, pagerankValues, weights, directed, useWeights);
while (true) {
double r = 0;
for (Node s : hgraph.getNodes()) {
int s_index = indicies.get(s);
boolean out;
if (isDirected) {
out = ((HierarchicalDirectedGraph) hgraph).getTotalOutDegree(s) > 0;
} else {
out = hgraph.getTotalDegree(s) > 0;
}
if (out) {
r += (1.0 - probability) * (pageranks[s_index] / N);
} else {
r += (pageranks[s_index] / N);
}
if (isCanceled) {
hgraph.readUnlockAll();
return;
}
}
double r = calculateR(hgraph, pagerankValues, indicies, directed, prob);
boolean done = true;
for (Node s : hgraph.getNodes()) {
int s_index = indicies.get(s);
temp[s_index] = r;
temp[s_index] = updateValueForNode(hgraph, s, pagerankValues, weights, indicies, directed, useWeights, r, prob);
EdgeIterable eIter;
if (isDirected) {
eIter = ((HierarchicalDirectedGraph) hgraph).getInEdgesAndMetaInEdges(s);
} else {
eIter = ((HierarchicalUndirectedGraph) hgraph).getEdgesAndMetaEdges(s);
}
for (Edge edge : eIter) {
Node neighbor = hgraph.getOpposite(s, edge);
int neigh_index = indicies.get(neighbor);
int normalize;
if (isDirected) {
normalize = ((HierarchicalDirectedGraph) hgraph).getTotalOutDegree(neighbor);
} else {
normalize = ((HierarchicalUndirectedGraph) hgraph).getTotalDegree(neighbor);
}
if (useEdgeWeight) {
double weight = edge.getWeight() / weights[neigh_index];
temp[s_index] += probability * pageranks[neigh_index] * weight;
} else {
temp[s_index] += probability * (pageranks[neigh_index] / normalize);
}
}
if ((temp[s_index] - pageranks[s_index]) / pageranks[s_index] >= epsilon) {
if ((temp[s_index] - pagerankValues[s_index]) / pagerankValues[s_index] >= eps) {
done = false;
}
if (isCanceled) {
hgraph.readUnlockAll();
return;
return pagerankValues;
}
}
pageranks = temp;
pagerankValues = temp;
temp = new double[N];
if ((done) || (isCanceled)) {
break;
}
}
return pagerankValues;
}
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeColumn pangeRanksCol = nodeTable.getColumn(PAGERANK);
if (pangeRanksCol == null) {
pangeRanksCol = nodeTable.addColumn(PAGERANK, "PageRank", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, new Double(0));
}
public HashMap<Node, Integer> createIndiciesMap(Graph hgraph) {
HashMap<Node, Integer> newIndicies = new HashMap<Node, Integer>();
int index = 0;
for (Node s : hgraph.getNodes()) {
int s_index = indicies.get(s);
AttributeRow row = (AttributeRow) s.getNodeData().getAttributes();
row.setValue(pangeRanksCol, pageranks[s_index]);
newIndicies.put(s, index);
index++;
}
hgraph.readUnlockAll();
return newIndicies;
}
/**
*
* @return
*/
@Override
public String getReport() {
//distribution of values
Map<Double, Integer> dist = new HashMap<Double, Integer>();
@@ -277,7 +329,7 @@ public class PageRank implements Statistics, LongTask {
ChartUtils.decorateChart(chart);
ChartUtils.scaleChart(chart, dSeries, true);
String imageFile = ChartUtils.renderChart(chart, "pageranks.png");
String report = "<HTML> <BODY> <h1>PageRank Report </h1> "
+ "<hr> <br />"
+ "<h2> Parameters: </h2>"
@@ -297,6 +349,7 @@ public class PageRank implements Statistics, LongTask {
*
* @return
*/
@Override
public boolean cancel() {
isCanceled = true;
return true;
@@ -306,6 +359,7 @@ public class PageRank implements Statistics, LongTask {
*
* @param progressTicket
*/
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
progress = progressTicket;
}
@@ -46,17 +46,12 @@ import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeRow;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Table;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.HierarchicalDirectedGraph;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.Node;
import org.gephi.statistics.spi.Statistics;
import org.gephi.utils.longtask.spi.LongTask;
@@ -67,6 +62,7 @@ import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.openide.util.NbBundle;
/**
*
@@ -89,93 +85,123 @@ public class WeightedDegree implements Statistics, LongTask {
return avgWDegree;
}
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
HierarchicalGraph graph = graphModel.getHierarchicalGraphVisible();
Graph graph = graphModel.getGraphVisible();
execute(graph, attributeModel);
}
public void execute(HierarchicalGraph graph, AttributeModel attributeModel) {
isDirected = graph instanceof DirectedGraph;
public void execute(Graph graph, AttributeModel attributeModel) {
isDirected = graph.isDirected();
isCanceled = false;
degreeDist = new HashMap<Double, Integer>();
inDegreeDist = new HashMap<Double, Integer>();
outDegreeDist = new HashMap<Double, Integer>();
AttributeTable nodeTable = attributeModel.getNodeTable();
AttributeColumn degCol = nodeTable.getColumn(WDEGREE);
AttributeColumn inCol = nodeTable.getColumn(WINDEGREE);
AttributeColumn outCol = nodeTable.getColumn(WOUTDEGREE);
if (degCol == null) {
degCol = nodeTable.addColumn(WDEGREE, "Weighted Degree", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, 0.0);
}
if (isDirected) {
if (inCol == null) {
inCol = nodeTable.addColumn(WINDEGREE, "Weighted In-Degree", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, 0.0);
}
if (outCol == null) {
outCol = nodeTable.addColumn(WOUTDEGREE, "Weighted Out-Degree", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, 0.0);
}
}
initializeDegreeDists();
initializeAttributeColunms(attributeModel);
graph.readLock();
Progress.start(progress, graph.getNodeCount());
int i = 0;
for (Node n : graph.getNodes()) {
AttributeRow row = (AttributeRow) n.getNodeData().getAttributes();
double totalWeight = 0;
if (isDirected) {
HierarchicalDirectedGraph hdg = graph.getGraphModel().getHierarchicalDirectedGraph();
double totalInWeight = 0;
double totalOutWeight = 0;
for (Iterator it = graph.getEdgesAndMetaEdges(n).iterator(); it.hasNext();) {
Edge e = (Edge) it.next();
if (e.getSource().getNodeData().equals(n.getNodeData())) {
totalOutWeight += e.getWeight();
}
if (e.getTarget().getNodeData().equals(n.getNodeData())) {
totalInWeight += e.getWeight();
}
}
totalWeight = totalInWeight + totalOutWeight;
row.setValue(inCol, totalInWeight);
row.setValue(outCol, totalOutWeight);
if (!inDegreeDist.containsKey(totalInWeight)) {
inDegreeDist.put(totalInWeight, 0);
}
inDegreeDist.put(totalInWeight, inDegreeDist.get(totalInWeight) + 1);
if (!outDegreeDist.containsKey(totalOutWeight)) {
outDegreeDist.put(totalOutWeight, 0);
}
outDegreeDist.put(totalOutWeight, outDegreeDist.get(totalOutWeight) + 1);
} else {
for (Iterator it = graph.getEdgesAndMetaEdges(n).iterator(); it.hasNext();) {
Edge e = (Edge) it.next();
totalWeight += e.getWeight();
}
}
row.setValue(degCol, totalWeight);
avgWDegree += totalWeight;
if (!degreeDist.containsKey(totalWeight)) {
degreeDist.put(totalWeight, 0);
}
degreeDist.put(totalWeight, degreeDist.get(totalWeight) + 1);
if (isCanceled) {
break;
}
i++;
Progress.progress(progress, i);
}
avgWDegree /= (isDirected) ? 2 * graph.getNodeCount() : graph.getNodeCount();
avgWDegree = calculateAverageWeightedDegree(graph, isDirected, true);
graph.readUnlockAll();
}
public double calculateAverageWeightedDegree(Graph graph, boolean isDirected, boolean updateAttributes) {
double averageWeightedDegree = 0;
DirectedGraph directedGraph = null;
if (isDirected) {
directedGraph = (DirectedGraph) graph;
}
Progress.start(progress, graph.getNodeCount());
for (Node n : graph.getNodes()) {
double totalWeight = 0;
if (isDirected) {
double totalInWeight = 0;
double totalOutWeight = 0;
for (Edge e : directedGraph.getEdges(n)) {
if (e.getSource().equals(n)) {
totalOutWeight += e.getWeight();
}
if (e.getTarget().equals(n)) {
totalInWeight += e.getWeight();
}
}
totalWeight = totalInWeight + totalOutWeight;
n.setAttribute(WINDEGREE, totalInWeight);
n.setAttribute(WOUTDEGREE, totalOutWeight);
n.setAttribute(WDEGREE, totalWeight);
updateDegreeDists(totalInWeight, totalOutWeight, totalWeight);
} else {
for (Edge e : graph.getEdges(n)) {
totalWeight += e.getWeight();
}
n.setAttribute(WDEGREE, totalWeight);
updateDegreeDists(totalWeight);
}
averageWeightedDegree += totalWeight;
if (isCanceled) {
break;
}
Progress.progress(progress);
}
averageWeightedDegree /= (isDirected) ? 2 * graph.getNodeCount() : graph.getNodeCount();
return averageWeightedDegree;
}
private void initializeDegreeDists() {
degreeDist = new HashMap<Double, Integer>();
inDegreeDist = new HashMap<Double, Integer>();
outDegreeDist = new HashMap<Double, Integer>();
}
private void initializeAttributeColunms(AttributeModel attributeModel) {
Table nodeTable = attributeModel.getNodeTable();
if (isDirected) {
if (!nodeTable.hasColumn(WINDEGREE)) {
nodeTable.addColumn(WINDEGREE, NbBundle.getMessage(WeightedDegree.class, "WeightedDegree.nodecolumn.InDegree"), Double.class, 0.0);
}
if (!nodeTable.hasColumn(WOUTDEGREE)) {
nodeTable.addColumn(WOUTDEGREE, NbBundle.getMessage(WeightedDegree.class, "WeightedDegree.nodecolumn.OutDegree"), Double.class, 0.0);
}
}
if (!nodeTable.hasColumn(WDEGREE)) {
nodeTable.addColumn(WDEGREE, NbBundle.getMessage(WeightedDegree.class, "WeightedDegree.nodecolumn.Degree"), Double.class, 0.0);
}
}
private void updateDegreeDists(double winDegree, double woutDegree, double wdegree) {
if (!inDegreeDist.containsKey(winDegree)) {
inDegreeDist.put(winDegree, 0);
}
inDegreeDist.put(winDegree, inDegreeDist.get(winDegree) + 1);
if (!outDegreeDist.containsKey(woutDegree)) {
outDegreeDist.put(woutDegree, 0);
}
outDegreeDist.put(woutDegree, outDegreeDist.get(woutDegree) + 1);
if (!degreeDist.containsKey(wdegree)) {
degreeDist.put(wdegree, 0);
}
degreeDist.put(wdegree, degreeDist.get(wdegree) + 1);
}
private void updateDegreeDists(double wdegree) {
if (!degreeDist.containsKey(wdegree)) {
degreeDist.put(wdegree, 0);
}
degreeDist.put(wdegree, degreeDist.get(wdegree) + 1);
}
@Override
public String getReport() {
String report = "";
@@ -282,11 +308,13 @@ public class WeightedDegree implements Statistics, LongTask {
return report;
}
@Override
public boolean cancel() {
this.isCanceled = true;
return true;
}
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progress = progressTicket;
}
@@ -38,31 +38,34 @@ made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.ClusteringCoefficient;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service=StatisticsBuilder.class)
public class ClusteringCoefficientBuilder implements StatisticsBuilder {
public String getName() {
return NbBundle.getMessage(ClusteringCoefficientBuilder.class, "ClusteringCoefficent.name");
}
public Statistics getStatistics() {
return new ClusteringCoefficient();
}
public Class<? extends Statistics> getStatisticsClass() {
return ClusteringCoefficient.class;
}
}
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.ClusteringCoefficient;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service=StatisticsBuilder.class)
public class ClusteringCoefficientBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(ClusteringCoefficientBuilder.class, "ClusteringCoefficent.name");
}
@Override
public Statistics getStatistics() {
return new ClusteringCoefficient();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return ClusteringCoefficient.class;
}
}
@@ -54,14 +54,17 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service=StatisticsBuilder.class)
public class ConnectedComponentsBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(ConnectedComponentsBuilder.class, "ConnectedComponents.name");
}
@Override
public Statistics getStatistics() {
return new ConnectedComponents();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return ConnectedComponents.class;
}
@@ -54,14 +54,17 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = StatisticsBuilder.class)
public class DegreeBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(DegreeBuilder.class, "InOutDegree.name");
}
@Override
public Statistics getStatistics() {
return new Degree();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return Degree.class;
}
@@ -38,31 +38,34 @@ made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.GraphDensity;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
* The statistics builder the graph denstiy statistics
* @author pjmcswee
*/
@ServiceProvider(service=StatisticsBuilder.class)
public class DensityBuilder implements StatisticsBuilder {
public String getName() {
return NbBundle.getMessage(DensityBuilder.class, "GraphDensity.name");
}
public Statistics getStatistics() {
return new GraphDensity();
}
public Class<? extends Statistics> getStatisticsClass() {
return GraphDensity.class;
}
}
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.GraphDensity;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
* The statistics builder the graph denstiy statistics
* @author pjmcswee
*/
@ServiceProvider(service=StatisticsBuilder.class)
public class DensityBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(DensityBuilder.class, "GraphDensity.name");
}
@Override
public Statistics getStatistics() {
return new GraphDensity();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return GraphDensity.class;
}
}
@@ -38,32 +38,34 @@ made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.EigenvectorCentrality;
import org.gephi.statistics.plugin.Hits;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service = StatisticsBuilder.class)
public class EigenvectorCentralityBuilder implements StatisticsBuilder {
public String getName() {
return NbBundle.getMessage(HitsBuilder.class, "EigenvectorCentrality.name");
}
public Statistics getStatistics() {
return new EigenvectorCentrality();
}
public Class<? extends Statistics> getStatisticsClass() {
return EigenvectorCentrality.class;
}
}
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.EigenvectorCentrality;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service = StatisticsBuilder.class)
public class EigenvectorCentralityBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(HitsBuilder.class, "EigenvectorCentrality.name");
}
@Override
public Statistics getStatistics() {
return new EigenvectorCentrality();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return EigenvectorCentrality.class;
}
}
@@ -38,31 +38,34 @@ made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.GraphDistance;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service=StatisticsBuilder.class)
public class GraphDistanceBuilder implements StatisticsBuilder {
public String getName() {
return NbBundle.getMessage(GraphDistanceBuilder.class, "GraphDistance.name");
}
public Statistics getStatistics() {
return new GraphDistance();
}
public Class<? extends Statistics> getStatisticsClass() {
return GraphDistance.class;
}
}
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.GraphDistance;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service=StatisticsBuilder.class)
public class GraphDistanceBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(GraphDistanceBuilder.class, "GraphDistance.name");
}
@Override
public Statistics getStatistics() {
return new GraphDistance();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return GraphDistance.class;
}
}
@@ -38,31 +38,34 @@ made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.Hits;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service = StatisticsBuilder.class)
public class HitsBuilder implements StatisticsBuilder {
public String getName() {
return NbBundle.getMessage(HitsBuilder.class, "Hits.name");
}
public Statistics getStatistics() {
return new Hits();
}
public Class<? extends Statistics> getStatisticsClass() {
return Hits.class;
}
}
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.Hits;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service = StatisticsBuilder.class)
public class HitsBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(HitsBuilder.class, "Hits.name");
}
@Override
public Statistics getStatistics() {
return new Hits();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return Hits.class;
}
}
@@ -38,31 +38,34 @@ made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.Modularity;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service = StatisticsBuilder.class)
public class ModularityBuilder implements StatisticsBuilder {
public String getName() {
return NbBundle.getMessage(ModularityBuilder.class, "Modularity.name");
}
public Statistics getStatistics() {
return new Modularity();
}
public Class<? extends Statistics> getStatisticsClass() {
return Modularity.class;
}
}
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.Modularity;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service = StatisticsBuilder.class)
public class ModularityBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(ModularityBuilder.class, "Modularity.name");
}
@Override
public Statistics getStatistics() {
return new Modularity();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return Modularity.class;
}
}
@@ -38,31 +38,34 @@ made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.PageRank;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service = StatisticsBuilder.class)
public class PageRankBuilder implements StatisticsBuilder {
public String getName() {
return NbBundle.getMessage(PageRankBuilder.class, "PageRank.name");
}
public Statistics getStatistics() {
return new PageRank();
}
public Class<? extends Statistics> getStatisticsClass() {
return PageRank.class;
}
}
*/
package org.gephi.statistics.plugin.builder;
import org.gephi.statistics.plugin.PageRank;
import org.gephi.statistics.spi.Statistics;
import org.gephi.statistics.spi.StatisticsBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
*
* @author pjmcswee
*/
@ServiceProvider(service = StatisticsBuilder.class)
public class PageRankBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(PageRankBuilder.class, "PageRank.name");
}
@Override
public Statistics getStatistics() {
return new PageRank();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return PageRank.class;
}
}
@@ -54,14 +54,17 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = StatisticsBuilder.class)
public class WeightedDegreeBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(WeightedDegreeBuilder.class, "WeightedDegree.name");
}
@Override
public Statistics getStatistics() {
return new WeightedDegree();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return WeightedDegree.class;
}
@@ -45,19 +45,15 @@ import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.data.attributes.type.DynamicDouble;
import org.gephi.data.attributes.type.Interval;
import org.gephi.dynamic.api.DynamicController;
import org.gephi.dynamic.api.DynamicModel;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Column;
import org.gephi.attribute.api.Table;
import org.gephi.attribute.time.Interval;
import org.gephi.attribute.time.TimestampDoubleSet;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.GraphView;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.Node;
import org.gephi.statistics.plugin.ChartUtils;
import org.gephi.statistics.plugin.ClusteringCoefficient;
@@ -90,48 +86,38 @@ public class DynamicClusteringCoefficient implements DynamicStatistics, LongTask
private boolean cancel = false;
private ClusteringCoefficient clusteringCoefficientStat;
//Cols
private AttributeColumn dynamicCoefficientColumn;
private Column dynamicCoefficientColumn;
//Average
private AttributeColumn dynamicAverageCoefficientColumn;
private DynamicDouble averages;
private Column dynamicAverageCoefficientColumn;
private Map<Double, Double> averages;
public DynamicClusteringCoefficient() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController != null && graphController.getModel() != null) {
isDirected = graphController.getModel().isDirected();
if (graphController != null && graphController.getGraphModel()!= null) {
isDirected = graphController.getGraphModel().isDirected();
}
}
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
this.graphModel = graphModel;
this.isDirected = graphModel.isDirected();
this.averages = new HashMap<Double, Double>();
//Attributes cols
if (!averageOnly) {
AttributeTable nodeTable = attributeModel.getNodeTable();
Table nodeTable = attributeModel.getNodeTable();
dynamicCoefficientColumn = nodeTable.getColumn(DYNAMIC_CLUSTERING_COEFFICIENT);
if (dynamicCoefficientColumn == null) {
dynamicCoefficientColumn = nodeTable.addColumn(DYNAMIC_CLUSTERING_COEFFICIENT, NbBundle.getMessage(DynamicClusteringCoefficient.class, "DynamicClusteringCoefficient.nodecolumn.ClusteringCoefficient"), AttributeType.DYNAMIC_DOUBLE, AttributeOrigin.COMPUTED, new DynamicDouble());
dynamicCoefficientColumn = nodeTable.addColumn(DYNAMIC_CLUSTERING_COEFFICIENT, NbBundle.getMessage(DynamicClusteringCoefficient.class, "DynamicClusteringCoefficient.nodecolumn.ClusteringCoefficient"), TimestampDoubleSet.class, null);
}
}
//Column
AttributeTable graphTable = attributeModel.getGraphTable();
dynamicAverageCoefficientColumn = graphTable.getColumn(DYNAMIC_AVG_CLUSTERING_COEFFICIENT);
if (dynamicAverageCoefficientColumn == null) {
dynamicAverageCoefficientColumn = graphTable.addColumn(DYNAMIC_AVG_CLUSTERING_COEFFICIENT, NbBundle.getMessage(DynamicClusteringCoefficient.class, "DynamicClusteringCoefficient.graphcolumn.AvgClusteringCoefficient"), AttributeType.DYNAMIC_DOUBLE, AttributeOrigin.COMPUTED, new DynamicDouble());
}
}
@Override
public String getReport() {
//Transform to Map
Map<Double, Double> map = new HashMap<Double, Double>();
for (Interval<Double> interval : averages.getIntervals()) {
map.put(interval.getLow(), interval.getValue());
}
//Time series
XYSeries dSeries = ChartUtils.createXYSeries(map, "Clustering Coefficient Time Series");
XYSeries dSeries = ChartUtils.createXYSeries(averages, "Clustering Coefficient Time Series");
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(dSeries);
@@ -168,12 +154,13 @@ public class DynamicClusteringCoefficient implements DynamicStatistics, LongTask
return report;
}
@Override
public void loop(GraphView window, Interval interval) {
HierarchicalGraph graph = null;
Graph graph = null;
if (isDirected) {
graph = graphModel.getHierarchicalDirectedGraph(window);
graph = graphModel.getDirectedGraph(window);
} else {
graph = graphModel.getHierarchicalUndirectedGraph(window);
graph = graphModel.getUndirectedGraph(window);
}
graph.readLock();
@@ -188,14 +175,10 @@ public class DynamicClusteringCoefficient implements DynamicStatistics, LongTask
int i = 0;
for (Node n : graph.getNodes()) {
double coef = coefficients[i++];
Interval<Double> valInterval = new Interval<Double>(interval, coef);
DynamicDouble val = (DynamicDouble) n.getAttributes().getValue(dynamicCoefficientColumn.getIndex());
if (val == null) {
val = new DynamicDouble(valInterval);
} else {
val = new DynamicDouble(val, valInterval);
}
n.getAttributes().setValue(dynamicCoefficientColumn.getIndex(), val);
n.setAttribute(dynamicCoefficientColumn, coef, interval.getLow());
n.setAttribute(dynamicCoefficientColumn, coef, interval.getHigh());
if (cancel) {
break;
}
@@ -206,36 +189,44 @@ public class DynamicClusteringCoefficient implements DynamicStatistics, LongTask
//Average
double avg = clusteringCoefficientStat.getAverageClusteringCoefficient();
graph.setAttribute(DYNAMIC_AVG_CLUSTERING_COEFFICIENT, avg, interval.getLow());
graph.setAttribute(DYNAMIC_AVG_CLUSTERING_COEFFICIENT, avg, interval.getHigh());
averages = new DynamicDouble(averages, new Interval<Double>(interval.getLow(), interval.getHigh(), false, true, avg));
averages.put(interval.getLow(), avg);
averages.put(interval.getHigh(), avg);
}
@Override
public void end() {
clusteringCoefficientStat = null;
graphModel.getGraphVisible().getAttributes().setValue(dynamicAverageCoefficientColumn.getIndex(), averages);
}
@Override
public void setBounds(Interval bounds) {
this.bounds = bounds;
}
@Override
public void setWindow(double window) {
this.window = window;
}
@Override
public void setTick(double tick) {
this.tick = tick;
}
@Override
public double getWindow() {
return window;
}
@Override
public double getTick() {
return tick;
}
@Override
public Interval getBounds() {
return bounds;
}
@@ -256,11 +247,13 @@ public class DynamicClusteringCoefficient implements DynamicStatistics, LongTask
return averageOnly;
}
@Override
public boolean cancel() {
cancel = true;
return true;
}
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
}
}
@@ -1,43 +1,43 @@
/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin.dynamic;
@@ -45,19 +45,17 @@ import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.data.attributes.type.DynamicDouble;
import org.gephi.data.attributes.type.DynamicInteger;
import org.gephi.data.attributes.type.Interval;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.Column;
import org.gephi.attribute.api.Table;
import org.gephi.attribute.time.Interval;
import org.gephi.attribute.time.TimestampDoubleSet;
import org.gephi.attribute.time.TimestampIntegerSet;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.GraphView;
import org.gephi.graph.api.HierarchicalDirectedGraph;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.Node;
import org.gephi.statistics.plugin.ChartUtils;
import org.gephi.statistics.spi.DynamicStatistics;
@@ -90,60 +88,49 @@ public class DynamicDegree implements DynamicStatistics, LongTask {
private boolean averageOnly;
private boolean cancel = false;
//Cols
private AttributeColumn dynamicInDegreeColumn;
private AttributeColumn dynamicOutDegreeColumn;
private AttributeColumn dynamicDegreeColumn;
private Column dynamicInDegreeColumn;
private Column dynamicOutDegreeColumn;
private Column dynamicDegreeColumn;
//Average
private AttributeColumn dynamicAverageDegreeColumn;
private DynamicDouble averages;
private Map<Double, Double> averages;
public DynamicDegree() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController != null && graphController.getModel() != null) {
isDirected = graphController.getModel().isDirected();
if (graphController != null && graphController.getGraphModel() != null) {
isDirected = graphController.getGraphModel().isDirected();
}
}
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
this.graphModel = graphModel;
this.isDirected = graphModel.isDirected();
this.averages = new HashMap<Double, Double>();
//Attributes cols
if (!averageOnly) {
AttributeTable nodeTable = attributeModel.getNodeTable();
Table nodeTable = attributeModel.getNodeTable();
dynamicInDegreeColumn = nodeTable.getColumn(DYNAMIC_INDEGREE);
dynamicOutDegreeColumn = nodeTable.getColumn(DYNAMIC_OUTDEGREE);
dynamicDegreeColumn = nodeTable.getColumn(DYNAMIC_DEGREE);
if (isDirected) {
if (dynamicInDegreeColumn == null) {
dynamicInDegreeColumn = nodeTable.addColumn(DYNAMIC_INDEGREE, NbBundle.getMessage(DynamicDegree.class, "DynamicDegree.nodecolumn.InDegree"), AttributeType.DYNAMIC_INT, AttributeOrigin.COMPUTED, new DynamicInteger());
dynamicInDegreeColumn = nodeTable.addColumn(DYNAMIC_INDEGREE, NbBundle.getMessage(DynamicDegree.class, "DynamicDegree.nodecolumn.InDegree"), TimestampIntegerSet.class, null);
}
if (dynamicOutDegreeColumn == null) {
dynamicOutDegreeColumn = nodeTable.addColumn(DYNAMIC_OUTDEGREE, NbBundle.getMessage(DynamicDegree.class, "DynamicDegree.nodecolumn.OutDegree"), AttributeType.DYNAMIC_INT, AttributeOrigin.COMPUTED, new DynamicInteger());
dynamicOutDegreeColumn = nodeTable.addColumn(DYNAMIC_OUTDEGREE, NbBundle.getMessage(DynamicDegree.class, "DynamicDegree.nodecolumn.OutDegree"), TimestampIntegerSet.class, null);
}
}
if (dynamicDegreeColumn == null) {
dynamicDegreeColumn = nodeTable.addColumn(DYNAMIC_DEGREE, NbBundle.getMessage(DynamicDegree.class, "DynamicDegree.nodecolumn.Degree"), AttributeType.DYNAMIC_INT, AttributeOrigin.COMPUTED, new DynamicInteger());
dynamicDegreeColumn = nodeTable.addColumn(DYNAMIC_DEGREE, NbBundle.getMessage(DynamicDegree.class, "DynamicDegree.nodecolumn.Degree"), TimestampIntegerSet.class, null);
}
}
//Avg Column
AttributeTable graphTable = attributeModel.getGraphTable();
dynamicAverageDegreeColumn = graphTable.getColumn(DYNAMIC_AVGDEGREE);
if (dynamicAverageDegreeColumn == null) {
dynamicAverageDegreeColumn = graphTable.addColumn(DYNAMIC_AVGDEGREE, NbBundle.getMessage(DynamicDegree.class, "DynamicDegree.graphcolumn.AvgDegree"), AttributeType.DYNAMIC_DOUBLE, AttributeOrigin.COMPUTED, new DynamicDouble());
}
}
@Override
public String getReport() {
//Transform to Map
Map<Double, Double> map = new HashMap<Double, Double>();
for (Interval<Double> interval : averages.getIntervals()) {
map.put(interval.getLow(), interval.getValue());
}
//Time series
XYSeries dSeries = ChartUtils.createXYSeries(map, "Degree Time Series");
XYSeries dSeries = ChartUtils.createXYSeries(averages, "Degree Time Series");
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(dSeries);
@@ -174,53 +161,33 @@ public class DynamicDegree implements DynamicStatistics, LongTask {
+ "<br /><br />" + degreeImageFile;
/*for (Interval<Double> averages : averages) {
report += averages.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />";
}*/
report += averages.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />";
}*/
report += "<br /><br /></BODY></HTML>";
return report;
}
@Override
public void loop(GraphView window, Interval interval) {
HierarchicalGraph graph = graphModel.getHierarchicalGraph(window);
HierarchicalDirectedGraph directedGraph = null;
Graph graph = graphModel.getGraph(window);
DirectedGraph directedGraph = null;
if (isDirected) {
directedGraph = graphModel.getHierarchicalDirectedGraph(window);
directedGraph = graphModel.getDirectedGraph(window);
}
long sum = 0;
for (Node n : graph.getNodes().toArray()) {
int degree = graph.getTotalDegree(n);
int degree = graph.getDegree(n);
if (!averageOnly) {
Interval<Integer> degreeInInterval = new Interval<Integer>(interval, degree);
DynamicInteger val = (DynamicInteger) n.getAttributes().getValue(dynamicDegreeColumn.getIndex());
if (val == null) {
val = new DynamicInteger(degreeInInterval);
} else {
val = new DynamicInteger(val, degreeInInterval);
}
n.getAttributes().setValue(dynamicDegreeColumn.getIndex(), val);
n.setAttribute(dynamicDegreeColumn, degree, interval.getLow());
if (isDirected) {
int indegree = directedGraph.getTotalInDegree(n);
Interval<Integer> inDegreeInInterval = new Interval<Integer>(interval, indegree);
DynamicInteger inVal = (DynamicInteger) n.getAttributes().getValue(dynamicInDegreeColumn.getIndex());
if (inVal == null) {
inVal = new DynamicInteger(inDegreeInInterval);
} else {
inVal = new DynamicInteger(inVal, inDegreeInInterval);
}
n.getAttributes().setValue(dynamicInDegreeColumn.getIndex(), inVal);
int indegree = directedGraph.getInDegree(n);
n.setAttribute(dynamicInDegreeColumn, indegree, interval.getLow());
int outdegree = directedGraph.getTotalOutDegree(n);
Interval<Integer> outDegreeInInterval = new Interval<Integer>(interval, outdegree);
DynamicInteger outVal = (DynamicInteger) n.getAttributes().getValue(dynamicOutDegreeColumn.getIndex());
if (outVal == null) {
outVal = new DynamicInteger(outDegreeInInterval);
} else {
outVal = new DynamicInteger(outVal, outDegreeInInterval);
}
n.getAttributes().setValue(dynamicOutDegreeColumn.getIndex(), outVal);
int outdegree = directedGraph.getOutDegree(n);
n.setAttribute(dynamicOutDegreeColumn, outdegree, interval.getLow());
}
}
sum += degree;
@@ -230,34 +197,43 @@ public class DynamicDegree implements DynamicStatistics, LongTask {
}
double avg = sum / (double) graph.getNodeCount();
averages = new DynamicDouble(averages, new Interval<Double>(interval.getLow(), interval.getHigh(), false, true, avg));
averages.put(interval.getLow(), avg);
averages.put(interval.getHigh(), avg);
graph.setAttribute(DYNAMIC_AVGDEGREE, avg, interval.getLow());
graph.setAttribute(DYNAMIC_AVGDEGREE, avg, interval.getHigh());
}
@Override
public void end() {
graphModel.getGraphVisible().getAttributes().setValue(dynamicAverageDegreeColumn.getIndex(), averages);
}
@Override
public void setBounds(Interval bounds) {
this.bounds = bounds;
}
@Override
public void setWindow(double window) {
this.window = window;
}
@Override
public void setTick(double tick) {
this.tick = tick;
}
@Override
public double getWindow() {
return window;
}
@Override
public double getTick() {
return tick;
}
@Override
public Interval getBounds() {
return bounds;
}
@@ -278,11 +254,13 @@ public class DynamicDegree implements DynamicStatistics, LongTask {
return averageOnly;
}
@Override
public boolean cancel() {
cancel = true;
return true;
}
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
}
}
@@ -45,16 +45,11 @@ import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.data.attributes.type.DynamicInteger;
import org.gephi.data.attributes.type.Interval;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.time.Interval;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.GraphView;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.statistics.plugin.ChartUtils;
import org.gephi.statistics.spi.DynamicStatistics;
import org.jfree.chart.ChartFactory;
@@ -62,7 +57,6 @@ import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.openide.util.NbBundle;
/**
*
@@ -77,29 +71,18 @@ public class DynamicNbEdges implements DynamicStatistics {
private double tick;
private Interval bounds;
//Average
private AttributeColumn nbEdgesCol;
private DynamicInteger counts;
private Map<Double, Integer> counts;
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
this.graphModel = graphModel;
//Column
AttributeTable graphTable = attributeModel.getGraphTable();
nbEdgesCol = graphTable.getColumn(NB_EDGES);
if (nbEdgesCol == null) {
nbEdgesCol = graphTable.addColumn(NB_EDGES, NbBundle.getMessage(DynamicNbEdges.class, "DynamicNbNodes.graphcolumn.NbEdges"), AttributeType.DYNAMIC_INT, AttributeOrigin.COMPUTED, new DynamicInteger());
}
this.counts = new HashMap<Double, Integer>();
}
@Override
public String getReport() {
//Transform to Map
Map<Double, Integer> map = new HashMap<Double, Integer>();
for(Interval<Integer> interval : counts.getIntervals()) {
map.put(interval.getLow(), interval.getValue());
}
//Time series
XYSeries dSeries = ChartUtils.createXYSeries(map, "Nb Edges Time Series");
XYSeries dSeries = ChartUtils.createXYSeries(counts, "Nb Edges Time Series");
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(dSeries);
@@ -136,38 +119,48 @@ public class DynamicNbEdges implements DynamicStatistics {
return report;
}
@Override
public void loop(GraphView window, Interval interval) {
HierarchicalGraph graph = graphModel.getHierarchicalGraph(window);
Graph graph = graphModel.getGraph(window);
int count = graph.getEdgeCount();
graph.setAttribute(NB_EDGES, count, interval.getLow());
graph.setAttribute(NB_EDGES, count, interval.getHigh());
counts = new DynamicInteger(counts, new Interval<Integer>(interval.getLow(), interval.getHigh(), false, true, count));
counts.put(interval.getLow(), count);
counts.put(interval.getHigh(), count);
}
@Override
public void end() {
graphModel.getGraphVisible().getAttributes().setValue(nbEdgesCol.getIndex(), counts);
}
public void setBounds(Interval bounds) {
this.bounds = bounds;
}
@Override
public void setWindow(double window) {
this.window = window;
}
@Override
public void setTick(double tick) {
this.tick = tick;
}
@Override
public double getWindow() {
return window;
}
@Override
public double getTick() {
return tick;
}
@Override
public Interval getBounds() {
return bounds;
}
@@ -1,43 +1,43 @@
/*
Copyright 2008-2011 Gephi
Authors : Sébastien Heymann <sebastien.heymann@gephi.org>
Website : http://www.gephi.org
Copyright 2008-2011 Gephi
Authors : Sébastien Heymann <sebastien.heymann@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.statistics.plugin.dynamic;
@@ -45,16 +45,11 @@ import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeOrigin;
import org.gephi.data.attributes.api.AttributeTable;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.data.attributes.type.DynamicInteger;
import org.gephi.data.attributes.type.Interval;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.time.Interval;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.GraphView;
import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.statistics.plugin.ChartUtils;
import org.gephi.statistics.spi.DynamicStatistics;
import org.jfree.chart.ChartFactory;
@@ -62,7 +57,6 @@ import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.openide.util.NbBundle;
/**
*
@@ -77,31 +71,18 @@ public class DynamicNbNodes implements DynamicStatistics {
private double tick;
private Interval bounds;
//Average
private AttributeColumn nbNodesCol;
private DynamicInteger counts;
private Map<Double, Integer> counts;
@Override
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
this.graphModel = graphModel;
//Column
AttributeTable graphTable = attributeModel.getGraphTable();
nbNodesCol = graphTable.getColumn(NB_NODES);
if (nbNodesCol == null) {
nbNodesCol = graphTable.addColumn(NB_NODES, NbBundle.getMessage(DynamicNbNodes.class, "DynamicNbNodes.graphcolumn.NbNodes"), AttributeType.DYNAMIC_INT, AttributeOrigin.COMPUTED, new DynamicInteger());
}
counts = new DynamicInteger();
graphModel.getGraphVisible().getAttributes().setValue(nbNodesCol.getIndex(), counts);
this.counts = new HashMap<Double, Integer>();
}
@Override
public String getReport() {
//Transform to Map
Map<Double, Integer> map = new HashMap<Double, Integer>();
for (Interval<Integer> interval : counts.getIntervals()) {
map.put(interval.getLow(), interval.getValue());
}
//Time series
XYSeries dSeries = ChartUtils.createXYSeries(map, "Nb Nodes Time Series");
XYSeries dSeries = ChartUtils.createXYSeries(counts, "Nb Nodes Time Series");
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(dSeries);
@@ -132,44 +113,55 @@ public class DynamicNbNodes implements DynamicStatistics {
+ "<br /><br />" + imageFile;
/*for (Interval<Integer> count : counts) {
report += count.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />";
}*/
report += count.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />";
}*/
report += "<br /><br /></BODY></HTML>";
return report;
}
@Override
public void loop(GraphView window, Interval interval) {
HierarchicalGraph graph = graphModel.getHierarchicalGraph(window);
Graph graph = graphModel.getGraph(window);
int count = graph.getNodeCount();
counts = new DynamicInteger(counts, new Interval<Integer>(interval.getLow(), interval.getHigh(), false, true, count));
graph.setAttribute(NB_NODES, count, interval.getLow());
graph.setAttribute(NB_NODES, count, interval.getHigh());
counts.put(interval.getLow(), count);
counts.put(interval.getHigh(), count);
}
@Override
public void end() {
graphModel.getGraphVisible().getAttributes().setValue(nbNodesCol.getIndex(), counts);
}
@Override
public void setBounds(Interval bounds) {
this.bounds = bounds;
}
@Override
public void setWindow(double window) {
this.window = window;
}
@Override
public void setTick(double tick) {
this.tick = tick;
}
@Override
public double getWindow() {
return window;
}
@Override
public double getTick() {
return tick;
}
@Override
public Interval getBounds() {
return bounds;
}
@@ -54,14 +54,17 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = StatisticsBuilder.class)
public class DynamicClusteringCoefficientBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(DynamicClusteringCoefficientBuilder.class, "DynamicClusteringCoefficient.name");
}
@Override
public Statistics getStatistics() {
return new DynamicClusteringCoefficient();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return DynamicClusteringCoefficient.class;
}
@@ -54,14 +54,17 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = StatisticsBuilder.class)
public class DynamicDegreeBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(DynamicDegreeBuilder.class, "DynamicDegree.name");
}
@Override
public Statistics getStatistics() {
return new DynamicDegree();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return DynamicDegree.class;
}
@@ -54,14 +54,17 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = StatisticsBuilder.class)
public class DynamicNbEdgesBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(DynamicNbNodesBuilder.class, "DynamicNbEdges.name");
}
@Override
public Statistics getStatistics() {
return new DynamicNbEdges();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return DynamicNbEdges.class;
}
@@ -54,14 +54,17 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = StatisticsBuilder.class)
public class DynamicNbNodesBuilder implements StatisticsBuilder {
@Override
public String getName() {
return NbBundle.getMessage(DynamicNbNodesBuilder.class, "DynamicNbNodes.name");
}
@Override
public Statistics getStatistics() {
return new DynamicNbNodes();
}
@Override
public Class<? extends Statistics> getStatisticsClass() {
return DynamicNbNodes.class;
}
@@ -7,4 +7,8 @@ OpenIDE-Module-Short-Description=Standard statistics and metrics algorithms
Degree.nodecolumn.InDegree = In-Degree
Degree.nodecolumn.OutDegree = Out-Degree
Degree.nodecolumn.Degree = Degree
Degree.graphcolumn.AverageDegree = Average Degree
Degree.graphcolumn.AverageDegree = Average Degree
WeightedDegree.nodecolumn.InDegree = Weighted In-Degree
WeightedDegree.nodecolumn.OutDegree = Weighted Out-Degree
WeightedDegree.nodecolumn.Degree = Weighted Degree
@@ -0,0 +1,492 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.statistics.plugin;
import java.util.HashMap;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.UndirectedGraph;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.project.api.ProjectController;
import org.gephi.project.impl.ProjectControllerImpl;
import org.openide.util.Lookup;
import static org.testng.Assert.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
*
* @author akharitonova
*/
public class ClusteringCoefficientNGTest {
private ProjectController pc;
@BeforeClass
public void setUp() {
pc = Lookup.getDefault().lookup(ProjectControllerImpl.class);
}
@BeforeMethod
public void initialize() {
pc.newProject();
}
@AfterMethod
public void clean() {
pc.closeCurrentProject();
}
@Test
public void testOneNodeClusteringCoefficient() {
GraphModel graphModel=GraphGenerator.generateCompleteUndirectedGraph(1);
Graph hgraph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[1];
int[] triangles = new int[1];
double[] nodeClustering = new double[1];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, false);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, Double.NaN);
}
@Test
public void testTwoConectedNodesClusteringCoefficient() {
GraphModel graphModel=GraphGenerator.generateCompleteUndirectedGraph(2);
Graph hgraph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[2];
int[] triangles = new int[2];
double[] nodeClustering = new double[2];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, false);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, Double.NaN);
}
@Test
public void testNullGraphClusteringCoefficient() {
GraphModel graphModel=GraphGenerator.generateNullUndirectedGraph(5);
Graph hgraph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[5];
int[] triangles = new int[5];
double[] nodeClustering = new double[5];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, false);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, Double.NaN);
}
@Test
public void testCompleteGraphClusteringCoefficient() {
GraphModel graphModel=GraphGenerator.generateCompleteUndirectedGraph(5);
Graph hgraph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[5];
int[] triangles = new int[5];
double[] nodeClustering = new double[5];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, false);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, 1.0);
}
@Test
public void testStarGraphClusteringCoefficient() {
GraphModel graphModel=GraphGenerator.generateStarUndirectedGraph(5);
Graph hgraph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[6];
int[] triangles = new int[6];
double[] nodeClustering = new double[6];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, false);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, 0.0);
}
@Test
public void testSpecial1UndirectedGraphClusteringCoefficient() {
GraphModel graphModel=Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph=graphModel.getUndirectedGraph();
Node node1=graphModel.factory().newNode("0");
Node node2=graphModel.factory().newNode("1");
Node node3=graphModel.factory().newNode("2");
Node node4=graphModel.factory().newNode("3");
Node node5=graphModel.factory().newNode("4");
Node node6=graphModel.factory().newNode("5");
Node node7=graphModel.factory().newNode("6");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
undirectedGraph.addNode(node6);
undirectedGraph.addNode(node7);
Edge edge12=graphModel.factory().newEdge(node1, node2, false);
Edge edge13=graphModel.factory().newEdge(node1, node3, false);
Edge edge14=graphModel.factory().newEdge(node1, node4, false);
Edge edge15=graphModel.factory().newEdge(node1, node5, false);
Edge edge16=graphModel.factory().newEdge(node1, node6, false);
Edge edge17=graphModel.factory().newEdge(node1, node7, false);
Edge edge23=graphModel.factory().newEdge(node2, node3, false);
Edge edge34=graphModel.factory().newEdge(node3, node4, false);
Edge edge45=graphModel.factory().newEdge(node4, node5, false);
Edge edge56=graphModel.factory().newEdge(node5, node6, false);
Edge edge67=graphModel.factory().newEdge(node6, node7, false);
Edge edge72=graphModel.factory().newEdge(node7, node2, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge13);
undirectedGraph.addEdge(edge14);
undirectedGraph.addEdge(edge15);
undirectedGraph.addEdge(edge16);
undirectedGraph.addEdge(edge17);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge34);
undirectedGraph.addEdge(edge45);
undirectedGraph.addEdge(edge56);
undirectedGraph.addEdge(edge67);
undirectedGraph.addEdge(edge72);
Graph hgraph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[7];
int[] triangles = new int[7];
double[] nodeClustering = new double[7];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, false);
double cl1 = nodeClustering[0];
double cl3 = nodeClustering[2];
double res3=0.667;
double diff = 0.01;
assertEquals(cl1, 0.4);
assertTrue(Math.abs(cl3-res3)<diff);
}
@Test
public void testSpecial2UndirectedGraphClusteringCoefficient() {
GraphModel graphModel=Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph=graphModel.getUndirectedGraph();
Node node1=graphModel.factory().newNode("0");
Node node2=graphModel.factory().newNode("1");
Node node3=graphModel.factory().newNode("2");
Node node4=graphModel.factory().newNode("3");
Node node5=graphModel.factory().newNode("4");
Node node6=graphModel.factory().newNode("5");
Node node7=graphModel.factory().newNode("6");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
undirectedGraph.addNode(node6);
undirectedGraph.addNode(node7);
Edge edge12=graphModel.factory().newEdge(node1, node2, false);
Edge edge23=graphModel.factory().newEdge(node2, node3, false);
Edge edge31=graphModel.factory().newEdge(node3, node1, false);
Edge edge14=graphModel.factory().newEdge(node1, node4, false);
Edge edge45=graphModel.factory().newEdge(node4, node5, false);
Edge edge51=graphModel.factory().newEdge(node5, node1, false);
Edge edge16=graphModel.factory().newEdge(node1, node6, false);
Edge edge67=graphModel.factory().newEdge(node6, node7, false);
Edge edge71=graphModel.factory().newEdge(node7, node1, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge31);
undirectedGraph.addEdge(edge14);
undirectedGraph.addEdge(edge45);
undirectedGraph.addEdge(edge51);
undirectedGraph.addEdge(edge16);
undirectedGraph.addEdge(edge67);
undirectedGraph.addEdge(edge71);
Graph hgraph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[7];
int[] triangles = new int[7];
double[] nodeClustering = new double[7];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, false);
double cl2 = nodeClustering[1];
double avClusteringCoefficient = results.get("clusteringCoefficient");
double resAv=0.8857;
double diff = 0.01;
assertEquals(cl2, 1.0);
assertTrue(Math.abs(avClusteringCoefficient-resAv)<diff);
}
@Test
public void testSpecial3UndirectedGraphClusteringCoefficient() {
GraphModel graphModel=Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph=graphModel.getUndirectedGraph();
Node node1=graphModel.factory().newNode("0");
Node node2=graphModel.factory().newNode("1");
Node node3=graphModel.factory().newNode("2");
Node node4=graphModel.factory().newNode("3");
Node node5=graphModel.factory().newNode("4");
Node node6=graphModel.factory().newNode("5");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
undirectedGraph.addNode(node6);
Edge edge12=graphModel.factory().newEdge(node1, node2, false);
Edge edge23=graphModel.factory().newEdge(node2, node3, false);
Edge edge31=graphModel.factory().newEdge(node3, node1, false);
Edge edge14=graphModel.factory().newEdge(node1, node4, false);
Edge edge25=graphModel.factory().newEdge(node2, node5, false);
Edge edge36=graphModel.factory().newEdge(node3, node6, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge31);
undirectedGraph.addEdge(edge14);
undirectedGraph.addEdge(edge25);
undirectedGraph.addEdge(edge36);;
Graph hgraph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[6];
int[] triangles = new int[6];
double[] nodeClustering = new double[6];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, false);
double cl1 = nodeClustering[0];
double res1=0.333;
double diff = 0.01;
assertTrue(Math.abs(cl1-res1)<diff);
}
@Test
public void testTriangleGraphClusteringCoefficient() {
GraphModel graphModel=GraphGenerator.generateCompleteUndirectedGraph(3);
Graph hgraph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[3];
int[] triangles = new int[3];
double[] nodeClustering = new double[3];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, false);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, 1.0);
}
@Test
public void testSpecial1DirectedGraphClusteringCoefficient() {
GraphModel graphModel=Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph=graphModel.getDirectedGraph();
Node node1=graphModel.factory().newNode("0");
Node node2=graphModel.factory().newNode("1");
Node node3=graphModel.factory().newNode("2");
Node node4=graphModel.factory().newNode("3");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
Edge edge12=graphModel.factory().newEdge(node1, node2);
Edge edge23=graphModel.factory().newEdge(node2, node3);
Edge edge24=graphModel.factory().newEdge(node2, node4);
Edge edge31=graphModel.factory().newEdge(node3, node1);
Edge edge34=graphModel.factory().newEdge(node3, node4);
Edge edge41=graphModel.factory().newEdge(node4, node1);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge24);
directedGraph.addEdge(edge31);
directedGraph.addEdge(edge34);
directedGraph.addEdge(edge41);
DirectedGraph hgraph = graphModel.getDirectedGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[4];
int[] triangles = new int[4];
double[] nodeClustering = new double[4];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, true);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, 0.5);
}
@Test
public void testTriangleDirectedGraphClusteringCoefficient() {
GraphModel graphModel=Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph=graphModel.getDirectedGraph();
Node node1=graphModel.factory().newNode("0");
Node node2=graphModel.factory().newNode("1");
Node node3=graphModel.factory().newNode("2");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
Edge edge12=graphModel.factory().newEdge(node1, node2);
Edge edge21=graphModel.factory().newEdge(node2, node1);
Edge edge23=graphModel.factory().newEdge(node2, node3);
Edge edge32=graphModel.factory().newEdge(node3, node2);
Edge edge31=graphModel.factory().newEdge(node3, node1);
Edge edge13=graphModel.factory().newEdge(node1, node3);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge21);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge32);
directedGraph.addEdge(edge31);
directedGraph.addEdge(edge13);
DirectedGraph hgraph = graphModel.getDirectedGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[3];
int[] triangles = new int[3];
double[] nodeClustering = new double[3];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, true);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, 1.);
}
@Test
public void testSpecial2DirectedGraphClusteringCoefficient() {
GraphModel graphModel=Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph=graphModel.getDirectedGraph();
Node node1=graphModel.factory().newNode("0");
Node node2=graphModel.factory().newNode("1");
Node node3=graphModel.factory().newNode("2");
Node node4=graphModel.factory().newNode("3");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
Edge edge21=graphModel.factory().newEdge(node2, node1);
Edge edge24=graphModel.factory().newEdge(node2, node4);
Edge edge31=graphModel.factory().newEdge(node3, node1);
Edge edge32=graphModel.factory().newEdge(node3, node2);
Edge edge43=graphModel.factory().newEdge(node4, node3);
directedGraph.addEdge(edge21);
directedGraph.addEdge(edge24);
directedGraph.addEdge(edge31);
directedGraph.addEdge(edge32);
directedGraph.addEdge(edge43);
DirectedGraph hgraph = graphModel.getDirectedGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[4];
int[] triangles = new int[4];
double[] nodeClustering = new double[4];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, true);
double avClusteringCoefficient = results.get("clusteringCoefficient");
double res = 0.4167;
double diff = 0.01;
assertTrue(Math.abs(avClusteringCoefficient-res)<diff);
}
@Test
public void testTriangleNonCompleteDirectedGraphClusteringCoefficient() {
GraphModel graphModel=Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph=graphModel.getDirectedGraph();
Node node1=graphModel.factory().newNode("0");
Node node2=graphModel.factory().newNode("1");
Node node3=graphModel.factory().newNode("2");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
Edge edge12=graphModel.factory().newEdge(node1, node2);
Edge edge21=graphModel.factory().newEdge(node2, node1);
Edge edge23=graphModel.factory().newEdge(node2, node3);
Edge edge32=graphModel.factory().newEdge(node3, node2);
Edge edge13=graphModel.factory().newEdge(node1, node3);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge21);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge32);
directedGraph.addEdge(edge13);
DirectedGraph hgraph = graphModel.getDirectedGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[3];
int[] triangles = new int[3];
double[] nodeClustering = new double[3];
HashMap<String, Double> results = cc.computeClusteringCoefficient(hgraph, network, triangles, nodeClustering, true);
double avClusteringCoefficient = results.get("clusteringCoefficient");
double res = 0.833;
double diff = 0.01;
assertTrue(Math.abs(avClusteringCoefficient-res)<diff);
}
}
@@ -0,0 +1,451 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.statistics.plugin;
import java.util.HashMap;
import java.util.LinkedList;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.UndirectedGraph;
import org.gephi.project.api.ProjectController;
import org.gephi.project.impl.ProjectControllerImpl;
import org.openide.util.Lookup;
import static org.testng.Assert.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
*
* @author Anna
*/
public class ConnectedComponentsNGTest {
private ProjectController pc;
@BeforeClass
public void setUp() {
pc = Lookup.getDefault().lookup(ProjectControllerImpl.class);
}
@BeforeMethod
public void initialize() {
pc.newProject();
}
@AfterMethod
public void clean() {
pc.closeCurrentProject();
}
@Test
public void testComputeOneNodeWeeklyConnectedComponents() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
UndirectedGraph graph = graphModel.getUndirectedGraph();
Node n = graph.getNode("0");
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
indicies.put(n, 0);
LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
assertEquals(components.size(), 1);
}
@Test
public void testNullGraphWeeklyConnectedComponents() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
UndirectedGraph graph = graphModel.getUndirectedGraph();
Node n0 = graph.getNode("0");
Node n1 = graph.getNode("1");
Node n2 = graph.getNode("2");
Node n3 = graph.getNode("3");
Node n4 = graph.getNode("4");
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
indicies.put(n0, 0);
indicies.put(n1, 1);
indicies.put(n2, 2);
indicies.put(n3, 3);
indicies.put(n4, 4);
LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
assertEquals(components.size(), 5);
}
@Test
public void testComputeBarbellGraphWeeklyConnectedComponents() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(4);
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node[] nodes = new Node[4];
for (int i = 0; i < 4; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) (i + 4)).toString());
nodes[i] = currentNode;
undirectedGraph.addNode(currentNode);
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j], false);
undirectedGraph.addEdge(currentEdge);
}
}
Edge currentEdge = graphModel.factory().newEdge(undirectedGraph.getNode("0"), undirectedGraph.getNode("5"), false);
undirectedGraph.addEdge(currentEdge);
UndirectedGraph graph = graphModel.getUndirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
assertEquals(components.size(), 1);
}
@Test
public void testSpecial1UndirectedGraphConnectedComponents() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
Edge edge14 = graphModel.factory().newEdge(node1, node4, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge25 = graphModel.factory().newEdge(node2, node5, false);
Edge edge35 = graphModel.factory().newEdge(node3, node5, false);
Edge edge43 = graphModel.factory().newEdge(node4, node3, false);
Edge edge51 = graphModel.factory().newEdge(node5, node1, false);
Edge edge54 = graphModel.factory().newEdge(node5, node4, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge14);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge25);
undirectedGraph.addEdge(edge35);
undirectedGraph.addEdge(edge43);
undirectedGraph.addEdge(edge51);
undirectedGraph.addEdge(edge54);
UndirectedGraph graph = graphModel.getUndirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
assertEquals(components.size(), 1);
}
@Test
public void testSpecial2UndirectedGraphConnectedComponents() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
Node node7 = graphModel.factory().newNode("6");
Node node8 = graphModel.factory().newNode("7");
Node node9 = graphModel.factory().newNode("8");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
undirectedGraph.addNode(node6);
undirectedGraph.addNode(node7);
undirectedGraph.addNode(node8);
undirectedGraph.addNode(node9);
Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge45 = graphModel.factory().newEdge(node4, node5, false);
Edge edge56 = graphModel.factory().newEdge(node5, node6, false);
Edge edge64 = graphModel.factory().newEdge(node6, node4, false);
Edge edge75 = graphModel.factory().newEdge(node7, node5, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge45);
undirectedGraph.addEdge(edge56);
undirectedGraph.addEdge(edge64);
undirectedGraph.addEdge(edge75);
UndirectedGraph graph = graphModel.getUndirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
int componentNumber3 = c.getComponentNumber(components, node3);
int componentNumber4 = c.getComponentNumber(components, node4);
int componentNumber7 = c.getComponentNumber(components, node7);
int componentNumber8 = c.getComponentNumber(components, node8);
assertEquals(components.size(), 4);
assertEquals(componentNumber4, componentNumber7);
assertNotEquals(componentNumber3, componentNumber8);
}
@Test
public void testDirectedPathGraphConnectedComponents() {
GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(4);
DirectedGraph graph = graphModel.getDirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> components = c.top_tarjans(graph, indicies);
assertEquals(components.size(), 4);
}
@Test
public void testDirectedCyclicGraphConnectedComponents() {
GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(5);
DirectedGraph graph = graphModel.getDirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> components = c.top_tarjans(graph, indicies);
assertEquals(components.size(), 1);
}
@Test
public void testSpecial1DirectedGraphConnectedComponents() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge14 = graphModel.factory().newEdge(node1, node4);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge25 = graphModel.factory().newEdge(node2, node5);
Edge edge35 = graphModel.factory().newEdge(node3, node5);
Edge edge43 = graphModel.factory().newEdge(node4, node3);
Edge edge51 = graphModel.factory().newEdge(node5, node1);
Edge edge54 = graphModel.factory().newEdge(node5, node4);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge14);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge25);
directedGraph.addEdge(edge35);
directedGraph.addEdge(edge43);
directedGraph.addEdge(edge51);
directedGraph.addEdge(edge54);
DirectedGraph graph = graphModel.getDirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> components = c.top_tarjans(graph, indicies);
assertEquals(components.size(), 1);
}
@Test
public void testSpecial2DirectedGraphConnectedComponents() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge14 = graphModel.factory().newEdge(node1, node4);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge25 = graphModel.factory().newEdge(node2, node5);
Edge edge35 = graphModel.factory().newEdge(node3, node5);
Edge edge43 = graphModel.factory().newEdge(node4, node3);
Edge edge54 = graphModel.factory().newEdge(node5, node4);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge14);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge25);
directedGraph.addEdge(edge35);
directedGraph.addEdge(edge43);
directedGraph.addEdge(edge54);
DirectedGraph graph = graphModel.getDirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> weeklyConnectedComponents = c.computeWeeklyConnectedComponents(graph, indicies);
LinkedList<LinkedList<Node>> stronglyConnectedComponents = c.top_tarjans(graph, indicies);
int componentNumber1 = c.getComponentNumber(stronglyConnectedComponents, node1);
int componentNumber3 = c.getComponentNumber(stronglyConnectedComponents, node3);
int componentNumber4 = c.getComponentNumber(stronglyConnectedComponents, node4);
int componentNumber5 = c.getComponentNumber(stronglyConnectedComponents, node5);
assertEquals(stronglyConnectedComponents.size(), 3);
assertEquals(weeklyConnectedComponents.size(), 1);
assertEquals(componentNumber3, componentNumber5);
assertNotEquals(componentNumber1, componentNumber4);
}
@Test
public void testSpecial3DirectedGraphConnectedComponents() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
Node node7 = graphModel.factory().newNode("6");
Node node8 = graphModel.factory().newNode("7");
Node node9 = graphModel.factory().newNode("8");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
directedGraph.addNode(node6);
directedGraph.addNode(node7);
directedGraph.addNode(node8);
directedGraph.addNode(node9);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge45 = graphModel.factory().newEdge(node4, node5);
Edge edge56 = graphModel.factory().newEdge(node5, node6);
Edge edge64 = graphModel.factory().newEdge(node6, node4);
Edge edge75 = graphModel.factory().newEdge(node7, node5);
Edge edge89 = graphModel.factory().newEdge(node8, node9);
Edge edge98 = graphModel.factory().newEdge(node9, node8);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge45);
directedGraph.addEdge(edge56);
directedGraph.addEdge(edge64);
directedGraph.addEdge(edge75);
directedGraph.addEdge(edge89);
directedGraph.addEdge(edge98);
DirectedGraph graph = graphModel.getDirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> stronglyConnectedComponents = c.top_tarjans(graph, indicies);
assertEquals(stronglyConnectedComponents.size(), 6);
}
@Test
public void testSpecial4DirectedGraphConnectedComponents() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
Node node7 = graphModel.factory().newNode("6");
Node node8 = graphModel.factory().newNode("7");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
directedGraph.addNode(node6);
directedGraph.addNode(node7);
directedGraph.addNode(node8);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge34 = graphModel.factory().newEdge(node3, node4);
Edge edge41 = graphModel.factory().newEdge(node4, node1);
Edge edge56 = graphModel.factory().newEdge(node5, node6);
Edge edge67 = graphModel.factory().newEdge(node6, node7);
Edge edge78 = graphModel.factory().newEdge(node7, node8);
Edge edge85 = graphModel.factory().newEdge(node8, node5);
Edge edge45 = graphModel.factory().newEdge(node4, node5);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge34);
directedGraph.addEdge(edge41);
directedGraph.addEdge(edge56);
directedGraph.addEdge(edge67);
directedGraph.addEdge(edge78);
directedGraph.addEdge(edge85);
directedGraph.addEdge(edge45);
DirectedGraph graph = graphModel.getDirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> stronglyConnectedComponents = c.top_tarjans(graph, indicies);
int componentNumber1 = c.getComponentNumber(stronglyConnectedComponents, node1);
int componentNumber5 = c.getComponentNumber(stronglyConnectedComponents, node5);
assertEquals(stronglyConnectedComponents.size(), 2);
assertNotEquals(componentNumber1, componentNumber5);
}
@Test
public void testSpecial2UndirectedGraphGiantComponent() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
Node node7 = graphModel.factory().newNode("6");
Node node8 = graphModel.factory().newNode("7");
Node node9 = graphModel.factory().newNode("8");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
undirectedGraph.addNode(node6);
undirectedGraph.addNode(node7);
undirectedGraph.addNode(node8);
undirectedGraph.addNode(node9);
Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge45 = graphModel.factory().newEdge(node4, node5, false);
Edge edge56 = graphModel.factory().newEdge(node5, node6, false);
Edge edge64 = graphModel.factory().newEdge(node6, node4, false);
Edge edge75 = graphModel.factory().newEdge(node7, node5, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge45);
undirectedGraph.addEdge(edge56);
undirectedGraph.addEdge(edge64);
undirectedGraph.addEdge(edge75);
UndirectedGraph graph = graphModel.getUndirectedGraph();
ConnectedComponents c = new ConnectedComponents();
HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
c.fillComponentSizeList(components);
int giantComponent = c.getGiantComponent();
int componentNumber5 = c.getComponentNumber(components, node5);
assertEquals(giantComponent, componentNumber5);
}
}
@@ -0,0 +1,168 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.statistics.plugin;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.project.api.ProjectController;
import org.gephi.project.impl.ProjectControllerImpl;
import org.openide.util.Lookup;
import static org.testng.Assert.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
*
* @author Anna
*/
public class DegreeNGTest {
private ProjectController pc;
@BeforeClass
public void setUp() {
pc = Lookup.getDefault().lookup(ProjectControllerImpl.class);
}
@BeforeMethod
public void initialize() {
pc.newProject();
}
@AfterMethod
public void clean() {
pc.closeCurrentProject();
}
@Test
public void testOneNodeDegree() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
Graph graph = graphModel.getGraph();
Node n = graph.getNode("0");
Degree d = new Degree();
int degree = d.calculateDegree(graph, n);
assertEquals(degree, 0);
}
@Test
public void testNullGraphDegree() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
Graph graph = graphModel.getGraph();
Node n = graph.getNode("1");
Degree d = new Degree();
int degree = d.calculateDegree(graph, n);
double avDegree = d.calculateAverageDegree(graph, false, false);
assertEquals(degree, 0);
assertEquals(avDegree, 0.0);
}
@Test
public void testCompleteGraphDegree() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(5);
Graph graph = graphModel.getGraph();
Node n = graph.getNode("2");
Degree d = new Degree();
int degree = d.calculateDegree(graph, n);
assertEquals(degree, 4);
}
@Test
public void testStarGraphDegree() {
GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(5);
Graph graph = graphModel.getGraph();
Node n1 = graph.getNode("0");
Node n2 = graph.getNode("1");
Degree d = new Degree();
int degree1 = d.calculateDegree(graph, n1);
int degree2 = d.calculateDegree(graph, n2);
double avDegree = d.calculateAverageDegree(graph, false, false);
double expectedAvDegree = 1.6667;
double diff = Math.abs(avDegree - expectedAvDegree);
assertEquals(degree1, 5);
assertEquals(degree2, 1);
assertTrue(diff < 0.001);
}
@Test
public void testCyclicGraphDegree() {
GraphModel graphModel = GraphGenerator.generateCyclicUndirectedGraph(5);
Graph graph = graphModel.getGraph();
Node n = graph.getNode("3");
Degree d = new Degree();
int degree = d.calculateDegree(graph, n);
double avDegree = d.calculateAverageDegree(graph, false, false);
assertEquals(degree, 2);
assertEquals(avDegree, 2.0);
}
@Test
public void testDirectedPathGraphDegree() {
GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(2);
DirectedGraph graph = graphModel.getDirectedGraph();
Node n1 = graph.getNode("0");
Node n2 = graph.getNode("1");
Degree d = new Degree();
int inDegree1 = d.calculateInDegree(graph, n1);
int inDegree2 = d.calculateInDegree(graph, n2);
int outDegree1 = d.calculateOutDegree(graph, n1);
double avDegree = d.calculateAverageDegree(graph, true, false);
assertEquals(inDegree1, 0);
assertEquals(inDegree2, 1);
assertEquals(outDegree1, 1);
assertEquals(avDegree, 1.0);
}
@Test
public void testDirectedCyclicGraphDegree() {
GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(5);
DirectedGraph graph = graphModel.getDirectedGraph();
Node n1 = graph.getNode("0");
Node n3 = graph.getNode("2");
Node n5 = graph.getNode("4");
Degree d = new Degree();
int inDegree3 = d.calculateInDegree(graph, n3);
int degree1 = d.calculateDegree(graph, n1);
int outDegree5 = d.calculateOutDegree(graph, n5);
double avDegree = d.calculateAverageDegree(graph, true, false);
assertEquals(inDegree3, 1);
assertEquals(degree1, 2);
assertEquals(outDegree5, 1);
assertEquals(avDegree, 2.0);
}
@Test
public void testDirectedStarOutGraphDegree() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node firstNode = graphModel.factory().newNode("0");
directedGraph.addNode(firstNode);
for (int i = 1; i <= 5; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
directedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(firstNode, currentNode);
directedGraph.addEdge(currentEdge);
}
DirectedGraph graph = graphModel.getDirectedGraph();
Node n1 = graph.getNode("0");
Node n3 = graph.getNode("2");
Degree d = new Degree();
int inDegree1 = d.calculateInDegree(graph, n1);
int outDegree1 = d.calculateOutDegree(graph, n1);
int degree3 = d.calculateDegree(graph, n3);
assertEquals(inDegree1, 0);
assertEquals(outDegree1, 5);
assertEquals(degree3, 1);
}
}
@@ -0,0 +1,22 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.statistics.plugin;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
/**
*
* @author Anna
*/
public class EdgeWrapperNGTest {
public EdgeWrapperNGTest() {
}
@Test
public void testSomeMethod() {
}
}
@@ -0,0 +1,437 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.statistics.plugin;
import java.util.HashMap;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.UndirectedGraph;
import org.gephi.project.api.ProjectController;
import org.gephi.project.impl.ProjectControllerImpl;
import org.openide.util.Lookup;
import static org.testng.Assert.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
*
* @author Anna
*/
public class EigenvectorCentralityNGTest {
private ProjectController pc;
@BeforeClass
public void setUp() {
pc = Lookup.getDefault().lookup(ProjectControllerImpl.class);
}
@BeforeMethod
public void initialize() {
pc.newProject();
}
@AfterMethod
public void clean() {
pc.closeCurrentProject();
}
@Test
public void testOneNodeEigenvectorCentrality() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[1];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, false, 100);
Node n1 = hgraph.getNode("0");
int index = invIndicies.get(n1);
double ec1 = centralities[index];
assertEquals(ec1, 0.0);
}
@Test
public void testTwoConnectedNodesEigenvectorCentrality() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(2);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[2];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, false, 100);
Node n1 = hgraph.getNode("0");
int index = invIndicies.get(n1);
double ec1 = centralities[index];
assertEquals(ec1, 1.0);
}
@Test
public void testNullGraphEigenvectorCentrality() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[5];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, false, 100);
Node n2 = hgraph.getNode("1");
int index = invIndicies.get(n2);
double ec2 = centralities[index];
assertEquals(ec2, 0.0);
}
@Test
public void testCompleteUndirectedGraphEigenvectorCentrality() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(5);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[5];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, false, 100);
Node n1 = hgraph.getNode("0");
Node n3 = hgraph.getNode("2");
int index1 = invIndicies.get(n1);
int index3 = invIndicies.get(n3);
double ec1 = centralities[index1];
double ec3 = centralities[index3];
assertEquals(ec1, 1.0);
assertEquals(ec3, 1.0);
}
@Test
public void testSpecial1UndirectedGraphEigenvectorCentrlity() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge34 = graphModel.factory().newEdge(node3, node4, false);
Edge edge13 = graphModel.factory().newEdge(node1, node3, false);
Edge edge24 = graphModel.factory().newEdge(node2, node4, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge34);
undirectedGraph.addEdge(edge13);
undirectedGraph.addEdge(edge24);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[4];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, false, 100);
int index1 = invIndicies.get(node1);
int index2 = invIndicies.get(node2);
int index3 = invIndicies.get(node3);
double ec1 = centralities[index1];
double ec2 = centralities[index2];
double ec3 = centralities[index3];
assertEquals(ec2, ec3);
assertNotEquals(ec1, ec2);
assertEquals(ec3, 1.0);
}
@Test
public void testSpecial2UndirectedGraphEigenvectorCentrlity() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
Edge edge13 = graphModel.factory().newEdge(node1, node3, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge34 = graphModel.factory().newEdge(node3, node4, false);
Edge edge45 = graphModel.factory().newEdge(node4, node5, false);
undirectedGraph.addEdge(edge13);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge34);
undirectedGraph.addEdge(edge45);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[5];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, false, 100);
int index2 = invIndicies.get(node2);
int index3 = invIndicies.get(node3);
int index4 = invIndicies.get(node4);
double ec2 = centralities[index2];
double ec3 = centralities[index3];
double ec4 = centralities[index4];
double res = 0.765;
double diff = 0.01;
assertTrue(ec2 < ec3);
assertTrue(Math.abs(ec4 - res) < diff);
}
@Test
public void testSpecial3UndirectedGraphEigenvectorCentrlity() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
Edge edge11 = graphModel.factory().newEdge(node1, node1, false);
Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge33 = graphModel.factory().newEdge(node3, node3, false);
undirectedGraph.addEdge(edge11);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge33);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[3];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, false, 100);
int index1 = invIndicies.get(node1);
int index2 = invIndicies.get(node2);
double ec1 = centralities[index1];
double ec2 = centralities[index2];
assertEquals(ec1, ec2);
}
@Test
public void testCyclicDirectedGraphEigenvectorCentrality() {
GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(3);
DirectedGraph hgraph = graphModel.getDirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[3];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, true, 100);
Node n1 = hgraph.getNode("0");
int index1 = invIndicies.get(n1);
double ec1 = centralities[index1];
assertEquals(ec1, 1.0);
}
@Test
public void testSpecial1DirectedEigenvectorCentrality() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge31 = graphModel.factory().newEdge(node3, node1);
Edge edge42 = graphModel.factory().newEdge(node4, node2);
Edge edge54 = graphModel.factory().newEdge(node5, node4);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge31);
directedGraph.addEdge(edge42);
directedGraph.addEdge(edge54);
DirectedGraph hgraph = graphModel.getDirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[5];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, true, 1000);
int index1 = invIndicies.get(node1);
int index2 = invIndicies.get(node2);
int index4 = invIndicies.get(node4);
int index5 = invIndicies.get(node5);
double ec1 = centralities[index1];
double ec2 = centralities[index2];
double ec4 = centralities[index4];
double ec5 = centralities[index5];
double diff = 0.01;
double res0 = 0.;
double res1 = 1.;
assertEquals(ec5, 0.0);
assertTrue(Math.abs(ec4 - res0) < diff);
assertTrue(Math.abs(ec1 - res1) < diff);
assertTrue(Math.abs(ec1 - ec2) < diff);
}
@Test
public void testDirectedStarOutEigenvectorCentrality() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node firstNode = graphModel.factory().newNode("0");
directedGraph.addNode(firstNode);
for (int i = 1; i <= 5; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
directedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(firstNode, currentNode);
directedGraph.addEdge(currentEdge);
}
DirectedGraph hgraph = graphModel.getDirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[6];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, true, 100);
Node n1 = hgraph.getNode("0");
Node n2 = hgraph.getNode("1");
int index1 = invIndicies.get(n1);
int index2 = invIndicies.get(n2);
double ec1 = centralities[index1];
double ec2 = centralities[index2];
assertEquals(ec1, 0.0);
assertEquals(ec2, 1.0);
}
@Test
public void testPathDirectedGraphEigenvectorCentrality() {
GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(4);
DirectedGraph hgraph = graphModel.getDirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[4];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, true, 100);
Node n1 = hgraph.getNode("0");
Node n4 = hgraph.getNode("3");
int index1 = invIndicies.get(n1);
int index4 = invIndicies.get(n4);
double ec1 = centralities[index1];
double ec4 = centralities[index4];
assertEquals(ec1, 0.0);
assertEquals(ec4, 1.0);
}
}
@@ -0,0 +1,195 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.statistics.plugin;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.UndirectedGraph;
import org.gephi.project.api.ProjectController;
import org.gephi.project.impl.ProjectControllerImpl;
import org.openide.util.Lookup;
import static org.testng.Assert.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
*
* @author Anna
*/
public class GraphDensityNGTest {
private ProjectController pc;
@BeforeClass
public void setUp() {
pc = Lookup.getDefault().lookup(ProjectControllerImpl.class);
}
@BeforeMethod
public void initialize() {
pc.newProject();
}
@AfterMethod
public void clean() {
pc.closeCurrentProject();
}
@Test
public void testOneNodeDensity() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, Double.NaN);
}
@Test
public void testTwoConnectedNodesDensity() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(2);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, 1.0);
}
@Test
public void testNullGraphDensity() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, 0.0);
}
@Test
public void testCompleteGraphDensity() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(5);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, 1.0);
}
@Test
public void testCyclicGraphDensity() {
GraphModel graphModel = GraphGenerator.generateCyclicUndirectedGraph(6);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, 0.4);
}
@Test
public void testSelfLoopNodeDensity() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node currentNode = graphModel.factory().newNode("0");
undirectedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(currentNode, currentNode, false);
undirectedGraph.addEdge(currentEdge);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, Double.POSITIVE_INFINITY);
}
@Test
public void testCompleteGraphWithSelfLoopsDensity() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(3);
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node n1 = undirectedGraph.getNode("0");
Node n2 = undirectedGraph.getNode("1");
Node n3 = undirectedGraph.getNode("2");
Edge currentEdge = graphModel.factory().newEdge(n1, n1, false);
undirectedGraph.addEdge(currentEdge);
currentEdge = graphModel.factory().newEdge(n2, n2, false);
undirectedGraph.addEdge(currentEdge);
currentEdge = graphModel.factory().newEdge(n3, n3, false);
undirectedGraph.addEdge(currentEdge);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, 2.0);
}
@Test
public void testTwoCompleteGraphsDensity() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(4);
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node[] nodes = new Node[4];
for (int i = 0; i < 4; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) (i + 4)).toString());
nodes[i] = currentNode;
undirectedGraph.addNode(currentNode);
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j], false);
undirectedGraph.addEdge(currentEdge);
}
}
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
double expectedAvDegree = 0.4286;
double diff = Math.abs(density - expectedAvDegree);
assertTrue(diff < 0.01);
}
@Test
public void testDirectedPathGraphDensity() {
GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(2);
DirectedGraph graph = graphModel.getDirectedGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, true);
assertEquals(density, 0.5);
}
@Test
public void testDirectedCyclicGraphDensity() {
GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(5);
DirectedGraph graph = graphModel.getDirectedGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, true);
assertEquals(density, 0.25);
}
@Test
public void testDirectedCompleteGraphDensity() {
GraphModel graphModel = GraphGenerator.generateCompleteDirectedGraph(5);
DirectedGraph graph = graphModel.getDirectedGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, true);
assertEquals(density, 1.0);
}
@Test
public void testDirectedCompleteGraphWithSelfLoopsDensity() {
GraphModel graphModel = GraphGenerator.generateCompleteDirectedGraph(3);
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node n1 = directedGraph.getNode("0");
Node n2 = directedGraph.getNode("1");
Node n3 = directedGraph.getNode("2");
Edge currentEdge = graphModel.factory().newEdge(n1, n1);
directedGraph.addEdge(currentEdge);
currentEdge = graphModel.factory().newEdge(n2, n2);
directedGraph.addEdge(currentEdge);
currentEdge = graphModel.factory().newEdge(n3, n3);
directedGraph.addEdge(currentEdge);
DirectedGraph graph = graphModel.getDirectedGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, true);
assertEquals(density, 1.5);
}
}
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
@@ -0,0 +1,174 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.statistics.plugin;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.UndirectedGraph;
import org.openide.util.Lookup;
/**
*
* @author mbastian
*/
public class GraphGenerator {
public static GraphModel generateNullUndirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
for (int i = 0; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
undirectedGraph.addNode(currentNode);
}
return graphModel;
}
public static GraphModel generateCompleteUndirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node[] nodes = new Node[n];
for (int i = 0; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
nodes[i] = currentNode;
undirectedGraph.addNode(currentNode);
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j], false);
undirectedGraph.addEdge(currentEdge);
}
}
return graphModel;
}
public static GraphModel generatePathUndirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
if (n <= 0) {
return graphModel;
}
Node firstNode = graphModel.factory().newNode("0");
undirectedGraph.addNode(firstNode);
Node prevNode = firstNode;
for (int i = 1; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
undirectedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(prevNode, currentNode, false);
undirectedGraph.addEdge(currentEdge);
prevNode = currentNode;
}
return graphModel;
}
public static GraphModel generateCyclicUndirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
if (n <= 0) {
return graphModel;
}
Node firstNode = graphModel.factory().newNode("0");
undirectedGraph.addNode(firstNode);
Node prevNode = firstNode;
for (int i = 1; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
undirectedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(prevNode, currentNode, false);
undirectedGraph.addEdge(currentEdge);
prevNode = currentNode;
}
Edge currentEdge = graphModel.factory().newEdge(prevNode, firstNode, false);
undirectedGraph.addEdge(currentEdge);
return graphModel;
}
//generates graph from n+1 nodes
public static GraphModel generateStarUndirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node firstNode = graphModel.factory().newNode("0");
undirectedGraph.addNode(firstNode);
for (int i = 1; i <= n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
undirectedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(firstNode, currentNode, false);
undirectedGraph.addEdge(currentEdge);
}
return graphModel;
}
public static GraphModel generateNullDirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
for (int i = 0; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
directedGraph.addNode(currentNode);
}
return graphModel;
}
public static GraphModel generateCompleteDirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node[] nodes = new Node[n];
for (int i = 0; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
nodes[i] = currentNode;
directedGraph.addNode(currentNode);
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j]);
directedGraph.addEdge(currentEdge);
currentEdge = graphModel.factory().newEdge(nodes[j], nodes[i]);
directedGraph.addEdge(currentEdge);
}
}
return graphModel;
}
public static GraphModel generatePathDirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
if (n <= 0) {
return graphModel;
}
Node firstNode = graphModel.factory().newNode("0");
directedGraph.addNode(firstNode);
Node prevNode = firstNode;
for (int i = 1; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
directedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(prevNode, currentNode);
directedGraph.addEdge(currentEdge);
prevNode = currentNode;
}
return graphModel;
}
public static GraphModel generateCyclicDirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
if (n <= 0) {
return graphModel;
}
Node firstNode = graphModel.factory().newNode("0");
directedGraph.addNode(firstNode);
Node prevNode = firstNode;
for (int i = 1; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
directedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(prevNode, currentNode);
directedGraph.addEdge(currentEdge);
prevNode = currentNode;
}
Edge currentEdge = graphModel.factory().newEdge(prevNode, firstNode);
directedGraph.addEdge(currentEdge);
return graphModel;
}
}
@@ -0,0 +1,460 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.statistics.plugin;
import java.util.HashMap;
import java.util.LinkedList;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.UndirectedGraph;
import org.gephi.project.api.ProjectController;
import org.gephi.project.impl.ProjectControllerImpl;
import org.openide.util.Lookup;
import static org.testng.Assert.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
*
* @author Anna
*/
public class HitsNGTest {
private ProjectController pc;
@BeforeClass
public void setUp() {
pc = Lookup.getDefault().lookup(ProjectControllerImpl.class);
}
@BeforeMethod
public void initialize() {
pc.newProject();
}
@AfterMethod
public void clean() {
pc.closeCurrentProject();
}
@Test
public void testOneNodeHits() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
Graph hgraph = graphModel.getUndirectedGraph();
Hits hit = new Hits();
double[] authority = new double[1];
double[] hubs = new double[1];
HashMap<Node, Integer> indicies = hit.createIndiciesMap(hgraph);
hit.calculateHits(hgraph, hubs, authority, indicies, false, 0.01);
Node n1 = hgraph.getNode("0");
int index = indicies.get(n1);
double hub1 = hubs[index];
double auth1 = authority[index];
assertEquals(hub1, 1.0);
assertEquals(auth1, 1.0);
}
@Test
public void testTwoConnectedNodesHits() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(2);
Graph hgraph = graphModel.getUndirectedGraph();
Hits hit = new Hits();
double[] authority = new double[2];
double[] hubs = new double[2];
HashMap<Node, Integer> indicies = hit.createIndiciesMap(hgraph);
hit.calculateHits(hgraph, hubs, authority, indicies, false, 0.01);
Node n1 = hgraph.getNode("0");
Node n2 = hgraph.getNode("1");
int index1 = indicies.get(n1);
int index2 = indicies.get(n2);
double hub1 = hubs[index1];
double auth2 = authority[index2];
assertEquals(hub1, 0.5);
assertEquals(auth2, 0.5);
}
@Test
public void testNullGraphHits() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
Graph hgraph = graphModel.getUndirectedGraph();
Hits hit = new Hits();
double[] authority = new double[5];
double[] hubs = new double[5];
HashMap<Node, Integer> indicies = hit.createIndiciesMap(hgraph);
hit.calculateHits(hgraph, hubs, authority,indicies, false, 0.01);
Node n2 = hgraph.getNode("1");
Node n3 = hgraph.getNode("2");
int index2 = indicies.get(n2);
int index3 = indicies.get(n3);
double hub2 = hubs[index2];
double auth3 = authority[index3];
assertEquals(hub2, 0.2);
assertEquals(auth3, 0.2);
}
@Test
public void testCompleteGraphHits() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(5);
Graph hgraph = graphModel.getUndirectedGraph();
Hits hit = new Hits();
double[] authority = new double[5];
double[] hubs = new double[5];
HashMap<Node, Integer> indicies = hit.createIndiciesMap(hgraph);
hit.calculateHits(hgraph, hubs, authority, indicies, false, 0.01);
Node n1 = hgraph.getNode("0");
Node n5 = hgraph.getNode("4");
int index1 = indicies.get(n1);
int index5 = indicies.get(n5);
double hub1 = hubs[index1];
double auth5 = authority[index5];
assertEquals(hub1, 0.2);
assertEquals(auth5, 0.2);
}
@Test
public void testStarGraphHits() {
GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(5);
Graph hgraph = graphModel.getUndirectedGraph();
Hits hit = new Hits();
double[] authority = new double[6];
double[] hubs = new double[6];
HashMap<Node, Integer> indicies = hit.createIndiciesMap(hgraph);
hit.calculateHits(hgraph, hubs, authority, indicies, false, 0.01);
Node n1 = hgraph.getNode("0");
Node n3 = hgraph.getNode("2");
Node n4 = hgraph.getNode("3");
int index1 = indicies.get(n1);
int index3 = indicies.get(n3);
int index4 = indicies.get(n4);
double hub1 = hubs[index1];
double hub3 = hubs[index3];
double auth1 = authority[index1];
double auth4 = authority[index4];
boolean b1 = hub1 > hub3;
boolean b2 = auth1 > auth4;
assertTrue(b1);
assertTrue(b2);
}
@Test
public void testGraphWithSelfLoopsHits() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge11 = graphModel.factory().newEdge(node1, node1, false);
Edge edge33 = graphModel.factory().newEdge(node3, node3, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge11);
undirectedGraph.addEdge(edge33);
Graph hgraph = graphModel.getUndirectedGraph();
Hits hit = new Hits();
HashMap<Node, Integer> indicies = hit.createIndiciesMap(hgraph);
double[] authority = new double[3];
double[] hubs = new double[3];
hit.calculateHits(hgraph, hubs, authority, indicies, false, 0.01);
Node n1 = hgraph.getNode("0");
Node n2 = hgraph.getNode("1");
int index1 = indicies.get(n1);
int index2 = indicies.get(n2);
double hub1 = hubs[index1];
double hub2 = hubs[index2];
boolean b1 = hub2 > hub1;
assertTrue(b1);
}
@Test
public void testDirectedSpecial1GraphHits() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
Edge edge14 = graphModel.factory().newEdge(node1, node4);
Edge edge15 = graphModel.factory().newEdge(node1, node5);
Edge edge24 = graphModel.factory().newEdge(node2, node4);
Edge edge25 = graphModel.factory().newEdge(node2, node5);
Edge edge34 = graphModel.factory().newEdge(node3, node4);
Edge edge35 = graphModel.factory().newEdge(node3, node5);
directedGraph.addEdge(edge14);
directedGraph.addEdge(edge15);
directedGraph.addEdge(edge24);
directedGraph.addEdge(edge25);
directedGraph.addEdge(edge34);
directedGraph.addEdge(edge35);
DirectedGraph hgraph = graphModel.getDirectedGraph();
Hits hit = new Hits();
double[] authority = new double[5];
double[] hubs = new double[5];
HashMap<Node, Integer> indicies = hit.createIndiciesMap(hgraph);
hit.calculateHits(hgraph, hubs, authority, indicies, true, 0.01);
Node n1 = hgraph.getNode("0");
Node n2 = hgraph.getNode("1");
Node n4 = hgraph.getNode("3");
Node n5 = hgraph.getNode("4");
int index1 = indicies.get(n1);
int index2 = indicies.get(n2);
int index4 = indicies.get(n4);
int index5 = indicies.get(n5);
double hub1 = hubs[index1];
double hub4 = hubs[index4];
double auth2 = authority[index2];
double auth5 = authority[index5];
double res = 0.333;
double diff = 0.01;
assertTrue(Math.abs(hub1 - res) < diff);
assertEquals(hub4, 0.);
assertEquals(auth2, 0.);
assertEquals(auth5, 0.5);
}
@Test
public void testDirectedStarOutGraphHits() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node firstNode = graphModel.factory().newNode("0");
directedGraph.addNode(firstNode);
for (int i = 1; i <= 5; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
directedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(firstNode, currentNode);
directedGraph.addEdge(currentEdge);
}
DirectedGraph hgraph = graphModel.getDirectedGraph();
Hits hit = new Hits();
double[] authority = new double[6];
double[] hubs = new double[6];
HashMap<Node, Integer> indicies = hit.createIndiciesMap(hgraph);
hit.calculateHits(hgraph, hubs, authority, indicies, true, 0.01);
Node n1 = hgraph.getNode("0");
Node n3 = hgraph.getNode("2");
int index1 = indicies.get(n1);
int index3 = indicies.get(n3);
double hub1 = hubs[index1];
double hub3 = hubs[index3];
double auth1 = authority[index1];
double auth3 = authority[index3];
double res = 0.146;
double diff = 0.01;
assertEquals(hub1, 1.);
assertEquals(auth1, 0.);
assertEquals(hub3, 0.);
assertEquals(auth3, 0.2);
}
@Test
public void testDirectedSpecial2GraphHits() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
directedGraph.addNode(node6);
Edge edge21 = graphModel.factory().newEdge(node2, node1);
Edge edge31 = graphModel.factory().newEdge(node3, node1);
Edge edge41 = graphModel.factory().newEdge(node4, node1);
Edge edge51 = graphModel.factory().newEdge(node5, node1);
Edge edge36 = graphModel.factory().newEdge(node3, node6);
Edge edge46 = graphModel.factory().newEdge(node4, node6);
Edge edge56 = graphModel.factory().newEdge(node5, node6);
directedGraph.addEdge(edge21);
directedGraph.addEdge(edge31);
directedGraph.addEdge(edge41);
directedGraph.addEdge(edge51);
directedGraph.addEdge(edge36);
directedGraph.addEdge(edge46);
directedGraph.addEdge(edge56);
DirectedGraph hgraph = graphModel.getDirectedGraph();
Hits hit = new Hits();
double[] authority = new double[6];
double[] hubs = new double[6];
HashMap<Node, Integer> indicies = hit.createIndiciesMap(hgraph);
hit.calculateHits(hgraph, hubs, authority, indicies, true, 0.01);
int index1 = indicies.get(node1);
int index2 = indicies.get(node2);
int index3 = indicies.get(node3);
int index5 = indicies.get(node5);
int index6 = indicies.get(node6);
double hub2 = hubs[index2];
double hub3 = hubs[index3];
double hub5 = hubs[index5];
double hub6 = hubs[index6];
double auth1 = authority[index1];
double auth3 = authority[index3];
double auth6 = authority[index6];
assertEquals(hub3, hub5);
assertTrue(hub3 > hub2);
assertTrue(auth1 > auth6);
assertEquals(hub6, 0.);
assertEquals(auth3, 0.);
}
@Test
public void testDirectedSpecial3GraphHits() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
directedGraph.addNode(node6);
Edge edge15 = graphModel.factory().newEdge(node1, node5);
Edge edge25 = graphModel.factory().newEdge(node2, node5);
Edge edge35 = graphModel.factory().newEdge(node3, node5);
Edge edge45 = graphModel.factory().newEdge(node4, node5);
Edge edge56 = graphModel.factory().newEdge(node5, node6);
directedGraph.addEdge(edge15);
directedGraph.addEdge(edge25);
directedGraph.addEdge(edge35);
directedGraph.addEdge(edge45);
directedGraph.addEdge(edge56);
DirectedGraph hgraph = graphModel.getDirectedGraph();
Hits hit = new Hits();
double[] authority = new double[6];
double[] hubs = new double[6];
HashMap<Node, Integer> indicies = hit.createIndiciesMap(hgraph);
hit.calculateHits(hgraph, hubs, authority, indicies, true, 0.01);
int index1 = indicies.get(node1);
int index3 = indicies.get(node3);
int index5 = indicies.get(node5);
int index6 = indicies.get(node6);
double hub1 = hubs[index1];
double hub3 = hubs[index3];
double hub5 = hubs[index5];
double auth5 = authority[index5];
double auth6 = authority[index6];
assertEquals(hub1, hub3);
assertTrue(hub1 > hub5);
assertTrue(auth5 > auth6);
}
}
@@ -0,0 +1,254 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.statistics.plugin;
import java.util.HashMap;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.UndirectedGraph;
import org.gephi.project.api.ProjectController;
import org.gephi.project.impl.ProjectControllerImpl;
import org.openide.util.Lookup;
import static org.testng.Assert.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
*
* @author Anna
*/
public class ModularityNGTest {
private ProjectController pc;
@BeforeClass
public void setUp() {
pc = Lookup.getDefault().lookup(ProjectControllerImpl.class);
}
@BeforeMethod
public void initialize() {
pc.newProject();
}
@AfterMethod
public void clean() {
pc.closeCurrentProject();
}
@Test
public void testTwoConnectedNodesModularity() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(2);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
Modularity mod = new Modularity();
Modularity.CommunityStructure theStructure = mod.new CommunityStructure(hgraph);
int[] comStructure = new int[hgraph.getNodeCount()];
HashMap<String, Double> modularityValues = mod.computeModularity(hgraph, theStructure, comStructure,
1., true, false);
double modValue = modularityValues.get("modularity");
int class1 = comStructure[0];
int class2 = comStructure[1];
assertEquals(modValue, 0.0);
assertEquals(class1, class2);
}
@Test
public void testGraphWithouLinksModularity() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
Modularity mod = new Modularity();
Modularity.CommunityStructure theStructure = mod.new CommunityStructure(hgraph);
int[] comStructure = new int[hgraph.getNodeCount()];
HashMap<String, Double> modularityValues = mod.computeModularity(hgraph, theStructure, comStructure,
1., true, false);
double modValue = modularityValues.get("modularity");
assertEquals(modValue, Double.NaN);
}
@Test
public void testComputeBarbellGraphModularityNormalResolution() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(4);
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node[] nodes = new Node[4];
for (int i = 0; i < 4; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) (i + 4)).toString());
nodes[i] = currentNode;
undirectedGraph.addNode(currentNode);
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j], false);
undirectedGraph.addEdge(currentEdge);
}
}
Edge currentEdge = graphModel.factory().newEdge(undirectedGraph.getNode("0"), undirectedGraph.getNode("5"), false);
undirectedGraph.addEdge(currentEdge);
UndirectedGraph graph = graphModel.getUndirectedGraph();
Modularity mod = new Modularity();
Modularity.CommunityStructure theStructure = mod.new CommunityStructure(graph);
int[] comStructure = new int[graph.getNodeCount()];
HashMap<String, Double> modularityValues = mod.computeModularity(graph, theStructure, comStructure,
1., true, false);
double modValue = modularityValues.get("modularity");
int class4 = comStructure[0];
int class5 = comStructure[5];
boolean correctResult = (class4 != class5 || modValue == 0.);
assertTrue(correctResult);
}
@Test
public void testComputeBarbellGraphHighResolution() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(4);
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node[] nodes = new Node[4];
for (int i = 0; i < 4; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) (i + 4)).toString());
nodes[i] = currentNode;
undirectedGraph.addNode(currentNode);
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j], false);
undirectedGraph.addEdge(currentEdge);
}
}
Edge currentEdge = graphModel.factory().newEdge(undirectedGraph.getNode("0"), undirectedGraph.getNode("5"), false);
undirectedGraph.addEdge(currentEdge);
UndirectedGraph graph = graphModel.getUndirectedGraph();
Modularity mod = new Modularity();
Modularity.CommunityStructure theStructure = mod.new CommunityStructure(graph);
int[] comStructure = new int[graph.getNodeCount()];
HashMap<String, Double> modularityValues = mod.computeModularity(graph, theStructure, comStructure,
100., true, false);
double modValue = modularityValues.get("modularity");
int class4 = comStructure[0];
int class5 = comStructure[5];
assertEquals(modValue, 0.0);
assertEquals(class4, class5);
}
@Test
public void testComputeBarbellGraphModularityHasHighWeight() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(4);
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node[] nodes = new Node[4];
for (int i = 0; i < 4; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) (i + 4)).toString());
nodes[i] = currentNode;
undirectedGraph.addNode(currentNode);
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j], false);
undirectedGraph.addEdge(currentEdge);
}
}
Edge currentEdge = graphModel.factory().newEdge(undirectedGraph.getNode("0"), undirectedGraph.getNode("5"), 0, 100.f, false);
undirectedGraph.addEdge(currentEdge);
UndirectedGraph graph = graphModel.getUndirectedGraph();
Modularity mod = new Modularity();
Modularity.CommunityStructure theStructure = mod.new CommunityStructure(graph);
int[] comStructure = new int[graph.getNodeCount()];
HashMap<String, Double> modularityValues = mod.computeModularity(graph, theStructure, comStructure,
1., true, true);
int class4 = comStructure[0];
int class5 = comStructure[5];
assertEquals(class4, class5);
}
@Test
public void testCyclicWithWeightsGraphModularity() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
Node node7 = graphModel.factory().newNode("6");
Node node8 = graphModel.factory().newNode("7");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
undirectedGraph.addNode(node6);
undirectedGraph.addNode(node7);
undirectedGraph.addNode(node8);
Edge edge12 = graphModel.factory().newEdge(node1, node2, 0, 10.f, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge34 = graphModel.factory().newEdge(node3, node4, 0, 10.f, false);
Edge edge45 = graphModel.factory().newEdge(node4, node5, false);
Edge edge56 = graphModel.factory().newEdge(node5, node6, 0, 10.f, false);
Edge edge67 = graphModel.factory().newEdge(node6, node7, false);
Edge edge78 = graphModel.factory().newEdge(node7, node8, 0, 10.f, false);
Edge edge81 = graphModel.factory().newEdge(node8, node1, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge34);
undirectedGraph.addEdge(edge45);
undirectedGraph.addEdge(edge56);
undirectedGraph.addEdge(edge67);
undirectedGraph.addEdge(edge78);
undirectedGraph.addEdge(edge81);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
Modularity mod = new Modularity();
Modularity.CommunityStructure theStructure = mod.new CommunityStructure(hgraph);
int[] comStructure = new int[hgraph.getNodeCount()];
HashMap<String, Double> modularityValues = mod.computeModularity(hgraph, theStructure, comStructure,
1., true, true);
int class1 = comStructure[0];
int class2 = comStructure[1];
int class4 = comStructure[3];
int class5 = comStructure[4];
int class7 = comStructure[6];
int class8 = comStructure[7];
assertEquals(class1, class2);
assertEquals(class7, class8);
assertNotEquals(class4, class5);
}
}
@@ -0,0 +1,450 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.statistics.plugin;
import java.util.HashMap;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.UndirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.project.api.ProjectController;
import org.gephi.project.impl.ProjectControllerImpl;
import org.openide.util.Lookup;
import static org.testng.Assert.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
*
* @author Anna
*/
public class PageRankNGTest {
private ProjectController pc;
@BeforeClass
public void setUp() {
pc = Lookup.getDefault().lookup(ProjectControllerImpl.class);
}
@BeforeMethod
public void initialize() {
pc.newProject();
}
@AfterMethod
public void clean() {
pc.closeCurrentProject();
}
@Test
public void testOneNodePageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, false, false, 0.001, 0.85);
Node n1 = hgraph.getNode("0");
int index = indicies.get(n1);
double pr1 = pageRank[index];
assertEquals(pr1, 1.0);
}
@Test
public void testTwoConnectedNodesPageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generatePathUndirectedGraph(2);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, false, false, 0.001, 0.85);
Node n2 = hgraph.getNode("1");
int index = indicies.get(n2);
double pr2 = pageRank[index];
assertEquals(pr2, 0.5);
}
@Test
public void testNullGraphPageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, false, false, 0.001, 0.85);
Node n1 = hgraph.getNode("0");
Node n4 = hgraph.getNode("3");
int index1 = indicies.get(n1);
int index4 = indicies.get(n4);
double pr1 = pageRank[index1];
double pr4 = pageRank[index4];
double res = 0.2d;
double diff1 = Math.abs(pr1 - res);
double diff4 = Math.abs(pr4 - res);
assertTrue(diff1 < 0.01);
assertTrue(diff4 < 0.01);
assertEquals(pr1, pr4);
}
@Test
public void testCompleteGraphPageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(5);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, false, false, 0.001, 0.85);
Node n2 = hgraph.getNode("2");
int index2 = indicies.get(n2);
double pr2 = pageRank[index2];
double res = 0.2d;
double diff2 = Math.abs(pr2 - res);
assertTrue(diff2 < 0.01);
}
@Test
public void testCyclicGraphPageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generateCyclicUndirectedGraph(6);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, false, false, 0.001, 0.6);
Node n4 = hgraph.getNode("3");
int index4 = indicies.get(n4);
double pr4 = pageRank[index4];
double res = 0.1667;
double diff4 = Math.abs(pr4 - res);
assertTrue(diff4 < 0.01);
}
@Test
public void testStarGraphPageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(5);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, false, false, 0.001, 0.6);
Node n1 = hgraph.getNode("0");
Node n2 = hgraph.getNode("1");
Node n3 = hgraph.getNode("2");
Node n4 = hgraph.getNode("3");
Node n5 = hgraph.getNode("4");
Node n6 = hgraph.getNode("5");
int index1 = indicies.get(n1);
int index2 = indicies.get(n2);
int index3 = indicies.get(n3);
int index4 = indicies.get(n4);
int index5 = indicies.get(n5);
int index6 = indicies.get(n6);
double pr1 = pageRank[index1];
double pr2 = pageRank[index2];
double pr3 = pageRank[index3];
double pr4 = pageRank[index4];
double pr5 = pageRank[index5];
double pr6 = pageRank[index6];
boolean oneMoreThree = pr1 > pr3;
double res = 1.;
double diff = 0.01;
double sum = pr1 + pr2 + pr3 + pr4 + pr5 + pr6;
assertTrue(oneMoreThree);
assertEquals(pr2, pr4);
assertTrue(Math.abs(sum - res) < diff);
}
@Test
public void testPathDirectedGraphPageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(4);
DirectedGraph hgraph = graphModel.getDirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, true, false, 0.001, 0.85);
Node n1 = hgraph.getNode("0");
Node n2 = hgraph.getNode("1");
Node n3 = hgraph.getNode("2");
Node n4 = hgraph.getNode("3");
int index1 = indicies.get(n1);
int index2 = indicies.get(n2);
int index3 = indicies.get(n3);
int index4 = indicies.get(n4);
double pr1 = pageRank[index1];
double pr2 = pageRank[index2];
double pr3 = pageRank[index3];
double pr4 = pageRank[index4];
double res = 1.;
double diff = 0.01;
double sum = pr1 + pr2 + pr3 + pr4;
assertTrue(pr1 < pr2);
assertTrue(pr2 < pr4);
assertTrue(Math.abs(sum - res) < diff);
}
@Test
public void testCyclicDirectedGraphPageRank() {
pc.newProject();
GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(5);
DirectedGraph hgraph = graphModel.getDirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, true, false, 0.001, 0.85);
Node n3 = hgraph.getNode("2");
int index3 = indicies.get(n3);
double pr3 = pageRank[index3];
double res = 0.2d;
double diff3 = Math.abs(pr3 - res);
assertTrue(diff3 < 0.01);
}
@Test
public void testDirectedSpecial1GraphPageRank() {
pc.newProject();
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
Node node7 = graphModel.factory().newNode("6");
Node node8 = graphModel.factory().newNode("7");
Node node9 = graphModel.factory().newNode("8");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
directedGraph.addNode(node6);
directedGraph.addNode(node7);
directedGraph.addNode(node8);
directedGraph.addNode(node9);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge31 = graphModel.factory().newEdge(node3, node1);
Edge edge14 = graphModel.factory().newEdge(node1, node4);
Edge edge45 = graphModel.factory().newEdge(node4, node5);
Edge edge51 = graphModel.factory().newEdge(node5, node1);
Edge edge16 = graphModel.factory().newEdge(node1, node6);
Edge edge67 = graphModel.factory().newEdge(node6, node7);
Edge edge71 = graphModel.factory().newEdge(node7, node1);
Edge edge18 = graphModel.factory().newEdge(node1, node8);
Edge edge89 = graphModel.factory().newEdge(node8, node9);
Edge edge91 = graphModel.factory().newEdge(node9, node1);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge31);
directedGraph.addEdge(edge14);
directedGraph.addEdge(edge45);
directedGraph.addEdge(edge51);
directedGraph.addEdge(edge16);
directedGraph.addEdge(edge67);
directedGraph.addEdge(edge71);
directedGraph.addEdge(edge18);
directedGraph.addEdge(edge89);
directedGraph.addEdge(edge91);
DirectedGraph hgraph = graphModel.getDirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, true, false, 0.001, 0.85);
int index1 = indicies.get(node1);
int index2 = indicies.get(node2);
int index3 = indicies.get(node3);
double pr1 = pageRank[index1];
double pr2 = pageRank[index2];
double pr3 = pageRank[index3];
assertTrue(pr1 > pr2);
assertTrue(pr2 < pr3);
}
@Test
public void testDirectedStarOutGraphPageRank() {
pc.newProject();
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node firstNode = graphModel.factory().newNode("0");
directedGraph.addNode(firstNode);
for (int i = 1; i <= 5; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
directedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(firstNode, currentNode);
directedGraph.addEdge(currentEdge);
}
DirectedGraph hgraph = graphModel.getDirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, true, false, 0.001, 0.85);
Node n1 = hgraph.getNode("0");
Node n2 = hgraph.getNode("1");
Node n3 = hgraph.getNode("2");
Node n5 = hgraph.getNode("4");
int index1 = indicies.get(n1);
int index2 = indicies.get(n2);
int index3 = indicies.get(n3);
int index5 = indicies.get(n5);
double pr1 = pageRank[index1];
double pr2 = pageRank[index2];
double pr3 = pageRank[index3];
double pr5 = pageRank[index5];
double res = 0.146;
double diff = 0.01;
assertTrue(pr1 < pr3);
assertEquals(pr2, pr5);
assertTrue(Math.abs(pr1 - res) < diff);
}
@Test
public void testUndirectedWeightedGraphPageRank() {
pc.newProject();
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
Node node6 = graphModel.factory().newNode("5");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
undirectedGraph.addNode(node6);
Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, 0, 10, false);
Edge edge34 = graphModel.factory().newEdge(node3, node4, false);
Edge edge45 = graphModel.factory().newEdge(node4, node5, false);
Edge edge56 = graphModel.factory().newEdge(node5, node6, false);
Edge edge61 = graphModel.factory().newEdge(node6, node1, false);
undirectedGraph.addEdge(edge12);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge34);
undirectedGraph.addEdge(edge45);
undirectedGraph.addEdge(edge56);
undirectedGraph.addEdge(edge61);
UndirectedGraph hgraph = graphModel.getUndirectedGraph();
PageRank pr = new PageRank();
double[] pageRank;
HashMap<Node, Integer> indicies = pr.createIndiciesMap(hgraph);
pageRank = pr.calculatePagerank(hgraph, indicies, false, true, 0.001, 0.85);
int index1 = indicies.get(node1);
int index2 = indicies.get(node2);
int index3 = indicies.get(node3);
int index6 = indicies.get(node6);
double diff = 0.01;
double pr1 = pageRank[index1];
double pr2 = pageRank[index2];
double pr3 = pageRank[index3];
double pr6 = pageRank[index6];
assertTrue(Math.abs(pr2 - pr3) < diff);
assertTrue(pr1 < pr2);
assertTrue(pr1 < pr6);
}
}
-4
Ver Arquivo
@@ -16,10 +16,6 @@
<name>StatisticsPluginUI</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>data-attributes-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>dynamic-api</artifactId>
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
@@ -29,7 +29,7 @@
<Component id="undirectedRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="directedRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="519" max="32767" attributes="0"/>
<EmptySpace pref="532" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -55,7 +55,7 @@ public class ClusteringCoefficientPanel extends javax.swing.JPanel {
//Disable directed if the graph is undirecteds
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if(graphController.getModel().isUndirected()){
if(graphController.getGraphModel().isUndirected()){
directedRadioButton.setEnabled(false);
}
}
@@ -113,7 +113,7 @@ public class ClusteringCoefficientPanel extends javax.swing.JPanel {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(undirectedRadioButton)
.addComponent(directedRadioButton))
.addContainerGap(519, Short.MAX_VALUE))
.addContainerGap(532, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
@@ -27,7 +27,7 @@
<Component id="directedRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="undirectedRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="26" max="32767" attributes="0"/>
<EmptySpace pref="39" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jLabel2" max="32767" attributes="1"/>
<Component id="jLabel1" alignment="0" pref="420" max="32767" attributes="1"/>
@@ -56,7 +56,7 @@ public class ConnectedComponentPanel extends javax.swing.JPanel {
//Disable directed if the graph is undirecteds
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if(graphController.getModel().isUndirected()){
if(graphController.getGraphModel().isUndirected()){
directedRadioButton.setEnabled(false);
}
}
@@ -115,7 +115,7 @@ public class ConnectedComponentPanel extends javax.swing.JPanel {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(directedRadioButton)
.addComponent(undirectedRadioButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)))
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
@@ -76,11 +76,11 @@
</Component>
<Component class="org.jdesktop.swingx.JXLabel" name="descriptionLabel">
<Properties>
<Property name="lineWrap" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/statistics/plugin/Bundle.properties" key="DegreeDistributionPanel.descriptionLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="verticalAlignment" type="int" value="1"/>
<Property name="lineWrap" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="org.jdesktop.swingx.JXHeader" name="header">
@@ -55,7 +55,7 @@ public class DegreeDistributionPanel extends javax.swing.JPanel {
//Disable directed if the graph is undirecteds
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if(graphController.getModel().isUndirected()){
if(graphController.getGraphModel().isUndirected()){
directedRadioButton.setEnabled(false);
}
}
@@ -103,7 +103,7 @@ public class DegreeDistributionPanel extends javax.swing.JPanel {
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(header, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
.addComponent(header, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -121,7 +121,7 @@ public class DegreeDistributionPanel extends javax.swing.JPanel {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(undirectedRadioButton)
.addGap(96, 96, 96)
.addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 2, Short.MAX_VALUE)
.addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
@@ -21,22 +21,18 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="header" alignment="0" pref="541" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="directedRadioButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="439" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="undirectedRadioButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="422" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="8" max="-2" attributes="0"/>
<Component id="iterationTextField" min="-2" pref="174" max="-2" attributes="0"/>
<EmptySpace pref="204" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="directedRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="undirectedRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="8" max="-2" attributes="0"/>
<Component id="iterationTextField" min="-2" pref="174" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -56,7 +56,7 @@ public class EigenvectorCentralityPanel extends javax.swing.JPanel {
//Disable directed if the graph is undirecteds
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if(graphController.getModel().isUndirected()){
if(graphController.getGraphModel().isUndirected()){
directedRadioButton.setEnabled(false);
}
}
@@ -127,18 +127,14 @@ public class EigenvectorCentralityPanel extends javax.swing.JPanel {
.addComponent(header, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(directedRadioButton)
.addContainerGap(439, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(undirectedRadioButton)
.addContainerGap(422, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(8, 8, 8)
.addComponent(iterationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(204, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(directedRadioButton)
.addComponent(undirectedRadioButton)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(8, 8, 8)
.addComponent(iterationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
@@ -21,15 +21,13 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="header" alignment="0" pref="477" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="undirectedRadioButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="358" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="directedRadioButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="375" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="undirectedRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="directedRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -55,7 +55,7 @@ public class GraphDensityPanel extends javax.swing.JPanel {
//Disable directed if the graph is undirecteds
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if(graphController.getModel().isUndirected()){
if(graphController.getGraphModel().isUndirected()){
directedRadioButton.setEnabled(false);
}
}
@@ -98,15 +98,13 @@ public class GraphDensityPanel extends javax.swing.JPanel {
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(header, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE)
.addComponent(header, javax.swing.GroupLayout.DEFAULT_SIZE, 477, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(undirectedRadioButton)
.addContainerGap(358, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(directedRadioButton)
.addContainerGap(372, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(undirectedRadioButton)
.addComponent(directedRadioButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
@@ -20,40 +20,43 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="header" alignment="0" pref="747" max="32767" attributes="0"/>
<Component id="header" alignment="0" pref="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="262" max="-2" attributes="0"/>
<Component id="descriptionLabel" pref="448" max="32767" attributes="0"/>
<Component id="descriptionLabel" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="directedRadioButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="260" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="normalizeButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="165" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="undirectedRadioButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="628" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="1"/>
<Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="1"/>
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jXLabel3" max="32767" attributes="0"/>
<Component id="jXLabel2" max="32767" attributes="0"/>
<Component id="jXLabel1" alignment="1" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="undirectedRadioButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="1"/>
<Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="1"/>
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jXLabel3" max="32767" attributes="0"/>
<Component id="jXLabel2" max="32767" attributes="0"/>
<Component id="jXLabel1" alignment="1" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@@ -124,11 +127,11 @@
</Component>
<Component class="org.jdesktop.swingx.JXLabel" name="descriptionLabel">
<Properties>
<Property name="lineWrap" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/statistics/plugin/Bundle.properties" key="GraphDistancePanel.descriptionLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="verticalAlignment" type="int" value="1"/>
<Property name="lineWrap" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="org.jdesktop.swingx.JXHeader" name="header">
@@ -143,26 +146,26 @@
</Component>
<Component class="org.jdesktop.swingx.JXLabel" name="jXLabel1">
<Properties>
<Property name="lineWrap" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/statistics/plugin/Bundle.properties" key="GraphDistancePanel.jXLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="lineWrap" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="org.jdesktop.swingx.JXLabel" name="jXLabel2">
<Properties>
<Property name="lineWrap" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/statistics/plugin/Bundle.properties" key="GraphDistancePanel.jXLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="lineWrap" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="org.jdesktop.swingx.JXLabel" name="jXLabel3">
<Properties>
<Property name="lineWrap" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/statistics/plugin/Bundle.properties" key="GraphDistancePanel.jXLabel3.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="lineWrap" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
@@ -55,7 +55,7 @@ public class GraphDistancePanel extends javax.swing.JPanel {
//Disable directed if the graph is undirecteds
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if(graphController.getModel().isUndirected()){
if(graphController.getGraphModel().isUndirected()){
directedRadioButton.setEnabled(false);
}
}
@@ -146,34 +146,35 @@ public class GraphDistancePanel extends javax.swing.JPanel {
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(header, javax.swing.GroupLayout.DEFAULT_SIZE, 747, Short.MAX_VALUE)
.addComponent(header, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(262, 262, 262)
.addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE)
.addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addComponent(directedRadioButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 260, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(normalizeButton)
.addGap(165, 165, 165))))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(undirectedRadioButton)
.addContainerGap(628, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jXLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jXLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jXLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(undirectedRadioButton)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jXLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jXLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jXLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
@@ -199,7 +200,7 @@ public class GraphDistancePanel extends javax.swing.JPanel {
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(20, 20, 20)
.addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 10, Short.MAX_VALUE)
.addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
@@ -120,11 +120,11 @@
</Component>
<Component class="org.jdesktop.swingx.JXLabel" name="descriptionLabel">
<Properties>
<Property name="lineWrap" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/statistics/plugin/Bundle.properties" key="HitsPanel.descriptionLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="verticalAlignment" type="int" value="1"/>
<Property name="lineWrap" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="org.jdesktop.swingx.JXHeader" name="header">
@@ -142,7 +142,6 @@
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="66" green="66" red="66" type="rgb"/>
</Property>
<Property name="lineWrap" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/statistics/plugin/Bundle.properties" key="HitsPanel.epsilonLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
@@ -151,6 +150,7 @@
<Font component="epsilonLabel" property="font" relativeSize="true" size="-1"/>
</FontInfo>
</Property>
<Property name="lineWrap" type="boolean" value="true"/>
</Properties>
</Component>
</SubComponents>
@@ -55,7 +55,7 @@ public class HitsPanel extends javax.swing.JPanel {
//Disable directed if the graph is undirecteds
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if(graphController.getModel().isUndirected()){
if(graphController.getGraphModel().isUndirected()){
directedRadioButton.setEnabled(false);
}
}
@@ -129,11 +129,11 @@ public class HitsPanel extends javax.swing.JPanel {
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(header, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
.addComponent(header, javax.swing.GroupLayout.DEFAULT_SIZE, 662, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
.addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(directedRadioButton)
@@ -162,7 +162,7 @@ public class HitsPanel extends javax.swing.JPanel {
.addComponent(undirectedRadioButton)
.addComponent(epsilonLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(59, 59, 59)
.addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
.addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
@@ -20,7 +20,7 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jXHeader1" alignment="0" pref="605" max="32767" attributes="0"/>
<Component id="jXHeader1" alignment="0" pref="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
@@ -55,7 +55,7 @@ public class PageRankPanel extends javax.swing.JPanel {
//Disable directed if the graph is undirecteds
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if(graphController.getModel().isUndirected()){
if(graphController.getGraphModel().isUndirected()){
directedRadioButton.setEnabled(false);
}
}
@@ -56,7 +56,7 @@ public class DynamicClusteringCoefficientPanel extends javax.swing.JPanel {
//Disable directed if the graph is undirecteds
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController.getModel().isUndirected()) {
if (graphController.getGraphModel().isUndirected()) {
directedRadioButton.setEnabled(false);
}
}
@@ -56,7 +56,7 @@ public class DynamicDegreePanel extends javax.swing.JPanel {
//Disable directed if the graph is undirecteds
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
if (graphController.getModel().isUndirected()) {
if (graphController.getGraphModel().isUndirected()) {
directedRadioButton.setEnabled(false);
}
}
@@ -2,24 +2,24 @@ OpenIDE-Module-Display-Category=Plugin
OpenIDE-Module-Name=Statistics Plugin UI
GraphDistancePanel.directedRadioButton.text=Directed
GraphDistancePanel.undirectedRadioButton.text=UnDirected
GraphDistancePanel.undirectedRadioButton.text=Undirected
ClusteringCoefficientPanel.jLabel1.text=Clustering Coefficent Metric
ClusteringCoefficientPanel.directedRadioButton.text=Directed
ClusteringCoefficientPanel.undirectedRadioButton.text=UnDirected
ClusteringCoefficientPanel.undirectedRadioButton.text=Undirected
DegreeDistributionPanel.directedRadioButton.text=Directed
DegreeDistributionPanel.undirectedRadioButton.text=UnDirected
DegreeDistributionPanel.undirectedRadioButton.text=Undirected
OpenIDE-Module-Short-Description=Standard statistics UI implementations
PageRankPanel.probTextField.text=
PageRankPanel.epsilonTextField.text=
HitsPanel.epsilonTextField.text=
GraphDensityPanel.directedRadioButton.text=Directed
GraphDensityPanel.undirectedRadioButton.text=UnDirected
GraphDensityPanel.undirectedRadioButton.text=Undirected
DegreeDistributionPanel.descriptionLabel.text=
GraphDistancePanel.descriptionLabel.text=
HitsPanel.labelEpsilon.text=Epsilon:
HitsPanel.descriptionLabel.text=
HitsPanel.directedRadioButton.text=Directed
HitsPanel.undirectedRadioButton.text=UnDirected
HitsPanel.undirectedRadioButton.text=Undirected
ModularityPanel.randomizeCheckbox.text=Randomize
ModularityPanel.desriptionLabel.text=
PageRankPanel.labelP.text=Probability (p):
@@ -50,7 +50,7 @@ PageRankPanel.jXLabel2.text=Stopping criterion, the smaller this value, the long
ModularityPanel.header.title=Modularity
ModularityPanel.header.description=Community detection algorithm.
ConnectedComponentPanel.header.description=Determines the number of connected components in the network.
ConnectedComponentPanel.undirectedRadioButton.text=UnDirected
ConnectedComponentPanel.undirectedRadioButton.text=Undirected
ConnectedComponentPanel.directedRadioButton.text=Directed
ConnectedComponentPanel.header.title=Connected Components
ConnectedComponentPanel.jLabel1.text=Detects strongly & weakly connected components
@@ -60,7 +60,7 @@ EigenvectorCentralityPanel.header.title=Eigenvector Centrality
EigenvectorCentralityPanel.iterationsTextField.text=jTextField1
EigenvectorCentralityPanel.labeliterations.text=Number of iterations:
EigenvectorCentralityPanel.directedButton.text=Directed
EigenvectorCentralityPanel.undirectedButton.text=UnDirected
EigenvectorCentralityPanel.undirectedButton.text=Undirected
GraphDistancePanel.normalizeButton.text=Normalize Centralities in [0,1]
ConnectedComponentUI.name=Connected Components
+2 -2
Ver Arquivo
@@ -75,12 +75,12 @@
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
<version>2.1.1</version>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<version>2.1.1</version>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
+14 -15
Ver Arquivo
@@ -217,20 +217,20 @@
<groupId>${project.groupId}</groupId>
<artifactId>spigot-plugin-ui</artifactId>
</dependency>-->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>statistics-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>statistics-plugin</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>statistics-plugin-ui</artifactId>
</dependency>
<!-- <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>statistics-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>statistics-plugin</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>statistics-plugin-ui</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>timeline</artifactId>
</dependency>
-->
@@ -302,11 +302,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>io-exporter-plugin</artifactId>
</dependency>
<!--
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>desktop-statistics</artifactId>
</dependency>-->
</dependency>
<!-- <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>filters-api</artifactId>
+43 -43
Ver Arquivo
@@ -1,59 +1,59 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plist version="1.0">
<dict>
<dict>
<key>CFBundleName</key>
<string>Gephi</string>
<key>CFBundleName</key>
<string>Gephi</string>
<key>CFBundleVersion</key>
<string>${project.version}</string>
<key>CFBundleVersion</key>
<string>${project.version}</string>
<key>CFBundleExecutable</key>
<string>gephi</string>
<key>CFBundleExecutable</key>
<string>gephi</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${project.version}</string>
<key>CFBundleShortVersionString</key>
<string>${project.version}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleIdentifier</key>
<string>org.gephi</string>
<key>CFBundleIdentifier</key>
<string>org.gephi</string>
<key>CFBundleIconFile</key>
<string>gephi.icns</string>
<key>CFBundleIconFile</key>
<string>gephi.icns</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSHighResolutionCapable</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<key>CFBundleDocumentTypes</key>
<array>
<string>gephi</string>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>gephi</string>
</array>
<key>CFBundleTypeName</key>
<string>Gephi Project File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>gexf</string>
</array>
<key>CFBundleTypeName</key>
<string>GEXF Graph File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
<key>CFBundleTypeName</key>
<string>Gephi Project File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>gexf</string>
</array>
<key>CFBundleTypeName</key>
<string>GEXF Graph File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
</dict>
</dict>
</plist>
+14
Ver Arquivo
@@ -725,6 +725,16 @@
</dependency>
</dependencies>
</dependencyManagement>
<!-- TestNG dependency -->
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@@ -1174,6 +1184,7 @@
<module>modules/DesktopProgress</module>
<module>modules/DesktopProject</module>
<module>modules/DesktopRecentFiles</module>
<module>modules/DesktopStatistics</module>
<module>modules/DirectoryChooser</module>
<module>modules/DynamicAPI</module>
<module>modules/ExportAPI</module>
@@ -1200,6 +1211,9 @@
<module>modules/ProjectAPI</module>
<module>modules/ProjectUI</module>
<module>modules/SettingsUpgrader</module>
<module>modules/StatisticsAPI</module>
<module>modules/StatisticsPlugin</module>
<module>modules/StatisticsPluginUI</module>
<module>modules/ToolsAPI</module>
<module>modules/UIComponents</module>
<module>modules/UIUtils</module>