Hi Subhasis,

right now don't exists a function that find all possible path. However, i'm 
attaching the class that i had created in Java to solve this problem.

Bye,
Giulia

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
package it.sorint.allpath;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;

public class AllPath {
	boolean init_find;
	boolean final_find;
	
	Set<Vertex> attualNodeList;
	List<Vertex> previusNodeList;
	List<List<String>> path;
	
	boolean stop;
	OrientGraph g;
		
	public AllPath(OrientGraph g){
		this.g= g;
		attualNodeList= new LinkedHashSet<Vertex>();
		previusNodeList= new ArrayList<Vertex>();
		path = new ArrayList<List<String>>();
		}
	
	public void getAllPath(OrientVertex initial_node, OrientVertex final_node){
		if (final_node != null && initial_node!=null){
		String init_rid = initial_node.getId().toString();
		String final_rid= final_node.getId().toString();
			previusNodeList.add(initial_node);
			List<String> p1 = new ArrayList<String>();
			p1.add(init_rid);
			path.add(p1);
			do{
				stop=false;
				for (Vertex v2: previusNodeList){
					List<String> nodeToAdd = new ArrayList<String>();
					Iterable<Vertex> out2 = v2.getVertices(Direction.OUT);
					for (Vertex v3 : out2){
						nodeToAdd.add(v3.getId().toString());
							if (!v3.getId().toString().equals(final_rid)){
								attualNodeList.add(v3);
							}
						}
						if (!nodeToAdd.isEmpty()){
							setPath(v2.getId().toString(),nodeToAdd);
						}
					}
				switchList();
			}while(stop);
				selectPath(final_rid);
				if(path.size()==0){
					System.out.println("Warning: the vertices aren't connected ");
				}else{
					printListString();
				}
		}else {
			System.out.println("Warning: The Vertex don't exist!");
		}
	}
	
	public void printListString(){
		for(List<String> s : path){
			System.out.println("List: " + s);
		}
		System.out.println("------------------------------");
	}
	
	public void selectPath(String final_rid){
		for (int i =0; i<path.size();i++){
			List<String> toAdd = path.get(i);
			String last = toAdd.get(toAdd.size()-1);
			if (!last.equals(final_rid)){
				path.remove(i);
				i--;
			}
		}
	}
	
	public void setPath(String rid, List<String> nodeToAdd){
		for (int i=0; i < path.size();i++){
			List<String> toAdd = path.get(i);
			String last = toAdd.get(toAdd.size()-1);
			if (last.equals(rid)){
				int j=0;
				for (String l : nodeToAdd){						
					boolean presentNode=false;
					for (String m :toAdd){
							if (m.equals(l)){
								presentNode=true;
							}
					}
						if(presentNode==false){
							List<String> p = new ArrayList<String>();
							for(String n : toAdd){
								p.add(n);
							}
							p.add(l);
							if (j==0){
								stop=true;
								path.set(i,p);
								j++;
							}else {
								path.add(p);
							}
						}
					}
				}
			}
		}
	
	public void switchList(){
		previusNodeList.clear();
		for(Vertex v: attualNodeList){
			previusNodeList.add(v);
		}
		attualNodeList.clear();
	}
}

Reply via email to