Skip to content

Commit

Permalink
finished
Browse files Browse the repository at this point in the history
  • Loading branch information
MarenHanke committed Mar 25, 2024
1 parent 0cafea5 commit 12de17f
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 135 deletions.
6 changes: 3 additions & 3 deletions etc/userLimitInformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{
"username": "default",
"allowedInactiveDays": "30",
"graphSize": "1100",
"graphCount": "120",
"coverCount": "140"
"graphSize": "100",
"graphCount": "20",
"coverCount": "40"
},
{
"username": "user1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,10 @@ public Response createGraph(@DefaultValue("unnamed") @QueryParam("name") String
/*
Check if user has a limit regarding number of graph throw an error if the limit is violated.
*/

//if (userLimitsHandler.reachedGraphCountLimit(username)){
// requestHandler.log(Level.WARNING, "user: " + username + " reached graph count limit.");
// return requestHandler.writeError(Error.INTERNAL, "Graph count limit reached. Delete a graph before generating a new one, or contact administrator to adjust limits.");
//}
if (userLimitsHandler.reachedGraphCountLimit(username)){
requestHandler.log(Level.WARNING, "user: " + username + " reached graph count limit.");
return requestHandler.writeError(Error.INTERNAL, "Graph count limit reached. Delete a graph before generating a new one, or contact administrator to adjust limits.");
}

GraphInputFormat format;
try {
Expand Down Expand Up @@ -403,6 +402,7 @@ public Response createGraph(@DefaultValue("unnamed") @QueryParam("name") String
representativeGraph.setName(URLDecoder.decode(nameStr, "UTF-8"));
representativeGraph.setUserName(username);
representativeGraph.setCreationMethod(log);
processor.determineGraphTypes(representativeGraph);
representativeGraph.addType(GraphType.MULTIPLEX);
database.storeGraph(representativeGraph);
graph.setRepresentativeKey(representativeGraph.getKey());
Expand Down Expand Up @@ -505,11 +505,10 @@ public Response storeGraph(@DefaultValue("unnamed") @QueryParam("name") String n
/*
Check if user has a limit regarding number of graph or covers and throw an error if the limit is violated.
*/

//if (userLimitsHandler.reachedGraphCountLimit(username)){
// requestHandler.log(Level.WARNING, "user: " + username + " reached graph count limit.");
// return requestHandler.writeError(Error.INTERNAL, "Graph count limit reached. Delete a graph before generating a new one, or contact administrator to adjust limits.");
//}
if (userLimitsHandler.reachedGraphCountLimit(username)){
requestHandler.log(Level.WARNING, "user: " + username + " reached graph count limit.");
return requestHandler.writeError(Error.INTERNAL, "Graph count limit reached. Delete a graph before generating a new one, or contact administrator to adjust limits.");
}

File graphDir = new File("tmp" + File.separator + username);
if (!graphDir.exists()) {
Expand Down Expand Up @@ -792,7 +791,6 @@ public Response getLayersOfMultiplexGraph(@DefaultValue("0") @QueryParam("keyMul
List<CustomGraphMeta> queryResults;
queryResults = database.getMultiplexGraphMetaDataOfLayersEfficiently(username, keyMultiplexStr);
String responseStr = requestHandler.writeGraphMetasEfficiently(queryResults);
System.out.println(responseStr);
return Response.ok(responseStr).build();
} catch (Exception e) {
requestHandler.log(Level.SEVERE, "", e);
Expand Down Expand Up @@ -1317,7 +1315,6 @@ public Response runAlgorithm(@PathParam("graphId") String graphIdStr,
@DefaultValue("0") @QueryParam("componentNodeCountFilter") String componentNodeCountFilterStr) {
try {
int componentNodeCountFilter;

String username = ((UserAgent) Context.getCurrent().getMainAgent()).getLoginName();
CoverCreationType algorithmType;

Expand Down Expand Up @@ -1466,7 +1463,6 @@ public Response runABACUSAlgorithm(@PathParam("graphId") String graphIdStr,
String params = "";
String multiplexParams = "";
ObjectMapper objectMapper = new ObjectMapper();
System.out.println("runABACUSAlgorithm");
try {
JsonNode jsonDataObj = objectMapper.readTree(content);
multiplexParams = jsonDataObj.get("multiplexparams").asText();
Expand Down Expand Up @@ -1609,26 +1605,6 @@ public Response runABACUSAlgorithm(@PathParam("graphId") String graphIdStr,
return requestHandler.writeError(Error.INTERNAL, "Internal system error.");
}
}

@POST
@Path("covers/multiplexgraph/{graphId}/algorithms")
@Produces(MediaType.TEXT_XML)
@Consumes(MediaType.TEXT_PLAIN)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
@ApiResponse(code = 401, message = "Unauthorized") })
@ApiOperation(tags = {"execution"}, value = "Run OCD Algorithm", notes = "Creates a new cover by running an algorithm on an existing graph. \n " +
"The provided data represents the algorithm parameters and needs to be an XML with the root \"Parameters\" enclosing \"Parameter\" nodes which have both \"Name\" and \"Value\" nodes." +
"\n To see which parameters of what type are needed for an algorithm, fetch its default parameters")
public Response runABACUSAlgorith(String jsonDataStr) {
try {
System.out.println("runABACUSAlgorithm");

return Response.ok().build();
} catch (Exception e) {
requestHandler.log(Level.SEVERE, "", e);
return requestHandler.writeError(Error.INTERNAL, "Internal system error.");
}
}

//////////////////////////////////////////////////////////////////////////
//////////// CENTRALITY MEASURES
Expand Down Expand Up @@ -2447,17 +2423,17 @@ public Response runGroundTruthBenchmark(@DefaultValue("unnamed") @QueryParam("co
try {
String username = ((UserAgent) Context.getCurrent().getMainAgent()).getLoginName();

/*
/*
Check if user has a limit regarding number of graph or covers and throw an error if the limit is violated.
*/
//if (userLimitsHandler.reachedGraphCountLimit(username)){
// requestHandler.log(Level.WARNING, "user: " + username + " reached graph count limit.");
// return requestHandler.writeError(Error.INTERNAL, "Graph count limit reached. Delete a graph before generating a new one, or contact administrator to adjust limits.");
//}
//if (userLimitsHandler.reachedCoverCountLimit(username)){
// requestHandler.log(Level.WARNING, "user: " + username + " reached cover count limit.");
// return requestHandler.writeError(Error.INTERNAL, "Cover count limit reached. Delete a cover before generating a new one, or contact administrator to adjust limits.");
//}
if (userLimitsHandler.reachedGraphCountLimit(username)){
requestHandler.log(Level.WARNING, "user: " + username + " reached graph count limit.");
return requestHandler.writeError(Error.INTERNAL, "Graph count limit reached. Delete a graph before generating a new one, or contact administrator to adjust limits.");
}
if (userLimitsHandler.reachedCoverCountLimit(username)){
requestHandler.log(Level.WARNING, "user: " + username + " reached cover count limit.");
return requestHandler.writeError(Error.INTERNAL, "Cover count limit reached. Delete a cover before generating a new one, or contact administrator to adjust limits.");
}


GraphCreationType benchmarkType;
Expand Down Expand Up @@ -3523,7 +3499,6 @@ public Response getAlgorithmCompatibleGraphTypes(@PathParam("CoverCreationType")
@ApiOperation(tags = {"names"}, value = "Algorithms information", notes = "Returns all algorithm type names.")
public Response getAlgorithmNames() {
try {
System.out.println(Response.ok(requestHandler.writeAlgorithmNames()).build());
return Response.ok(requestHandler.writeAlgorithmNames()).build();
} catch (Exception e) {
requestHandler.log(Level.SEVERE, "", e);
Expand Down Expand Up @@ -3558,9 +3533,7 @@ public Response getMultiplexAlgorithmNames() {
@ApiResponse(code = 401, message = "Unauthorized") })
@ApiOperation(tags = {"testforbot"}, value = "A test method for the bot", notes = "Returns a success message.")
public Response testforbot() {
System.out.println("testforbot");
String jsonResponse = "{\"text\": \"test successfull\", \"closeContext\": \"\"}";
System.out.println(Response.ok(jsonResponse).build());
return Response.ok(jsonResponse).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public void setParameter(Map<String,String> param) throws IllegalArgumentExcepti
@Override
public MultiplexGraph readGraph() throws AdapterException {
MultiplexGraph multiplexGraph = new MultiplexGraph();
CustomGraph representativeGraph = new CustomGraph();
try {
Map<String, Map<String, Node>> graphReverseNodeNames = new HashMap<String, Map<String, Node>>();
HashMap<String, Node> representativeGraphReverseNodeNames = new HashMap<String, Node>();
List<String> line = Adapters.readLine(reader);
Set<String> totalNumberOfNodes = new HashSet<String>();
int totalNumberOfEdges = 0;
Expand All @@ -58,6 +60,7 @@ public MultiplexGraph readGraph() throws AdapterException {
Map<String, Node>reverseNodeNames = graphReverseNodeNames.get(layerName);

//read edge
//add nodes and edge to layer
String sourceNodeName = line.get(1);
Node sourceNode;
if (!reverseNodeNames.containsKey(sourceNodeName)) {
Expand All @@ -78,6 +81,24 @@ public MultiplexGraph readGraph() throws AdapterException {
}
Edge edge = graph.addEdge(UUID.randomUUID().toString(), sourceNode, targetNode);
graph.setEdgeWeight(edge, 1);

//add nodes and edge to representative graph
if (!representativeGraphReverseNodeNames.containsKey(sourceNodeName)) {
sourceNode = representativeGraph.addNode(sourceNodeName);
representativeGraphReverseNodeNames.put(sourceNodeName, sourceNode);
representativeGraph.setNodeName(sourceNode, sourceNodeName);
} else {
sourceNode = representativeGraphReverseNodeNames.get(sourceNodeName);
}
if (!representativeGraphReverseNodeNames.containsKey(targetNodeName)) {
targetNode = representativeGraph.addNode(targetNodeName);
representativeGraphReverseNodeNames.put(targetNodeName, targetNode);
representativeGraph.setNodeName(targetNode, targetNodeName);
} else {
targetNode = representativeGraphReverseNodeNames.get(targetNodeName);
}
representativeGraph.addEdge(UUID.randomUUID().toString(), sourceNode, targetNode);

line = Adapters.readLine(reader);

totalNumberOfNodes.add(sourceNodeName);
Expand All @@ -97,12 +118,6 @@ public MultiplexGraph readGraph() throws AdapterException {
}
}
}
//add representative graph
CustomGraph representativeGraph = new CustomGraph();
for(String nodeName: totalNumberOfNodes) {
Node node = representativeGraph.addNode(nodeName);
representativeGraph.setNodeName(node, nodeName);
}
multiplexGraph.setRepresentativeGraph(representativeGraph);

multiplexGraph.setNodeCount(totalNumberOfNodes.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public void setParameter(Map<String,String> param) throws IllegalArgumentExcepti
@Override
public MultiplexGraph readGraph() throws AdapterException {
MultiplexGraph multiplexGraph = new MultiplexGraph();
CustomGraph representativeGraph = new CustomGraph();
try {
Map<String, Map<String, Node>> graphReverseNodeNames = new HashMap<String, Map<String, Node>>();
HashMap<String, Node> representativeGraphReverseNodeNames = new HashMap<String, Node>();
List<String> line = Adapters.readLine(reader);
Set<String> totalNumberOfNodes = new HashSet<String>();
int totalNumberOfEdges = 0;
Expand Down Expand Up @@ -86,6 +88,24 @@ public MultiplexGraph readGraph() throws AdapterException {
double edgeWeight = Double.parseDouble(edgeWeightString);
Edge edge = graph.addEdge(UUID.randomUUID().toString(), sourceNode, targetNode);
graph.setEdgeWeight(edge, edgeWeight);

//add nodes and edge to representative graph
if (!representativeGraphReverseNodeNames.containsKey(sourceNodeName)) {
sourceNode = representativeGraph.addNode(sourceNodeName);
representativeGraphReverseNodeNames.put(sourceNodeName, sourceNode);
representativeGraph.setNodeName(sourceNode, sourceNodeName);
} else {
sourceNode = representativeGraphReverseNodeNames.get(sourceNodeName);
}
if (!representativeGraphReverseNodeNames.containsKey(targetNodeName)) {
targetNode = representativeGraph.addNode(targetNodeName);
representativeGraphReverseNodeNames.put(targetNodeName, targetNode);
representativeGraph.setNodeName(targetNode, targetNodeName);
} else {
targetNode = representativeGraphReverseNodeNames.get(targetNodeName);
}
representativeGraph.addEdge(UUID.randomUUID().toString(), sourceNode, targetNode);

line = Adapters.readLine(reader);

totalNumberOfEdges++;
Expand All @@ -106,12 +126,6 @@ public MultiplexGraph readGraph() throws AdapterException {
}
}
}
//add representative graph
CustomGraph representativeGraph = new CustomGraph();
for(String nodeName: totalNumberOfNodes) {
Node node = representativeGraph.addNode(nodeName);
representativeGraph.setNodeName(node, nodeName);
}
multiplexGraph.setRepresentativeGraph(representativeGraph);

multiplexGraph.setNodeCount(totalNumberOfNodes.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package i5.las2peer.services.ocd.adapters.graphOutput;

import i5.las2peer.services.ocd.adapters.AdapterException;
import i5.las2peer.services.ocd.adapters.OutputAdapter;
import i5.las2peer.services.ocd.adapters.graphInput.CommonGraphInputAdapter;
import i5.las2peer.services.ocd.graphs.CustomGraph;
import i5.las2peer.services.ocd.graphs.MultiplexGraph;

/**
* The common interface of all graph output adapters.
* @author Sebastian
* The common interface of all multiplex graph output adapters.
* @author Maren
*
*/
public interface MultiplexGraphOutputAdapter extends CommonGraphOutputAdapter<MultiplexGraph> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package i5.las2peer.services.ocd.algorithms;

import i5.las2peer.services.ocd.graphs.*;
import i5.las2peer.services.ocd.graphs.Cover;
import i5.las2peer.services.ocd.graphs.CoverCreationType;
import i5.las2peer.services.ocd.graphs.CustomGraph;
import i5.las2peer.services.ocd.graphs.GraphType;
import org.graphstream.graph.Edge;
import org.graphstream.graph.Node;
import org.la4j.matrix.Matrix;
Expand All @@ -18,11 +21,11 @@ public class OCDIDAlgorithm implements OcdAlgorithm {
/**
* The threshold value used for spreading the information in the network.
*/
private double thresholdOCDID = 0.0001;
private double thresholdOCDID = 0.00001;
/**
* The threshold value used in the community detection phase of the algorithm.
*/
private double thresholdCD = 0.002;
private double thresholdCD = 0.0002;
/**
* The threshold value used in the overlapping community detection phase of the algorithm.
*/
Expand Down Expand Up @@ -410,7 +413,6 @@ protected Matrix cd(CustomGraph graph, double[] informationList) throws Interrup
*/
protected Matrix ocd(CustomGraph graph, Matrix communities, double[][] I_uv) throws InterruptedException{
Set<Node> BN = boundaryNodes(graph, communities);

for (Node node : BN) {
int nodeID = node.getIndex();
Set<Node> neighbours = graph.getNeighbours(node);
Expand All @@ -425,6 +427,7 @@ protected Matrix ocd(CustomGraph graph, Matrix communities, double[][] I_uv) thr
}
if(B > hightesB){ //extension so that all nodes are assigned
communityOfHighestB = community;
hightesB = B;
}
}
if (getMemberships(communities, nodeID).isEmpty()){ //extension so that all nodes are assigned
Expand Down Expand Up @@ -601,16 +604,6 @@ protected Matrix toMembershipMatrix(Matrix oc) throws InterruptedException{
}
}

//if columns are identical only keep one of them, only needed for ocdBetter
for (int col1 = 0; col1 < numCols; col1++) {
for (int col2 = col1 + 1; col2 < numCols; col2++) {
if (keepColumns[col2] && columnsEqual(oc, col1, col2, numRows)) {
keepColumns[col2] = false;
remainingColumnsCount--;
}
}
}

Matrix membershipMatrix = new Basic2DMatrix(numRows, remainingColumnsCount);
int newCol = 0;
for (int col = 0; col < numCols; col++) {
Expand All @@ -624,14 +617,4 @@ protected Matrix toMembershipMatrix(Matrix oc) throws InterruptedException{

return membershipMatrix;
}


protected boolean columnsEqual(Matrix matrix, int col1, int col2, int numRows) {
for (int row = 0; row < numRows; row++) {
if (matrix.get(row, col1) != matrix.get(row, col2)) {
return false;
}
}
return true;
}
}
Loading

0 comments on commit 12de17f

Please sign in to comment.