Skip to content
Open
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 @@ -9,9 +9,9 @@ jobs:

steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 21
- name: Build with Ant
run: ant -noinput -buildfile build.xml
37 changes: 19 additions & 18 deletions src/graphtea/extensions/AlgorithmUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void clearVertexMarks(GraphModel g) {
}

/**
* returns the subtree rooted by subTreeRoot in the rooted tree tree with the root treeRoot
* returns the subtree rooted by subTreeRoot in the rooted tree with the root treeRoot
* the vertices are ordered by their distances to subTreeRoot
* the exact distance is placed in v.getProp().obj as an Integer, starting distance is 0 which is subTreeRoot
*/
Expand All @@ -144,6 +144,7 @@ ArrayList<Vertex> getSubTree(GraphModel tree, Vertex treeRoot, Vertex subTreeRoo
clearVertexMarks(tree);

//close the path to tree root
assert pathToRoot != null;
for (Vertex vertex : pathToRoot) {
vertex.setMark(true);
}
Expand Down Expand Up @@ -351,7 +352,7 @@ public static double getAngle(GPoint p1, GPoint p2) {
}

/**
* locations v in a r-teta coordination
* locations v in an r-teta coordination
*/
public static void setLocation(Vertex v, GPoint center, double radius, double ang) {
v.setLocation(new GPoint(center.x + radius * Math.cos(ang), center.y + radius * Math.sin(ang)));
Expand Down Expand Up @@ -426,17 +427,17 @@ 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";
res.append(AlgorithmUtils.round(rv[i], 10)).append(" + ").append(AlgorithmUtils.round(iv[i], 10)).append("i");
else
res += "" + AlgorithmUtils.round(rv[i],10);
res.append(AlgorithmUtils.round(rv[i], 10));
if(i!=rv.length-1) {
res += ",";
res.append(",");
}
}
return res;
return res.toString();
}

/**
Expand Down Expand Up @@ -493,25 +494,25 @@ public static String getEigenValues(Matrix A) {
EigenvalueDecomposition ed = A.eig();
double[] rv = ed.getRealEigenvalues();
double[] iv = ed.getImagEigenvalues();
String res = "";
StringBuilder res = new StringBuilder();
Vector<Double> EigenValues = new Vector<>();
for (int i = 0; i < rv.length; i++) {
if (iv[i] != 0)
res +="" + AlgorithmUtils.round(rv[i],10) + " + " + AlgorithmUtils.round(iv[i],10) + "i";
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.size() > 0) {
res = "";
if(!EigenValues.isEmpty()) {
res = new StringBuilder();
EigenValues.sort((aDouble, t1) -> -aDouble.compareTo(t1));
for (int i = 0; i < EigenValues.size(); i++) {
res += EigenValues.get(i);
res.append(EigenValues.get(i));
if(i != EigenValues.size() - 1) {
res+=",";
res.append(",");
}
}
}
return res;
return res.toString();
}

// get kth minimum degree
Expand Down Expand Up @@ -541,7 +542,7 @@ public static double getDegreeSumOfVertex(GraphModel g, double alpha, Vertex v)
public static double getDegreeSum(GraphModel g, double alpha) {
int sum = 0;
for(Vertex v: g) {
sum+=getDegreeSumOfVertex(g,alpha,v);
sum+= (int) getDegreeSumOfVertex(g,alpha,v);
}
return sum;
}
Expand Down Expand Up @@ -677,7 +678,7 @@ public static Matrix getMaxDegreeAdjacencyMatrix (GraphModel g) {
/**
* Distance adjacency matrix
* Distance Energy based on
* Gopalapillai Indulal,a Ivan Gutmanb and Vijayakumarc
* Gopalapillai Indulal,an Ivan Gutmanb and Vijayakumarc
* ON DISTANCE ENERGY OF GRAPHS
* MATCH Commun. Math. Comput. Chem. 60 (2008) 461-472.
*
Expand Down Expand Up @@ -714,7 +715,7 @@ public static Matrix getLaplacian(Matrix A) {
for (int i = 0; i < n; i++) {
sum = 0;
for (int j = 0; j < n; j++) {
sum += ATemp[j][i];
sum += (int) ATemp[j][i];
}
DTemp[i][i] = sum;
}
Expand Down Expand Up @@ -781,7 +782,7 @@ public static Matrix getSignlessLaplacian(Matrix A) {
for (int i = 0; i < n; i++) {
sum = 0;
for (int j = 0; j < n; j++) {
sum += ATemp[j][i];
sum += (int) ATemp[j][i];
}
DTemp[i][i] = sum;
}
Expand Down
22 changes: 10 additions & 12 deletions src/graphtea/extensions/G6Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,29 @@ public static String graphToG6(GraphModel g) {
}

public static String createAdjMatrix (Matrix m){
String result="";
StringBuilder result= new StringBuilder();

for (int i = 1, k = 1; k < m.getColumnDimension(); i++, k++) {
for (int j = 0; j < i; j++) {
if (m.get(j,i) != 0) result += "1";
else result += "0";
if (m.get(j,i) != 0) result.append("1");
else result.append("0");
}
}
return result;
return result.toString();
}


public static String encodeGraph(int NoNodes, String adjmatrix) {
String rv = "";
StringBuilder rv = new StringBuilder();
int[] nn = encodeN(NoNodes);
int[] adj = encodeR(adjmatrix);
int[] res = new int[nn.length + adj.length];
System.arraycopy(nn, 0, res, 0, nn.length);
System.arraycopy(adj, 0, res, nn.length, adj.length);
for (int re : res) {
rv = rv + (char) re;
rv.append((char) re);
}
return rv;
return rv.toString();
}

private static int[] encodeN(long i) {
Expand Down Expand Up @@ -189,16 +189,14 @@ private static int[] encodeR(String a) {

private static String padR(String str) {
int padwith = 6 - (str.length() % 6);
for (int i = 0; i < padwith; i++) {
str += "0";
}
str = str + "0".repeat(padwith);
return str;
}

private static String padL(String str, int h) {
String retval = "";
StringBuilder retval = new StringBuilder();
for (int i = 0; i < h - str.length(); i++) {
retval += "0";
retval.append("0");
}
return retval + str;
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphtea/extensions/actions/ExtractSubGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void action(GraphData graphData) {

SubGraph sg = SubGraphRenderer.sgbck;
HashMap<Integer,Integer> idid= new HashMap<>();
if(sg.vertices.size()!=0) {
if(!sg.vertices.isEmpty()) {
for(Vertex v : sg.vertices) {
Vertex tmp = new Vertex();
tmp.setLabel(v.getLabel());
Expand Down
2 changes: 1 addition & 1 deletion src/graphtea/extensions/actions/g6/G6CSVStringLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void action(GraphData graphData) {
if (id == given_id)
g6 = line.substring(line.lastIndexOf(",") + 1).trim();
}
if(!g6.equals("")) {
if(!g6.isEmpty()) {
GraphModel g = G6Format.stringToGraphModel(g6);
GPoint[] pp = PositionGenerators.circle(200, 400, 250, g.numOfVertices());

Expand Down
2 changes: 1 addition & 1 deletion src/graphtea/extensions/algorithms/DAG.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static AbstractList<Vertex> doSort(GraphModel graph) {
v.setMark(true);
}

while (alv.size() != 0) {
while (!alv.isEmpty()) {
Vertex v = alv.remove(0);
out.add(v);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void doAlgorithm() {

boolean[] isThere = new boolean[mapSize];
int numOfThere = 0;
for(int i=0;i < mapSize;i++) isThere[i]=false;
for(int j=0;j < 100;j++) {
if(numOfThere == mapSize) break;
step(j+"th step");
Expand Down
3 changes: 0 additions & 3 deletions src/graphtea/extensions/algorithms/GreedyColoring.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package graphtea.extensions.algorithms;

import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
import graphtea.platform.core.BlackBoard;
import graphtea.plugins.algorithmanimator.core.GraphAlgorithm;
import graphtea.plugins.algorithmanimator.extension.AlgorithmExtension;
import graphtea.plugins.main.core.actions.ResetGraph;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Vector;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Vector<Vector<Integer>> setproduct(Vector<Vector<Integer>> set1,Vector<Ve
break;
}
}
if (!sameItem && tmp.size() != 0 && integers.size() != 0) {
if (!sameItem && !tmp.isEmpty() && !integers.isEmpty()) {
tmp.add(-1);
tmp.addAll(integers);
}
Expand Down
10 changes: 5 additions & 5 deletions src/graphtea/extensions/algorithms/LloydKMeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import java.util.Arrays;

/**
* http://frodriguez.webs.com/Java%20Algo/kmeans.txt
*
* <a href="http://frodriguez.webs.com/Java%20Algo/kmeans.txt">...</a>
* <p>
* Lloyd's Algorithm - A greedy approximation to the kmeans clustering problem (NP-HARD), this is similar to
* finding the centers of the voronoi cells of a tessellation that has the input points
* distributed as evenly as possible throughout the cells.
*
* <p>
* Steps:
* 1) It guesses an initial location for the center of each cluster
* 2) It assigns each input point to one cluster (the one with the closest center)
* 3) For each cluster, move its center to the centroid of all its assigned points.
* 4) Repeat steps 2-3 until no change occurs.
*
* <p>
* Returns: An array of Clusters. If you need exactly k clusters you may have to run it several times since
* some clusters may die out during the algorithm, this shouldn't be a problem because this function
* usually runs very fast.
Expand Down Expand Up @@ -89,7 +89,7 @@ public static Cluster[] cluster(GPoint[] p, int k) {

// remove all empty clusters (due to bad initial placement)
for (int i = 0; i < ret.size(); i++)
if (ret.get(i).getMembers().size() == 0)
if (ret.get(i).getMembers().isEmpty())
ret.remove(i--);

return ret.toArray(new Cluster[0]); // the result may not have exactly k
Expand Down
2 changes: 1 addition & 1 deletion src/graphtea/extensions/algorithms/TopologicalSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TopologicalSort extends Algorithm implements AutomatedAlgorithm {
if (graph.getInDegree(v) == 0)
alv.add(v);

while (alv.size() != 0) {
while (!alv.isEmpty()) {
Vertex v = alv.remove(0);
out.add(v);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* This method finds the shortest path from a vertex to all vertices
* of a graph.
*
* <p>
* Created by rostam on 06.03.15.
* @author M. Ali Rostami
*/
Expand All @@ -25,11 +25,11 @@ public DijkstraAlgorithm(BlackBoard blackBoard) {

/**
* This method finds a reference array using Dijkstra algorithm
* from which, one can find
* from which one can find
* the shortest paths of all vertices of a graph from an arbitrary
* given vertex.
*
* graph Graph object to be searched.
* <p>
* graph Graph object to be searched.
* vertex The source of the paths.
* Creates Vector of vertices that for each i, it has a reference to
* the vertex, before the vertex with ID number i in the shortest path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public int[][] ComputePaths(GraphModel g) {
if (sp.computePaths(g, u) != null) {
Vector<Vertex> pd = sp.computePaths(g, u);
for (Vertex v : g) {

int dd = 0;
Edge h;
while (v != u) {
Expand Down
7 changes: 0 additions & 7 deletions src/graphtea/extensions/algorithms/spanningtree/Prim.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public class Prim extends Algorithm implements AutomatedAlgorithm {
* Temporary reference to the graph the algorithm is going to run on it.
*/
final GraphModel graph;
/**
* Reference to a GraphConverter object which is responsible for duplication
* of the graph elements, because graph edges and vertices are going to be
* copied to the newly created spanning tree.
*/
private final EdgeVertexCopier<Vertex, Edge> gc;
/**
* Priority queue implemented as a binary heap to store edges, sorted according
* to their weights.
Expand Down Expand Up @@ -73,7 +67,6 @@ public Prim(GraphModel graph,
// throw new NullPointerException();

this.graph = graph;
this.gc = gc;
this.ec = new DefaultEdgeComparator();
}

Expand Down
4 changes: 2 additions & 2 deletions src/graphtea/extensions/generators/BananaTreeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

/**
* Author: Ali Rostami
*
* https://mathworld.wolfram.com/BananaTree.html
* <p><a href="
">* <a href="https://mathworld.wolfram.com/Ba</a>nanaTree.html">...</a>
*/

@CommandAttitude(name = "generate_banana_tree", abbreviation = "_g_banana", description = "generates a Banana graph")
Expand Down
3 changes: 1 addition & 2 deletions src/graphtea/extensions/generators/CrownGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

/**
* Author: Ali Rostami
* <a <a href="href="https://mathworld.wolfram.com/CrownGrap">...</a>h.html">...</a>
*
* https://mathworld.wolfram.com/CrownGraph.html
*
*/
@CommandAttitude(name = "generate_crown", abbreviation = "_g_crown",
description = "generates a Crown graph of order n")
Expand Down
2 changes: 0 additions & 2 deletions src/graphtea/extensions/generators/ExampleChainGraph1.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

/**
* @author azin azadi
Expand Down
2 changes: 1 addition & 1 deletion src/graphtea/extensions/generators/FlowerGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public GPoint[] getVertexPositions()
int w = 1000;
double mw = ((double)w)/2.0, qw = ((double)w)/4.0;
GPoint[] result = new GPoint[2*n+1];
result[2*n] = new GPoint(w/2, w/2);
result[2*n] = new GPoint((double) w /2, (double) w /2);
double ang = Math.PI*2.0/n;
double offset = 0.0;
if ((n % 2) == 0)
Expand Down
4 changes: 2 additions & 2 deletions src/graphtea/extensions/generators/HelmGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public GPoint[] getVertexPositions() {
int w = 1000;
double mw = ((double) w) / 2.0, qw = ((double) w) / 4.0;
GPoint[] result = new GPoint[2 * n + 1];
result[2 * n] = new GPoint(w / 2, w / 2);
result[2 * n] = new GPoint((double) w / 2, (double) w / 2);
double ang = Math.PI * 2.0 / n;
double offset = 0.0;
if ((n % 2) == 0)
Expand All @@ -97,7 +97,7 @@ public GraphModel generateGraph() {

/**
* generates a Helm Graph with given parameters
*
* <p>
* A helm graph, denoted Hn is a graph obtained by attaching a single
* edge and node to each node of the outer circuit of a wheel graph Wn.
*
Expand Down
Loading