当前位置: 首页>>代码示例>>Java>>正文


Java GraphAlgoFactory.shortestPath方法代码示例

本文整理汇总了Java中org.neo4j.graphalgo.GraphAlgoFactory.shortestPath方法的典型用法代码示例。如果您正苦于以下问题:Java GraphAlgoFactory.shortestPath方法的具体用法?Java GraphAlgoFactory.shortestPath怎么用?Java GraphAlgoFactory.shortestPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.neo4j.graphalgo.GraphAlgoFactory的用法示例。


在下文中一共展示了GraphAlgoFactory.shortestPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shortestPath

import org.neo4j.graphalgo.GraphAlgoFactory; //导入方法依赖的package包/类
@Override
public void shortestPath(Node n1, Integer i)
{
    PathFinder<Path> finder
        = GraphAlgoFactory.shortestPath(Traversal.expanderForTypes(Neo4jGraphDatabase.RelTypes.SIMILAR), 5);
    Node n2 = getVertex(i);
    Path path = finder.findSinglePath(n1, n2);

}
 
开发者ID:socialsensor,项目名称:graphdb-benchmarks,代码行数:10,代码来源:Neo4jGraphDatabase.java

示例2: shortestDistance

import org.neo4j.graphalgo.GraphAlgoFactory; //导入方法依赖的package包/类
public Integer shortestDistance( Node source, Node target, Integer depth, String type, String direction ) {
	
	PathFinder<org.neo4j.graphdb.Path> finder;
	
	if ( type.equals("go") ) {
	
		// The relationships we will follow
		RelationshipType isa = DynamicRelationshipType.withName( "is_a" );
		RelationshipType partof = DynamicRelationshipType.withName( "part_of" );
		
		if ( direction.equals( "direction" ) ) {	
			finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypesAndDirections( isa, Direction.OUTGOING, partof, Direction.OUTGOING ), depth );
		} else {
			finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypesAndDirections( isa, Direction.BOTH, partof, Direction.BOTH ), depth );
		}
	
	} else {
	
		// The relationships we will follow
		RelationshipType parent = DynamicRelationshipType.withName( "has_parent" );

		if ( direction.equals( "direction" ) ) {	
			finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypeAndDirection( parent, Direction.OUTGOING ), depth );
		} else {
			finder = GraphAlgoFactory.shortestPath( PathExpanders.forType( parent ), depth );

		}
	}

	
	Iterable<org.neo4j.graphdb.Path> ListPaths = finder.findAllPaths( source, target );
	
	Iterator<org.neo4j.graphdb.Path> itr = ListPaths.iterator();
	
	while ( itr.hasNext() ) {
		
		Integer hoplength = itr.next().length();
		if ( hoplength < depth ) {
			depth = hoplength;
		}
	}
	
	return depth;
}
 
开发者ID:toniher,项目名称:neo4j-biorelation,代码行数:45,代码来源:BioRelationFunction.java

示例3: shortestPathNodes

import org.neo4j.graphalgo.GraphAlgoFactory; //导入方法依赖的package包/类
public ArrayList<Long> shortestPathNodes( Node source, Node target, Integer depth, String type, String direction ) {
	
	ArrayList<Long> pathNodes = new ArrayList<Long>();

	PathFinder<org.neo4j.graphdb.Path> finder;
	
	BioRelationHelper helper = new BioRelationHelper(); 
	
	if ( type.equals("go") ) {
	
		// The relationships we will follow
		RelationshipType isa = DynamicRelationshipType.withName( "is_a" );
		RelationshipType partof = DynamicRelationshipType.withName( "part_of" );
		
		if ( direction.equals( "direction" ) ) {	
			finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypesAndDirections( isa, Direction.OUTGOING, partof, Direction.OUTGOING ), depth );
		} else {
			finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypesAndDirections( isa, Direction.BOTH, partof, Direction.BOTH ), depth );
		}
	
	} else {
	
		// The relationships we will follow
		RelationshipType parent = DynamicRelationshipType.withName( "has_parent" );

		if ( direction.equals( "direction" ) ) {	
			finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypeAndDirection( parent, Direction.OUTGOING ), depth );
		} else {
			finder = GraphAlgoFactory.shortestPath( PathExpanders.forType( parent ), depth );

		}
	}
	
	Iterable<org.neo4j.graphdb.Path> ListPaths = finder.findAllPaths( source, target );
	
	Iterator<org.neo4j.graphdb.Path> itr = ListPaths.iterator();
	
	while ( itr.hasNext() ) {
		
		org.neo4j.graphdb.Path nodePath = itr.next();
		Integer hoplength = nodePath.length();
		if ( hoplength < depth ) {
			depth = hoplength;
			pathNodes.clear(); // Clear arrayList
			Iterable<Node> ListNodes = nodePath.nodes();
			
			pathNodes = helper.nodes2Array( ListNodes ); 
		}
	}
	
	return pathNodes;
}
 
开发者ID:toniher,项目名称:neo4j-biorelation,代码行数:53,代码来源:BioRelationFunction.java


注:本文中的org.neo4j.graphalgo.GraphAlgoFactory.shortestPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。