Skip to content

Commit

Permalink
Merge pull request #1 from rostam/master
Browse files Browse the repository at this point in the history
Merging from rostam
  • Loading branch information
HKH515 authored Sep 16, 2017
2 parents 58e4d69 + 736edd1 commit b1f4e6e
Show file tree
Hide file tree
Showing 45 changed files with 726 additions and 65,250 deletions.
21 changes: 0 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@
<dep.flink.version>1.3.2</dep.flink.version>
<dep.jersey.version>1.19.3</dep.jersey.version>
</properties>
<repositories>
<repository>
<id>dbleipzig</id>
<name>Database Group Leipzig University</name>
<url>https://wdiserv1.informatik.uni-leipzig.de:443/archiva/repository/dbleipzig/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>

<!-- Jersey -->
Expand Down Expand Up @@ -94,14 +81,6 @@
<version>0.9.11</version>
</dependency>


<!-- Flink -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${dep.flink.version}</version>
</dependency>

<dependency>
<groupId>gov.nist.math</groupId>
<artifactId>jama</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ public Object calculate(GraphModel g) {
p = new Partitioner(g);
ct = 1;
found = false;
if(g.getEdgesCount() == 0) {
ct = 1;
found = true;
}
while (!found) {
found = isColorable(ct++);
found = isColorable(ct);
ct++;
}
return ct;
}
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/graphtea/extensions/reports/GreedyColoring.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// GraphTea Project: http://github.com/graphtheorysoftware/GraphTea
// Copyright (C) 2012 Graph Theory Software Foundation: http://GraphTheorySoftware.com
// Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/

package graphtea.extensions.reports;

import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.RenderTable;
import graphtea.graph.graph.Vertex;
import graphtea.plugins.reports.extension.GraphReportExtension;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

import java.util.Iterator;
import java.util.Vector;

/**
* @author Azin Azadi
*/
public class GreedyColoring implements GraphReportExtension {

public String getName() {
return "Greedy Coloring";
}

public String getDescription() {
return "The coloring of graph computed by greedy algorithm";
}

public Object calculate(GraphModel g) {
int numOfVertices = g.numOfVertices();
int mapToColors[] = new int[numOfVertices];
boolean available[] = new boolean[numOfVertices];
mapToColors[0] = 0;

for (int u = 1; u < numOfVertices; u++)
mapToColors[u] = -1;

for (int cr = 0; cr < numOfVertices; cr++)
available[cr] = false;

for (int u = 1; u < numOfVertices; u++) {

Iterator<Vertex> it = g.directNeighbors(g.getVertex(u)).iterator();
while (it.hasNext()) {
int i = it.next().getId();
if (mapToColors[i] != -1)
available[mapToColors[i]] = true;
}

for (int color = 0; color < numOfVertices; color++)
if (available[color] == false) {
mapToColors[u] = color;
break;
}


it = g.directNeighbors(g.getVertex(u)).iterator();
while (it.hasNext()) {
int i = it.next().getId();
if (mapToColors[i] != -1)
available[mapToColors[i]] = false;
}
}

int max = 0;
for (int i : mapToColors) {
if (max < i) max = i;
}
max++;

JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("num_of_colors", max);
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < mapToColors.length; i++) jsonArray.put(mapToColors[i]);
jsonObject.put("colors", jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}

return jsonObject;
}

@Override
public String getCategory() {
return "Coloring";
}
}
2 changes: 0 additions & 2 deletions src/main/java/graphtea/extensions/reports/Partitioner.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ private void findMaxIndSetsRecursively(int iv) {
curSet--;
set[vid] = false;


for (i = 0; i < ss; i++) {
mark[nv[i]] = markbck[i];
}
Expand All @@ -147,7 +146,6 @@ private void findMaxIndSetsRecursively(int iv) {
//////////////////////////////////
}


public boolean findAllPartitionings(final int t, final ColoringListener listener) {
color = new int[vertices.length];

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/graphtea/extensions/reports/RandomMatching.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public Object calculate(GraphModel g) {
sg.vertices.add(vv.get(v));
}

sg.edges.addAll(vv.keySet().stream().map(v -> g.getEdge(v, vv.get(v))).collect(Collectors.toList()));

sg.edges.addAll(vv.keySet().stream()
.map(v -> g.getEdge(v, vv.get(v))).collect(Collectors.toList()));
Vector<Object> ret = new Vector<>();
ret.add("Number of Matching:" + sg.edges.size());
ret.add(sg);
Expand All @@ -75,7 +75,6 @@ public Object calculate(GraphModel g) {

@Override
public String getCategory() {
// TODO Auto-generated method stub
return "General";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public Object calculate(GraphModel g) {
v.add(zif.getSecondVariableZagrebIndex(alpha));
ret.add(v);
}
System.out.println("chi " + ret.size());
return ret;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/graphtea/graph/graph/RenderTable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package graphtea.graph.graph;

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Vector;
Expand Down
90 changes: 77 additions & 13 deletions src/main/java/server/RequestHandler.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package server;

import graphtea.extensions.Centrality;
import graphtea.extensions.G6Format;
import graphtea.extensions.RandomTree;
import graphtea.graph.graph.*;
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
import graphtea.plugins.reports.extension.GraphReportExtension;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.reflections.Reflections;

import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.awt.*;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.*;
Expand All @@ -24,7 +23,6 @@
@Path("")
public class RequestHandler {
private static HashMap<String,Class> extensionNameToClass = new HashMap<>();
//private static GraphModel currentGraph = new GraphModel();
private static HashMap<String, GraphModel> sessionToGraph = new HashMap<>();


Expand Down Expand Up @@ -296,23 +294,21 @@ public Response report(@PathParam("info") String info) {
String sessionID = infos[4];
handleSession(sessionID);

for(String s : reportProps) {
System.out.println(s);
}

try {
if(sessionToGraph.get(sessionID).getVerticesCount() == 0)
sessionToGraph.put(sessionID, generateGraph(props, graph));
//= generateGraph(props,graph);
if(!report.contains("No ")) {
GraphReportExtension gre = ((GraphReportExtension) extensionNameToClass.get(report).newInstance());
Object o = gre.calculate(sessionToGraph.get(sessionID));
if(o instanceof JSONObject) {
return Response.ok(o.toString()).header("Access-Control-Allow-Origin", "*").build();
}
JSONObject jsonObject = new JSONObject();
if(o instanceof RenderTable) {
jsonObject.put("titles",((RenderTable)o).getTitles().toString());
}
jsonObject.put("results",o.toString());
System.out.println(jsonObject);
return Response.ok(jsonObject.toString()).header("Access-Control-Allow-Origin", "*").build();
} else {
return Response.ok("").header("Access-Control-Allow-Origin", "*").build();
Expand All @@ -328,6 +324,79 @@ public Response report(@PathParam("info") String info) {
return Response.ok("{}").header("Access-Control-Allow-Origin", "*").build();
}

@GET
@Path("/loadGraph/{info}")
@Produces("application/json;charset=utf-8")
public Response edgeList(@PathParam("info") String info) {
String[] data = info.split("--");
String loadType = data[0];
String graph = data[1];
String type = data[2];
String sessionID = data[3];
handleSession(sessionID);
GraphModel g = new GraphModel();
switch (loadType) {
case "el":
g = getGraphFromEdgeList(graph);
break;
case "g6":
g = G6Format.stringToGraphModel(graph);
break;
case "adj":
String[] rows = info.split("-");
for (String row : rows) g.addVertex(new Vertex());
for(int i=0;i<rows.length;i++) {
String tmp[] = rows[i].split(",");
for(int j=0;j<tmp.length;j++) {
if(tmp[j].equals("1")) {
g.addEdge(new Edge(g.getVertex(i),g.getVertex(j)));
}
}
}
break;
}
sessionToGraph.put(sessionID, g);
if(type.equals("directed")){
sessionToGraph.get(sessionID).setDirected(true);
} else if (type.equals("undirected")){
sessionToGraph.get(sessionID).setDirected(false);
}
try {
String json = CytoJSONBuilder.getJSON(sessionToGraph.get(sessionID));
return Response.ok(json).header("Access-Control-Allow-Origin", "*").build();
} catch (JSONException e) {
e.printStackTrace();
}
return Response.ok("").header("Access-Control-Allow-Origin", "*").build();
}

private GraphModel getGraphFromEdgeList(String info) {
String[] rows = info.split("-");
Vector<String> vs = new Vector<>();
for(String row : rows) {
String tmp[] = row.split(",");
String v1 = tmp[0].trim();
String v2 = tmp[1].trim();
if(!vs.contains(v1)) vs.add(v1);
if(!vs.contains(v2)) vs.add(v2);
}
HashMap<String,Vertex> labelVertex = new HashMap<>();
GraphModel currentGraph = new GraphModel();
for(String v : vs) {
Vertex vertex = new Vertex();
vertex.setLabel(v);
labelVertex.put(v,vertex);
currentGraph.addVertex(vertex);
}
for(String row : rows) {
String tmp[] = row.split(",");
String v1 = tmp[0].trim();
String v2 = tmp[1].trim();
Edge e = new Edge(labelVertex.get(v1),labelVertex.get(v2));
currentGraph.addEdge(e);
}
return currentGraph;
}

@GET
@Path("/draw/{info}")
Expand All @@ -337,22 +406,17 @@ public Response draw(@PathParam("info") String info) {
String graph = infos[0];
String report = infos[1];
String[] props = infos[2].replaceAll(" ","").split(":");

String type = infos[3];
String sessionID = infos[4];
handleSession(sessionID);

try {
sessionToGraph.put(sessionID, generateGraph(props, graph));

if(type.equals("directed")){
System.out.println("Directed!!");
sessionToGraph.get(sessionID).setDirected(true);
} else if (type.equals("undirected")){
System.out.println("Undirected!!");
sessionToGraph.get(sessionID).setDirected(false);
}

String json = CytoJSONBuilder.getJSON(sessionToGraph.get(sessionID));
return Response.ok(json).header("Access-Control-Allow-Origin", "*").build();
} catch (JSONException e) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public class Server {
* Default port
*/
private static final int PORT = 2342;
// private static final int PORT = 8008;
/**
* Path to demo application
*/
private static final String APPLICATION_PATH = "server/dashboard/index2.html";
private static final String APPLICATION_PATH = "server/dashboard/index.html";

/**
* Creates the base URI.
Expand Down
Loading

0 comments on commit b1f4e6e

Please sign in to comment.