OrientDB: How to query a graph using dijkstra function while ignoring some edges -
i trying query data orientdb while ignoring edges.
my query has form:
select expand(dijkstra(#12:15,#12:20,'property','both'))
but mentioned want ignore edges of graph.
are there suggestions?
edit
here graph structure . station vertex image click
path edge image click
thank @ivan mainetti answer have try testing main()
here main()
string nomedb = "demo2"; try { system.out.println("before connect oserveradmin"); oserveradmin serveradmin = new oserveradmin("remote:128.199.xxx.xxx/"+nomedb).connect("admin","password"); system.out.println("after connect"); if(serveradmin.existsdatabase()){ // il db esiste system.out.println("in if"); //connessione db orientgraph g = new orientgraph("remote:128.199.xxx.xxx/"+nomedb); dijkstraexcl d = new dijkstraexcl(g, "path", "distance"); set<string> ex =new hashset<string>(); //------------------------------------------------ vertex start = g.getvertex("#12:6"); vertex end = g.getvertex("#12:11"); ex.add("#13:0"); direction direction = direction.out; system.out.println(d.getpath(start,end,direction,ex)); system.out.println(d.getpathstring(start,end,direction,ex)); system.out.println(d.getweight(start,end,direction,ex)); //------------------------------------------------ //chiude db g.shutdown(); } else{ system.out.println("il database '"+ nomedb + "' non esiste"); } serveradmin.close(); } catch (ioexception e) { e.printstacktrace(); }
and result after run main() is
null
null
2147483647
the correct answer after ignore [#13:0] should
[#12:6,#12:8,#12:10,#12:11]
try following js function has parameters ridfrom, ridto, property, direction , excludeedges. studio can try command:
select expand(result) (select myfunction("12:6","12:11","distance","out","[#13:0]") result)
the edges "edge1" , "edge2" ignored.
var g=orient.getgraph(); var listedges=excludeedges.substring(1,excludeedges.length-1).split(","); var s=[], t=[] , id_weigth=[] , , , infinity = number.max_value; step1(); step2(); return getpath(); // initialization function step1() { var selectfrom=g.command("sql","select v @rid ="+ ridfrom); var selectto=g.command("sql","select v @rid ="+ ridto); if(selectfrom.length>0 && selectto.length>0){ from=selectfrom[0]; to=selectto[0]; s.push(from); var selectall=g.command("sql","select v"); (i=0;i<selectall.length;i++) { if (selectall[i].getid()!=from.getid()) t.push(selectall[i]); } var index=1; (i=0;i<selectall.length;i++) { var id = selectall[i].getid(); if (selectall[i].getid()!= from.getid()) { id_weigth[index] = {id:id,weigth:infinity}; index++; } else id_weigth[0] = {id:id,weigth:0}; } setweigth_direction(from); } } // assignment permanent label function step2(){ var stop = true; { stop = true; (i=0;i<t.length;i++) { var id = t[i].getid(); (j=0;j<id_weigth.length;j++) { if (id_weigth[j].id==id) { if (id_weigth[j].weigth != infinity){ stop = false; } } } } if (stop == true) break; else { var index2 = 0; minweigth = 0; j = null; (i=0;i<t.length;i++) { var id = t[i].getid(); (m=0;m<id_weigth.length;m++) { if (id_weigth[m].id==id) { if (index2 == 0) { minweigth = id_weigth[m].weigth; index2++; j = t[i]; } else if (id_weigth[m].weigth < minweigth) { minweigth = id_weigth[m].weigth; j = t[i]; } } } } t.splice(getpositionint(j.getid()),1); s.push(j); if (t.length == 0) break; else step3(j); } } while (stop == false); } // assignment temporary label function step3(j) { setweigth_direction(j); } function setweigth(vertex,direction1,direction2) { var edges=g.command("sql","select expand(" + direction1+"e()) "+ vertex.getid()); for(m=0;m<edges.length;m++){ var myedge=edges[m];; var idedge = myedge.getid().tostring(); var validedge=true; (s=0;s<listedges.length;s++) { if(listedges[s]==idedge) validedge=false; } if(validedge==true){ var myweigth = myedge.getproperty(property); var myvertex=g.command("sql","select expand("+ direction2 + ") " +myedge.getid()); var id = myvertex[0].getid(); if(vertex!=from){ (p=0;p<t.length;p++) { if (t[p].getid()==id) { var id_weight_i = getid_weigth(id); var id_weight_j = getid_weigth(j.getid()); var weigthi = id_weight_i.weigth; var weigthj = id_weight_j.weigth; if (weigthi > weigthj + myweigth) { id_weight_i.weigth=weigthj + myweigth; id_weight_i.previous=vertex; } } } } else{ (q=0;q<id_weigth.length;q++) { if (id_weigth[q].id==id) { id_weigth[q].weigth=myweigth; id_weigth[q].previous=vertex; } } } } } } function getid_weigth(id) { (l=0;l<id_weigth.length;l++) { if (id_weigth[l].id==id) return id_weigth[l]; } return null; } function getpath(){ var validpath = true, temp = [], path = []; temp.push(to); var npm = getid_weigth(to.getid()); var v = npm.previous; while (v != from) { temp.push(v); if (v == null) { validpath = false; break; } npm = getid_weigth(v.getid()); v = npm.previous; } if (validpath == true) { temp.push(from); (i = temp.length - 1; >= 0; i--) path.push(temp[i]); } return path; } function setweigth_direction(vertex){ if (direction == "both"){ setweigth(vertex,"in","out"); setweigth(vertex,"out","in"); } else if (direction == "in") setweigth(vertex,"in","out"); else setweigth(vertex,"out","in"); } function getpositionint(id){ (l=0;l<t.length;l++) { if(t[l].getid()==id) return l; } return null; }
Comments
Post a Comment