-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#36 improved performance; starting to implement 'Algorithm' class
though the version that's using the Algorithm object doesn't work, yet
- Loading branch information
Showing
4 changed files
with
253 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/main/java/org/fujaba/graphengine/algorithm/Algorithm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
src/main/java/org/fujaba/graphengine/algorithm/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.