(self)
| 23 | CREATE (a)-[:E {{weight: ToInteger(rand()*5) + 1, cost: ToInteger(rand()*10) + 3}}]->(b)""") |
| 24 | |
| 25 | def init(self): |
| 26 | self.n = 0 # start node ID |
| 27 | self.m = 0 # end node ID |
| 28 | self.sp_paths = [] # paths between (n)->(m) |
| 29 | self.incoming_sp_paths = [] # paths between (m)<-(n) |
| 30 | self.ss_paths = [] # all paths expand from (n) |
| 31 | |
| 32 | # look for nodes `i` and `j` with at least 10 different paths |
| 33 | # between them, stop once found |
| 34 | for i in range(1, NODES): |
| 35 | for j in range(1, NODES): |
| 36 | if i == j: |
| 37 | continue |
| 38 | |
| 39 | query = f""" |
| 40 | MATCH (n:L {{v: {i}}}), (m:L {{v: {j}}}) |
| 41 | MATCH p=(n)-[:E*1..3]->(m) |
| 42 | RETURN p, |
| 43 | reduce(weight = 0, r in relationships(p) | weight + r.weight) AS weight, |
| 44 | reduce(cost = 0, r in relationships(p) | cost + r.cost) AS cost, |
| 45 | length(p) as pathLen""" |
| 46 | |
| 47 | result = self.graph.query(query) |
| 48 | l = len(result.result_set) |
| 49 | if l > 10: |
| 50 | # found nodes `i` and `j` with multiple paths |
| 51 | self.n = i |
| 52 | self.m = j |
| 53 | self.sp_paths = result.result_set |
| 54 | |
| 55 | query = f""" |
| 56 | MATCH (n:L {{v: {i}}}) |
| 57 | MATCH p=(n)-[:E*1..3]->(m) |
| 58 | RETURN p, |
| 59 | reduce(weight = 0, r in relationships(p) | weight + r.weight) AS weight, |
| 60 | reduce(cost = 0, r in relationships(p) | cost + r.cost) AS cost, |
| 61 | length(p) as pathLen""" |
| 62 | |
| 63 | result = self.graph.query(query) |
| 64 | self.ss_paths = result.result_set |
| 65 | |
| 66 | query = f""" |
| 67 | MATCH (n:L {{v: {i}}}), (m:L {{v: {j}}}) |
| 68 | MATCH p=(m)<-[:E*1..3]-(n) |
| 69 | RETURN p, |
| 70 | reduce(weight = 0, r in relationships(p) | weight + r.weight) AS weight, |
| 71 | reduce(cost = 0, r in relationships(p) | cost + r.cost) AS cost, |
| 72 | length(p) as pathLen""" |
| 73 | |
| 74 | result = self.graph.query(query) |
| 75 | self.incoming_sp_paths = result.result_set |
| 76 | break |
| 77 | |
| 78 | # expecting `cost` to be at p[2] |
| 79 | def compare_cost(p1, p2): |
| 80 | return p1[2] - p2[2] |
| 81 | |
| 82 | def compare_full(p1, p2): |
no test coverage detected