Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'

- name: Download JUnit 5 dependencies
Expand Down
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<target name="test" depends="compile" description="Compile and run JUnit 5 tests">
<mkdir dir="${basedir}/build/test-classes"/>
<javac srcdir="${basedir}/test" destdir="${basedir}/build/test-classes"
source="11" target="11" includeantruntime="false">
source="17" target="17" includeantruntime="false">
<classpath>
<path refid="project.lib"/>
<pathelement location="${basedir}/build"/>
Expand Down Expand Up @@ -129,7 +129,7 @@
target: compile
================================= -->
<target name="compile" depends="depends" description="--> The ant build file of GraphTea Project.">
<javac srcdir="${src.dir}" destdir="${build.dir}" source="11" target="11" includeantruntime="false">
<javac srcdir="${src.dir}" destdir="${build.dir}" source="17" target="17" includeantruntime="false">
<classpath>
<path refid="project.lib"/>
</classpath>
Expand Down
102 changes: 66 additions & 36 deletions src/graphtea/extensions/AlgorithmUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public static void resetVertexMarks(GraphModel g) {
public static boolean isConnected(GraphModel g) {
ArrayList<Integer> vs = new ArrayList<>();
int[] parent = new int[g.getVerticesCount()];
for(int i=0;i < g.getVerticesCount();i++) parent[i] = -1;
for (int i = 0; i < g.getVerticesCount(); i++) {
parent[i] = -1;
}
dfs(g, 0, vs, parent);
return Arrays.stream(vs.toArray()).distinct().toArray().length == g.getVerticesCount();
return vs.stream().distinct().count() == g.getVerticesCount();
}

/**
Expand Down Expand Up @@ -428,17 +430,19 @@ public static String getEigenValues(GraphModel g) {
EigenvalueDecomposition ed = A.eig();
double[] rv = ed.getRealEigenvalues();
double[] iv = ed.getImagEigenvalues();
String res = "";
StringBuilder res = new StringBuilder();
for (int i = 0; i < rv.length; i++) {
if (iv[i] != 0)
res +="" + AlgorithmUtils.round(rv[i],10) + " + " + AlgorithmUtils.round(iv[i],10) + "i";
else
res += "" + AlgorithmUtils.round(rv[i],10);
if(i!=rv.length-1) {
res += ",";
if (iv[i] != 0) {
res.append(AlgorithmUtils.round(rv[i], 10)).append(" + ")
.append(AlgorithmUtils.round(iv[i], 10)).append("i");
} else {
res.append(AlgorithmUtils.round(rv[i], 10));
}
if (i != rv.length - 1) {
res.append(",");
}
}
return res;
return res.toString();
}

/**
Expand Down Expand Up @@ -485,6 +489,35 @@ public static double sumOfEigenValues(Matrix A) {
return sum;
}

/**
* Returns the all-pairs shortest-path distance matrix for {@code g} (unweighted).
* Convenience wrapper around {@link FloydWarshall} to avoid the two-liner boilerplate
* that appears throughout the codebase.
*
* @param g the graph
* @return distance matrix d where d[i][j] is the shortest path length from vertex i to vertex j
*/
public static int[][] getAllPairsDistances(GraphModel g) {
return new FloydWarshall().getAllPairsShortestPathWithoutWeight(g);
}

/**
* Computes the spectral energy of a matrix: sum of |eigenvalue - shift| over all real eigenvalues.
* Use shift = 0 for plain energy (e.g. Distance Energy, Transmission Energy).
*
* @param A the matrix whose eigenvalues to sum
* @param shift subtracted from each eigenvalue before taking the absolute value
* @return spectral energy
*/
public static double spectralEnergy(Matrix A, double shift) {
double[] rv = A.eig().getRealEigenvalues();
double sum = 0;
for (double v : rv) {
sum += Math.abs(v - shift);
}
return sum;
}

/**
* Computes the eigen values
*
Expand All @@ -495,25 +528,27 @@ public static String getEigenValues(Matrix A) {
EigenvalueDecomposition ed = A.eig();
double[] rv = ed.getRealEigenvalues();
double[] iv = ed.getImagEigenvalues();
String res = "";
List<Double> EigenValues = new ArrayList<>();
StringBuilder res = new StringBuilder();
List<Double> eigenValues = new ArrayList<>();
for (int i = 0; i < rv.length; i++) {
if (iv[i] != 0)
res +="" + AlgorithmUtils.round(rv[i],10) + " + " + AlgorithmUtils.round(iv[i],10) + "i";
else
EigenValues.add(AlgorithmUtils.round(rv[i],10));
}
if(EigenValues.size() > 0) {
res = "";
EigenValues.sort((aDouble, t1) -> -aDouble.compareTo(t1));
for (int i = 0; i < EigenValues.size(); i++) {
res += EigenValues.get(i);
if(i != EigenValues.size() - 1) {
res+=",";
if (iv[i] != 0) {
res.append(AlgorithmUtils.round(rv[i], 10)).append(" + ")
.append(AlgorithmUtils.round(iv[i], 10)).append("i");
} else {
eigenValues.add(AlgorithmUtils.round(rv[i], 10));
}
}
if (!eigenValues.isEmpty()) {
res = new StringBuilder();
eigenValues.sort((a, b) -> -a.compareTo(b));
for (int i = 0; i < eigenValues.size(); i++) {
res.append(eigenValues.get(i));
if (i != eigenValues.size() - 1) {
res.append(",");
}
}
}
return res;
return res.toString();
}

// get kth minimum degree
Expand Down Expand Up @@ -682,8 +717,7 @@ public static Matrix getMaxDegreeAdjacencyMatrix (GraphModel g) {
* @return the maximum degree adjacency matrix
*/
public static Matrix getDistanceAdjacencyMatrix (GraphModel g) {
FloydWarshall fw = new FloydWarshall();
int[][] dist = fw.getAllPairsShortestPathWithoutWeight(g);
int[][] dist = getAllPairsDistances(g);
Matrix adj = g.getAdjacencyMatrix();
for(int i=0;i < adj.getColumnDimension();i++) {
for(int j=0;j < adj.getRowDimension();j++) {
Expand Down Expand Up @@ -808,9 +842,8 @@ public static GPoint normalize(GPoint vector) {
}

public static Matrix getDistanceLaplacianMatrix (GraphModel g) {
FloydWarshall fw = new FloydWarshall();
int sum;
int[][] dist = fw.getAllPairsShortestPathWithoutWeight(g);
int[][] dist = getAllPairsDistances(g);
Matrix adj = g.getAdjacencyMatrix();
for(int i=0;i < adj.getColumnDimension();i++) {
sum=0;
Expand All @@ -825,9 +858,8 @@ public static Matrix getDistanceLaplacianMatrix (GraphModel g) {
}

public static Matrix getDistanceSignlessLaplacianMatrix (GraphModel g) {
FloydWarshall fw = new FloydWarshall();
double sum;
int [][] dist = fw.getAllPairsShortestPathWithoutWeight(g);
int[][] dist = getAllPairsDistances(g);
Matrix adj = g.getAdjacencyMatrix();
for(int i=0;i < adj.getColumnDimension();i++) {
sum=0;
Expand All @@ -844,9 +876,8 @@ public static Matrix getDistanceSignlessLaplacianMatrix (GraphModel g) {
}

public static Matrix getDiagonalTransMatrix (GraphModel g) {
FloydWarshall fw = new FloydWarshall();
int sum;
int[][] dist = fw.getAllPairsShortestPathWithoutWeight(g);
int[][] dist = getAllPairsDistances(g);
Matrix adj = g.getAdjacencyMatrix();
for(int i=0;i < adj.getColumnDimension();i++) {
sum=0;
Expand All @@ -861,9 +892,8 @@ public static Matrix getDiagonalTransMatrix (GraphModel g) {
}

public static Matrix getAverageTransMatrix (GraphModel g) {
FloydWarshall fw = new FloydWarshall();
int sum; sum=0;
int[][] dist = fw.getAllPairsShortestPathWithoutWeight(g);
int sum = 0;
int[][] dist = getAllPairsDistances(g);
Matrix adj = g.getAdjacencyMatrix();
for(int i=0;i < adj.getColumnDimension();i++) {
for(int j=0;j < adj.getRowDimension();j++) {
Expand Down
100 changes: 5 additions & 95 deletions src/graphtea/extensions/actions/EdgeSemitotalGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,107 +5,17 @@

package graphtea.extensions.actions;

import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GPoint;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
import graphtea.platform.parameter.Parameter;
import graphtea.platform.parameter.Parametrizable;
import graphtea.plugins.main.GraphData;
import graphtea.plugins.main.extension.GraphActionExtension;


/**
* Creates a line graph from the current graph and shows it in a new tab
*
* @author Mohammad Ali Rostami
* @author Azin Azadi
*/
public class EdgeSemitotalGraph implements GraphActionExtension, Parametrizable {
@Parameter
public int k = 2;

public void action(GraphData graphData) {

GraphModel g1 = graphData.getGraph();
GraphModel g2 = new GraphModel(false);
g2.setIsEdgesCurved(true);

for(Vertex v : g1.getVertexArray()) {
Vertex tmp = new Vertex();
tmp.setLocation(v.getLocation());
g2.addVertex(tmp);
}

for(Edge e : g1.getEdges()) {
GPoint v1 = e.source.getLocation();
GPoint v2 = e.target.getLocation();
double dis = v1.distance(v2);
GPoint v3 = GPoint.sub(v2, v1);
v3 = GPoint.div(v3, k+1);

Vertex src = g2.getVertex(e.source.getId());
for (int i = 0; i < k; i++) {
Vertex tmp = new Vertex();
tmp.getProp().obj=e;
GPoint v4 = new GPoint(v3);
v4.multiply(i + 1);
v4.add(v1);
tmp.setLocation(v4);
g2.addVertex(tmp);
g2.addEdge(new Edge(src,tmp));
src=tmp;
}
g2.addEdge(new Edge(src, g2.getVertex(e.target.getId())));
}

for(Vertex v1 : g2.getVertexArray()) {
for (Vertex v2 : g2.getVertexArray()) {
if(v1.getProp().obj!=null) {
if (v2.getProp().obj != null) {
Edge e1 = (Edge) v1.getProp().obj;
Edge e2 = (Edge) v2.getProp().obj;
if(edgeConnects(e1,e2)) {
Edge ee = new Edge(v1,v2);
GPoint vector =
GPoint.sub(v1.getLocation(),v2.getLocation());
vector= GPoint.div(vector,vector.norm());
GPoint ppVec = new GPoint(-vector.y,vector.x);
ppVec.multiply(30.0);
ee.setCurveControlPoint(ppVec);
g2.addEdge(ee);
}
}
}
}
}


graphData.core.showGraph(g2);
}

public boolean edgeConnects(Edge e1,Edge e2) {
if(e1.source.getId() == e2.source.getId()) return true;
if(e1.target.getId() == e2.source.getId()) return true;
if(e1.source.getId() == e2.target.getId()) return true;
return e1.target.getId() == e2.target.getId();
}

public String getName() {
return "Edge Semitotal Graph";
}

public String getDescription() {
return "Edge Semitotal Graph";
}
public class EdgeSemitotalGraph extends SubdividedGraphBase {
@Override protected boolean markSubdivisionVertices() { return true; }
@Override protected boolean addSubdivisionVertexEdges() { return true; }

@Override
public String checkParameters() {
return null;
}
public String getName() { return "Edge Semitotal Graph"; }

@Override
public String getCategory() {
return "Transformations";
}
public String getDescription() { return "Edge Semitotal Graph"; }
}
Loading
Loading