Skip to content

Commit

Permalink
#36 improved performance; starting to implement 'Algorithm' class
Browse files Browse the repository at this point in the history
though the version that's using the Algorithm object doesn't work, yet
  • Loading branch information
hoechp committed May 23, 2017
1 parent 505b72e commit 4a50f1a
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 63 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/fujaba/graphengine/PatternEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import javax.naming.spi.DirStateFactory.Result;

import org.fujaba.graphengine.algorithm.Algorithm;
import org.fujaba.graphengine.algorithm.Application;
import org.fujaba.graphengine.graph.Graph;
import org.fujaba.graphengine.graph.Node;
import org.fujaba.graphengine.isomorphismtools.IsomorphismHandlerCSPLowHeuristics;
Expand Down
104 changes: 104 additions & 0 deletions src/main/java/org/fujaba/graphengine/algorithm/Algorithm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.fujaba.graphengine.algorithm;

import java.util.ArrayList;

import org.fujaba.graphengine.Match;
import org.fujaba.graphengine.PatternEngine;
import org.fujaba.graphengine.graph.Graph;
import org.fujaba.graphengine.pattern.PatternGraph;

public class Algorithm {

private String name;
private ArrayList<Algorithm> algorithmSteps;
private PatternGraph atomicAlgorithm;
private boolean repeating;

public Algorithm(String name) {
this.name = name;
this.algorithmSteps = new ArrayList<Algorithm>();
this.atomicAlgorithm = null;
this.repeating = true;
}

public Application process(Graph input) {
Graph output = input;
if (atomicAlgorithm != null) {
while (true) {
ArrayList<Match> matches = PatternEngine.matchPattern(output, atomicAlgorithm, true);
if (matches.size() > 0) {
output = PatternEngine.applyMatch(matches.get(0));
// System.err.println("\n" + atomicAlgorithm.getName());
// System.err.println(output);
if (!repeating) {
break;
}
} else {
break;
}
}
} else {
for (Algorithm algo: algorithmSteps) {
while (true) {
Graph subAlgorithmInput = output;
Application subAlgorithmApplication = algo.process(subAlgorithmInput);
if (subAlgorithmInput != subAlgorithmApplication.getOutput()) {
output = subAlgorithmApplication.getOutput();
System.err.println("\n" + subAlgorithmApplication.getAlgorithm().getName());
System.err.println(output);
if (!repeating) {
break;
}
} else {
break;
}
}
}
}
return new Application(this, input, output);
}

public String getName() {
return name;
}
public Algorithm setName(String name) {
this.name = name;
return this;
}
public ArrayList<Algorithm> getAlgorithmSteps() {
return algorithmSteps;
}
public Algorithm setAlgorithmSteps(ArrayList<Algorithm> algorithmSteps) {
this.algorithmSteps = algorithmSteps;
return this;
}
public Algorithm addAlgorithmStep(Algorithm step) {
this.algorithmSteps.add(step);
return this;
}
public Algorithm addAlgorithmStep(PatternGraph step) {
return addAlgorithmStep(step, true);
}
public Algorithm addAlgorithmStep(PatternGraph step, boolean repeating) {
Algorithm newStep = new Algorithm(step.getName());
newStep.setAtomicAlgorithm(step);
newStep.setRepeating(repeating);
this.algorithmSteps.add(newStep);
return this;
}
public PatternGraph getAtomicAlgorithm() {
return atomicAlgorithm;
}
public Algorithm setAtomicAlgorithm(PatternGraph atomicAlgorithm) {
this.atomicAlgorithm = atomicAlgorithm;
return this;
}
public boolean isRepeating() {
return repeating;
}
public Algorithm setRepeating(boolean repeat) {
this.repeating = repeat;
return this;
}

}
39 changes: 39 additions & 0 deletions src/main/java/org/fujaba/graphengine/algorithm/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.fujaba.graphengine.algorithm;

import org.fujaba.graphengine.graph.Graph;

public class Application {

private Algorithm algorithm;
private Graph input;
private Graph output;

public Application(Algorithm algorithm, Graph input, Graph output) {
this.algorithm = algorithm;
this.input = input;
this.output = output;
}

public Algorithm getAlgorithm() {
return algorithm;
}
public Application setAlgorithm(Algorithm algorithm) {
this.algorithm = algorithm;
return this;
}
public Graph getInput() {
return input;
}
public Application setInput(Graph input) {
this.input = input;
return this;
}
public Graph getOutput() {
return output;
}
public Application setOutput(Graph output) {
this.output = output;
return this;
}

}
Loading

0 comments on commit 4a50f1a

Please sign in to comment.