| 1 | /* -*- mode: C++ -*- */ |
|---|
| 2 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 3 | // FILE : test.tol |
|---|
| 4 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 5 | Text email_ = "vdebuen@tol-project.org"; |
|---|
| 6 | Text link_ = ""; |
|---|
| 7 | Text summary_ = "checking a simple graph"; |
|---|
| 8 | |
|---|
| 9 | #Require GraphTools; |
|---|
| 10 | //#Embed "../../../_embed_all.tol"; |
|---|
| 11 | |
|---|
| 12 | //Write here the initial test TOL code if needed |
|---|
| 13 | Real numErr0 = Copy(NError); |
|---|
| 14 | Real numWar0 = Copy(NWarning); |
|---|
| 15 | |
|---|
| 16 | Real rndSeed = 0; |
|---|
| 17 | Real vertex.num = 1000; |
|---|
| 18 | Real edge.num = 20000; |
|---|
| 19 | Real removeRepeatedEdges = True; |
|---|
| 20 | |
|---|
| 21 | #Embed "../define.random.graph.tol"; |
|---|
| 22 | |
|---|
| 23 | Real vertex.idx = IntRand(1,vertex.num); |
|---|
| 24 | Text vertex.name = graph::get.vertex.name(vertex.idx); |
|---|
| 25 | |
|---|
| 26 | //The number of edges whose output is the selected vertex |
|---|
| 27 | Real vertex.in.deg = graph::vertex.in.degree(vertex.idx); |
|---|
| 28 | |
|---|
| 29 | //The number of edges whose input is the selected vertex |
|---|
| 30 | Real vertex.out.deg = graph::vertex.out.degree(vertex.idx); |
|---|
| 31 | |
|---|
| 32 | //Returns an sparse column matrix with True in all edges which Output is the |
|---|
| 33 | //specified vertex |
|---|
| 34 | VMatrix edge.match.in = graph::_.edge::match.feature.with.value( |
|---|
| 35 | "Output", vertex.idx); |
|---|
| 36 | |
|---|
| 37 | //We can obtain the selected set of edges as |
|---|
| 38 | Set edge.in = MatQuery::SelectMatch(edge.match.in); |
|---|
| 39 | |
|---|
| 40 | //Returns an sparse column matrix with True in all edges which Length is in |
|---|
| 41 | //the interval [20,30] both included |
|---|
| 42 | VMatrix edge.match.length = graph::_.edge::match.feature.in.interval( |
|---|
| 43 | "Length", True, 0, 70, True); |
|---|
| 44 | |
|---|
| 45 | //Logic operations are faster in sparse matrix when there are no much non |
|---|
| 46 | //zero cells |
|---|
| 47 | VMatrix edge.match.all = And(edge.match.in, edge.match.length); |
|---|
| 48 | |
|---|
| 49 | //We can obtain the selected set of edges as |
|---|
| 50 | Set edge.select = MatQuery::SelectMatch(edge.match.all); |
|---|
| 51 | |
|---|
| 52 | //If we want another feature of selected edges as the input nodes |
|---|
| 53 | VMatrix in.select=graph::_.edge::extract.feature.rows("Input",edge.select); |
|---|
| 54 | |
|---|
| 55 | //Checks the number of inputs is the input degree |
|---|
| 56 | Real ok.1 = VMatSum(edge.match.in) == vertex.in.deg; |
|---|
| 57 | //Checks that edge.select is a subset of edge.in |
|---|
| 58 | Real ok.2 = Card((edge.select * edge.in) - edge.select)==0; |
|---|
| 59 | |
|---|
| 60 | Real numErr1 = Copy(NError); |
|---|
| 61 | Real numWar1 = Copy(NWarning); |
|---|
| 62 | |
|---|
| 63 | Set partialResults_ = [[numErr0, numErr1, |
|---|
| 64 | ok.1, ok.2]]; |
|---|
| 65 | |
|---|
| 66 | //This is a messure of the success of the test |
|---|
| 67 | Real quality_ = And(numErr1 == numErr0, |
|---|
| 68 | numWar1 <= numWar0+1, |
|---|
| 69 | ok.1, ok.2); |
|---|
| 70 | |
|---|
| 71 | //Return the results |
|---|
| 72 | Set resultStr_ = @strTestStatus(summary_, link_, quality_, |
|---|
| 73 | "Partial results = "<<partialResults_, |
|---|
| 74 | "NO DBServerType", "NO DBServerHost", "NO DBAlias", |
|---|
| 75 | email_); |
|---|
| 76 | WriteLn(""<<resultStr_); |
|---|
| 77 | resultStr_ |
|---|
| 78 | |
|---|
| 79 | /* */ |
|---|
| 80 | |
|---|