Skip to content
Permalink
Browse files

Transferred ai.graphsearch interfaces

  • Loading branch information...
fmohr committed Jul 11, 2019
1 parent 8225ff5 commit 7860cb57da40efd4eccf71a5de92721c8106bb0d
Showing with 482 additions and 13 deletions.
  1. +60 −0 ai/graphsearch/build.gradle
  2. +7 −0 ai/graphsearch/readme.md
  3. +20 −0 ai/graphsearch/src/main/java/org/api4/java/ai/graphsearch/problem/IGraphSearch.java
  4. +7 −0 ai/graphsearch/src/main/java/org/api4/java/ai/graphsearch/problem/IGraphSearchFactory.java
  5. +7 −0 ai/graphsearch/src/main/java/org/api4/java/ai/graphsearch/problem/IGraphSearchInput.java
  6. +8 −0 ...arch/src/main/java/org/api4/java/ai/graphsearch/problem/IGraphSearchWithPathEvaluationsInput.java
  7. +23 −0 ai/graphsearch/src/main/java/org/api4/java/ai/graphsearch/problem/IOptimalPathInORGraphSearch.java
  8. +8 −0 ...search/src/main/java/org/api4/java/ai/graphsearch/problem/IOptimalPathInORGraphSearchFactory.java
  9. +8 −0 ai/graphsearch/src/main/java/org/api4/java/ai/graphsearch/problem/IPathInORGraphSearch.java
  10. +18 −0 ai/graphsearch/src/main/java/org/api4/java/ai/graphsearch/problem/PathUnifyingGraphGenerator.java
  11. +10 −0 ...h/src/main/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/IGraphGenerator.java
  12. +16 −0 ai/graphsearch/src/main/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/IPath.java
  13. +7 −0 ...main/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/MultipleRootGenerator.java
  14. +74 −0 ...n/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/NodeExpansionDescription.java
  15. +18 −0 ...ch/src/main/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/NodeGoalTester.java
  16. +5 −0 ...phsearch/src/main/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/NodeType.java
  17. +13 −0 ...ch/src/main/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/PathGoalTester.java
  18. +5 −0 ...rch/src/main/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/RootGenerator.java
  19. +7 −0 ...java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/SerializableGraphGenerator.java
  20. +9 −0 .../java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/SerializableNodeEvaluator.java
  21. +7 −0 .../java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/SerializableRootGenerator.java
  22. +5 −0 ...c/main/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/SingleRootGenerator.java
  23. +16 −0 ...n/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/SingleSuccessorGenerator.java
  24. +16 −0 ...rc/main/java/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/SuccessorGenerator.java
  25. +18 −0 ...ava/org/api4/java/ai/graphsearch/problem/implicit/graphgenerator/TimeAwareSuccessorGenerator.java
  26. +6 −0 ...java/org/api4/java/ai/graphsearch/problem/pathsearch/pathevaluation/ICancelableNodeEvaluator.java
  27. +8 −0 .../src/main/java/org/api4/java/ai/graphsearch/problem/pathsearch/pathevaluation/IEvaluatedPath.java
  28. +7 −0 .../src/main/java/org/api4/java/ai/graphsearch/problem/pathsearch/pathevaluation/IPathEvaluator.java
  29. +9 −0 ...ava/ai/graphsearch/problem/pathsearch/pathevaluation/IPotentiallyGraphDependentPathEvaluator.java
  30. +17 −0 .../ai/graphsearch/problem/pathsearch/pathevaluation/IPotentiallySolutionReportingPathEvaluator.java
  31. +7 −0 ...graphsearch/problem/pathsearch/pathevaluation/IPotentiallyUncertaintyAnnotatingPathEvaluator.java
  32. +10 −0 .../main/java/org/api4/java/ai/graphsearch/problem/pathsearch/pathevaluation/IUncertaintySource.java
  33. +15 −0 .../java/org/api4/java/ai/graphsearch/problem/pathsearch/pathevaluation/PathEvaluationException.java
  34. +3 −3 algorithm/src/main/java/org/api4/java/algorithm/IAlgorithmFactory.java
  35. +1 −6 algorithm/src/main/java/org/api4/java/algorithm/IOptimizationAlgorithmFactory.java
  36. +3 −3 algorithm/src/main/java/org/api4/java/algorithm/exceptions/AlgorithmException.java
  37. +1 −0 build.gradle
  38. +3 −1 settings.gradle
@@ -0,0 +1,60 @@
dependencies {
compile project(":common")
compile project(":algorithm")
}

uploadArchives {
repositories {
mavenDeployer {
def ossrhUsername = project.hasProperty('ossrhUsername') ? project.property('ossrhUsername') : ""
def ossrhPassword = project.hasProperty('ossrhPassword') ? project.property('ossrhPassword') : ""

beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}

pom.project {
name 'api4-ai-graphsearch'
packaging 'jar'
// optionally artifactId can be defined here
description 'Fundamental utils required by many other starlibs projects.'
url 'https://api4.org'

scm {
connection 'scm:git:https://github.com/fmohr/api4.git'
developerConnection 'scm:git:https://github.com/fmohr/api4.git'
url 'https://github.com/fmohr/api4'
}

licenses {
license {
name 'GPLv3'
url 'https://www.gnu.org/licenses/gpl-3.0.en.html'
}
}

developers {
developer {
id 'fmohr'
name 'Felix Mohr'
email 'felix.mohr@upb.de'
}
developer {
id 'mwever'
name 'Marcel Wever'
email 'marcel.wever@upb.de'
}
developer {
id 'ahetzer'
name 'Alexander Tornede'
email 'alexander.tornede@upb.de'
}
}
}
}
}
}
@@ -0,0 +1,7 @@
In the context of nodes and paths, we distinguish three classes:

* the problem-specific (domain) node label (N in the generics) is the class associated with a *node*. Having this model for nodes instead of paths is not a limitation, because N may contain all the history, effectively making the graph a tree and, hence, representing a path as well.
* the problem-specific (technical) path of nodes in the search graph
* the algorithm-specific representation of a path

The second and the third, however, can implement the same interface, because both are paths in the search graph, just with different implementations.
@@ -0,0 +1,20 @@
package org.api4.java.ai.graphsearch.problem;

import org.api4.java.ai.graphsearch.problem.implicit.graphgenerator.IGraphGenerator;
import org.api4.java.algorithm.IAlgorithm;

/**
* Graph search algorithms take a graph <N, A> that is given in the form of a graph generator and search it.
* Usually, the algorithm uses internal wrapper classes to represent edges and nodes, which is why there are
* additional generics for that.
*
* @author fmohr
*
* @param <I>
* @param <O>
* @param <N>
* @param <A>
*/
public interface IGraphSearch<I extends IGraphSearchInput<N, A>, O, N, A> extends IAlgorithm<I, O> {
public IGraphGenerator<N, A> getGraphGenerator();
}
@@ -0,0 +1,7 @@
package org.api4.java.ai.graphsearch.problem;

import org.api4.java.algorithm.IAlgorithmFactory;

public interface IGraphSearchFactory<I extends IGraphSearchInput<N, A>, O, N, A, A2 extends IGraphSearch<I, O, N, A>> extends IAlgorithmFactory<I, O, A2> {

}
@@ -0,0 +1,7 @@
package org.api4.java.ai.graphsearch.problem;

import org.api4.java.ai.graphsearch.problem.implicit.graphgenerator.IGraphGenerator;

public interface IGraphSearchInput<N, A> {
public IGraphGenerator<N, A> getGraphGenerator();
}
@@ -0,0 +1,8 @@
package org.api4.java.ai.graphsearch.problem;

import org.api4.java.ai.graphsearch.problem.implicit.graphgenerator.IPath;
import org.api4.java.common.attributedobjects.IObjectEvaluator;

public interface IGraphSearchWithPathEvaluationsInput<N, A, V extends Comparable<V>> extends IGraphSearchInput<N, A> {
public IObjectEvaluator<IPath<N, A>, V> getPathEvaluator();
}
@@ -0,0 +1,23 @@
package org.api4.java.ai.graphsearch.problem;

import org.api4.java.ai.graphsearch.problem.pathsearch.pathevaluation.IEvaluatedPath;
import org.api4.java.algorithm.IOptimizationAlgorithm;

/**
* This is a template for algorithms that aim at finding paths from a root to
* goal nodes in a graph. This template does not assume paths to have a score.
*
* The output type of this algorithm is fixed to EvaluatedSearchGraphPath<NSrc, ASrc, V>
*
* @author fmohr
*
* @param <I>
* @param <N>
* @param <A>
* @param <V>
* @param <NSearch>
* @param <Asearch>
*/
public interface IOptimalPathInORGraphSearch<I extends IGraphSearchInput<N, A>, O extends IEvaluatedPath<N, A, V>, N, A, V extends Comparable<V>> extends IOptimizationAlgorithm<I, O, V>, IPathInORGraphSearch<I, O, N, A> {

}
@@ -0,0 +1,8 @@
package org.api4.java.ai.graphsearch.problem;

import org.api4.java.ai.graphsearch.problem.pathsearch.pathevaluation.IEvaluatedPath;
import org.api4.java.algorithm.IOptimizationAlgorithmFactory;

public interface IOptimalPathInORGraphSearchFactory<I extends IGraphSearchInput<N, A>, O extends IEvaluatedPath<N, A, V>, N, A, V extends Comparable<V>, A2 extends IOptimalPathInORGraphSearch<I, O, N, A, V>> extends IOptimizationAlgorithmFactory<I, O, V, A2> {

}
@@ -0,0 +1,8 @@
package org.api4.java.ai.graphsearch.problem;

import org.api4.java.ai.graphsearch.problem.implicit.graphgenerator.IPath;
import org.api4.java.algorithm.ISolutionCandidateIterator;

public interface IPathInORGraphSearch<I extends IGraphSearchInput<N, A>, O extends IPath<N, A>, N, A> extends IGraphSearch<I, O, N, A>, ISolutionCandidateIterator<I, O> {

}
@@ -0,0 +1,18 @@
package org.api4.java.ai.graphsearch.problem;

import java.util.List;

import org.api4.java.ai.graphsearch.problem.implicit.graphgenerator.IGraphGenerator;

/**
* This is an extension of the classical GraphGenerator that allows to assert that a path is semantically subsumed by another.
* This is important if it is not trivially checkable whether two states are identical due to deviating object names of semantically equivalent objects.
*
* @author fmohr
*
* @param <N>
* @param <A>
*/
public interface PathUnifyingGraphGenerator<N, A> extends IGraphGenerator<N, A> {
public boolean isPathSemanticallySubsumed(List<N> path, List<N> potentialSuperPath) throws InterruptedException;
}
@@ -0,0 +1,10 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

public interface IGraphGenerator<T, A> {

public RootGenerator<T> getRootGenerator();

public SuccessorGenerator<T, A> getSuccessorGenerator();

public PathGoalTester<T, A> getGoalTester();
}
@@ -0,0 +1,16 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

import java.util.List;

public interface IPath<N, A> {

public N getRoot();

public N getHead();

public IPath<N, A> getPathToParentOfHead();

public List<N> getNodes();

public List<A> getArcs();
}
@@ -0,0 +1,7 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

import java.util.Collection;

public interface MultipleRootGenerator<T> extends RootGenerator<T> {
public Collection<T> getRoots();
}
@@ -0,0 +1,74 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

public class NodeExpansionDescription<S, A> {

private final S to;
private final A action;
private final NodeType typeOfToNode;

public NodeExpansionDescription(final S to) {
this(to, null, NodeType.OR);
}

public NodeExpansionDescription(final S to, final A action, final NodeType typeOfToNode) {
super();
this.to = to;
this.action = action;
this.typeOfToNode = typeOfToNode;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.action == null) ? 0 : this.action.hashCode());
result = prime * result + ((this.to == null) ? 0 : this.to.hashCode());
result = prime * result + ((this.typeOfToNode == null) ? 0 : this.typeOfToNode.hashCode());
return result;
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
NodeExpansionDescription<?, ?> other = (NodeExpansionDescription<?, ?>) obj;
if (this.action == null) {
if (other.action != null) {
return false;
}
} else if (!this.action.equals(other.action)) {
return false;
}
if (this.to == null) {
if (other.to != null) {
return false;
}
} else if (!this.to.equals(other.to)) {
return false;
}
if (this.typeOfToNode != other.typeOfToNode) {
return false;
}
return true;
}

public S getTo() {
return this.to;
}

public A getAction() {
return this.action;
}

public NodeType getTypeOfToNode() {
return this.typeOfToNode;
}

}
@@ -0,0 +1,18 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

public interface NodeGoalTester<N, A> extends PathGoalTester<N, A> {

/**
* Check if the current node is a goal for the problem.
*
* @param node
* The node to check.
* @return <code>true</code> if it is a goal, <code>false</else> otherwise.
*/
public boolean isGoal(N node);

@Override
default boolean isGoal(final IPath<N,A> path) {
return isGoal(path.getHead());
}
}
@@ -0,0 +1,5 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

public enum NodeType {
AND, OR
}
@@ -0,0 +1,13 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

public interface PathGoalTester<N, A> {

/**
* Check if the current node is a goal for the problem.
*
* @param path
* The path to check.
* @return <code>true</code> if it is a goal, <code>false</else> otherwise.
*/
public boolean isGoal(IPath<N, A> path);
}
@@ -0,0 +1,5 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

public interface RootGenerator<T> {

}
@@ -0,0 +1,7 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

import java.io.Serializable;

public interface SerializableGraphGenerator<T,A> extends IGraphGenerator<T, A>, Serializable {

}
@@ -0,0 +1,9 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

import java.io.Serializable;

import org.api4.java.ai.graphsearch.problem.pathsearch.pathevaluation.IPathEvaluator;

public interface SerializableNodeEvaluator<T, A, V extends Comparable<V>> extends IPathEvaluator<T, A, V>, Serializable {

}
@@ -0,0 +1,7 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

import java.io.Serializable;

public interface SerializableRootGenerator<T> extends SingleRootGenerator<T>, Serializable {

}
@@ -0,0 +1,5 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

public interface SingleRootGenerator<T> extends RootGenerator<T> {
public T getRoot();
}
@@ -0,0 +1,16 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

public interface SingleSuccessorGenerator<T,A> extends SuccessorGenerator<T, A> {

/**
* generate the (i%N)-th ungenerated successor of the given node where N is the number of existing successors that have not been generated before.
*
* returns null if no more successors exist.
*
* @param i
* @return
*/
public NodeExpansionDescription<T,A> generateSuccessor(T node, int i) throws InterruptedException;

public boolean allSuccessorsComputed(T node);
}
@@ -0,0 +1,16 @@
package org.api4.java.ai.graphsearch.problem.implicit.graphgenerator;

import java.util.List;

public interface SuccessorGenerator<T, A> {

/**
* Generate the successors for a given node.
*
* @param node
* The node we want to expand.
* @return A list of possible next steps.
*/
public List<NodeExpansionDescription<T, A>> generateSuccessors(T node) throws InterruptedException;

}

0 comments on commit 7860cb5

Please sign in to comment.
You can’t perform that action at this time.