Changeset e7af41b in tol
- Timestamp:
- Nov 9, 2009, 1:57:31 PM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 2720097
- Parents:
- ea1b10f
- Location:
- tol_pkg
- Files:
-
- 4 edited
-
GisTools/_GisTools.tol (modified) (3 diffs)
-
GraphTools/_GraphTools.tol (modified) (4 diffs)
-
GraphTools/test/test_0001/define.random.graph.tol (modified) (3 diffs)
-
GraphTools/test/test_0001/test.tol (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tol_pkg/GisTools/_GisTools.tol
rea1b10f re7af41b 6 6 7 7 NameBlock GisTools = [[ 8 9 Text _.autodoc.description = "Functions and classes related with " 10 "Geographic Information System (GIS), selection and classification methods " 11 "over matricial data over massive geographical points."; 12 13 Text _.autodoc.keywords = "GIS,Geographic,select,classify"; 14 8 15 ////////////////////////////////////////////////////////////////////////////// 9 //Selects rows of matrix M that are inside the hipercube whose side length is 10 //2*d and is centered in point given by row matrix P 16 Static Text _.autodoc.member.SelectRowsInHyperCube = "Selects rows of matrix " 17 "M that are inside the hipercube whose side length is 2*d and is centered in " 18 "point given by row matrix P "; 11 19 Set SelectRowsInHyperCube(Matrix M, Matrix P, Real d) 12 20 ////////////////////////////////////////////////////////////////////////////// … … 24 32 25 33 ////////////////////////////////////////////////////////////////////////////// 26 //Selects rows of matrix M_ that are inside the hipersphere with specified 27 //ratio and is centered in point given by row matrix P 34 Static Text _.autodoc.member.SelectRowsInHyperSphere = "Selects rows of " 35 "matrix M that are inside the hipersphere with specified ratio and is " 36 "centered in point given by row matrix P"; 28 37 Set SelectRowsInHyperSphere(Matrix M, Matrix P, Real ratio) 29 38 ////////////////////////////////////////////////////////////////////////////// … … 39 48 Matrix select = VMat2Triplet(Convert(match,"Cholmod.R.Triplet")); 40 49 If(!Rows(select),Copy(Empty), MatSet(Tra(SubCol(select,[[1]])))[1]) 50 }; 51 52 ////////////////////////////////////////////////////////////////////////////// 53 Static Text _.autodoc.member.ClassifyColumnByRank = "Classifies a column " 54 "matrix by the ranking position respect a set of R sortednumbers. The class " 55 "of the i-th row will be assigned in this way:\n" 56 " class[i] = 1 <=> M[i] < rankBound[1]\n" 57 " class(i] = k+1 <=> rankBound[k] <= M[i] < rankBound[k+1]; k=1...R\n" 58 " class[i] = R+1 <=> rankBound[R] <= M[i]\n"; 59 Matrix ClassifyColumnByRank(Matrix M, Set rankBound) 60 ////////////////////////////////////////////////////////////////////////////// 61 { 62 Real m = Rows(M); 63 Real R = Card(rankBound); 64 Real min = 65 { 66 Real aux = MatMin(M); 67 aux - Abs(aux) - 1 68 }; 69 Real max = 70 { 71 Real aux = MatMax(M); 72 aux + Abs(aux) + 1 73 }; 74 Set rnk = SetOfReal(min)<<rankBound<<SetOfReal(max); 75 VMatrix class = Zeros(m,1); 76 Real r = 1; 77 While(r<=R+1, 78 { 79 Matrix left = Rand(m,1,rnk[r ],rnk[r ]); 80 Matrix right = Rand(m,1,rnk[r+1],rnk[r+1]); 81 VMatrix left.match = Mat2VMat(LE(left,M)); 82 VMatrix right.match = Mat2VMat(LT(M,right)); 83 VMatrix class := class + And(left.match,right.match)*r; 84 Real r := r+1 85 }); 86 VMat2Mat(class) 41 87 } 88 42 89 ]]; -
tol_pkg/GraphTools/_GraphTools.tol
rea1b10f re7af41b 9 9 ////////////////////////////////////////////////////////////////////////////// 10 10 [[ 11 12 Text _.autodoc.description = "Functions and classes related with " 13 "Graph Theory."; 14 15 Text _.autodoc.keywords = "Graph Theory,vertex,edge,adjacent"; 16 11 17 ////////////////////////////////////////////////////////////////////////////// 12 18 Text _.autodoc.member.Append.Indexed = "Adds and index a new element to a " … … 220 226 VMatrix _.edge.map = Rand(0,0,0,0); 221 227 VMatrix _.edge.adjacency = Rand(0,0,0,0); 222 VMatrix _.edge.rep = Rand(0,0,0,0);223 Real _.edge.check.rep = ?;224 228 VMatrix _.edge.repeated = Rand(0,0,0,0); 229 Real _.edge.check.repeated = ?; 230 Real _.edge.check.repaired = ?; 225 231 //////////////////////////////////////////////////////////////////////////// 226 232 Static Text _.autodoc.member.New = "Creates a new instance of " … … 255 261 //////////////////////////////////////////////////////////////////////////// 256 262 Text _.autodoc.member.edge.build = ""; 257 Real edge.build(Matrix data )263 Real edge.build(Matrix data, Real removeRepeatedEdges) 258 264 //////////////////////////////////////////////////////////////////////////// 259 265 { … … 264 270 Matrix in = If(_.directed, in_, Max(in_, out_)); 265 271 Matrix _.edge::_.data := out | in | SubCol(data,Range(3,Columns(data),1)); 266 267 272 Matrix idx = DifEq(1/(1-B),Rand(_.edge.num,1,1,1)); 268 273 Matrix idx.rep = Rand(_.edge.num,1,1,1); 269 274 Matrix outInRep = out|in|idx.rep; 270 275 VMatrix triplet.rep = Triplet(outInRep,_.vertex.num,_.vertex.num); 271 VMatrix _.edge.rep := Convert(triplet.rep,"Cholmod.R.Sparse"); 272 Real _.edge.check.rep := VMatMax(_.edge.rep)>1; 273 VMatrix triplet.map = If(!_.edge.check.rep, 276 VMatrix _.edge.repeated := Convert(triplet.rep,"Cholmod.R.Sparse"); 277 VMatrix _.edge.adjacency := Or(_.edge.repeated, Zeros(_.vertex.num)); 278 VMatrix _.edge.repeated := _.edge.repeated - _.edge.adjacency; 279 Real _.edge.check.repeated := VMatSum(_.edge.repeated); 280 Code funTriplet = Case( 281 !_.edge.check.repeated, 274 282 { 275 VMatrix _.edge.adjacency := _.edge.rep;276 Triplet (out|in|idx,_.vertex.num,_.vertex.num)283 Real _.edge.check.repaired := 0; 284 Triplet 277 285 }, 286 removeRepeatedEdges, 278 287 { 279 288 WriteLn("[GraphTools::@Graph "+_.name+"::edge.build()] "+ 280 "There are repeated edges","W"); 281 VMatrix triplet.adj = TripletUnique(outInRep,_.vertex.num,_.vertex.num); 282 VMatrix _.edge.adjacency := Convert(triplet.adj,"Cholmod.R.Sparse"); 283 TripletUnique(out|in|idx,_.vertex.num,_.vertex.num) 289 "There was "<<_.edge.check.repeated+ 290 " repeated edges that has been removed","W"); 291 Real _.edge.check.repaired := _.edge.check.repeated; 292 TripletUnique 293 }, 294 1==1, 295 { 296 WriteLn("[GraphTools::@Graph "+_.name+"::edge.build()] "+ 297 "There are "<<_.edge.check.repeated+" repeated edges " 298 "but they don't will be deleted","W"); 299 Real _.edge.check.repaired := 0; 300 Triplet 284 301 }); 302 VMatrix triplet.map = funTriplet(out|in|idx,_.vertex.num,_.vertex.num); 285 303 VMatrix _.edge.map := Convert(triplet.map,"Cholmod.R.Sparse"); 286 304 True -
tol_pkg/GraphTools/test/test_0001/define.random.graph.tol
rea1b10f re7af41b 5 5 6 6 //Random seed setting 7 Real PutRandomSeed(0); 8 Real rndSeed = GetRandomSeed(0); 7 Real If(ObjectExist("Real","rndSeed"), 8 PutRandomSeed(rndSeed), 9 PutRandomSeed(0)); 10 Real If(ObjectExist("Real","rndSeed"), rndSeed, 11 rndSeed = GetRandomSeed(0)); 12 9 13 WriteLn("Current Random Seed = "<<rndSeed); 10 14 11 Real vertex.num = IntRand(2,1000); 12 Real edge.num = IntRand(1,(vertex.num)^1.6); 13 Real directed = IntRand(0,1); 15 16 Real If(ObjectExist("Real","vertex.num"), vertex.num, 17 vertex.num = IntRand(2,100) ); 18 Real If(ObjectExist("Real","edge.num"), edge.num, 19 edge.num = IntRand(1,(vertex.num)^1.6) ); 20 Real If(ObjectExist("Real","directed"), directed, 21 directed = IntRand(0,1) ); 22 Real If(ObjectExist("Real","removeRepeatedEdges"), removeRepeatedEdges, 23 removeRepeatedEdges = IntRand(0,1) ); 14 24 15 25 WriteLn("Creating "+If(directed,"directed","symmetric")+ … … 17 27 edge.num+" edges ..."); 18 28 Real t0 = Copy(Time); 19 20 29 21 30 GraphTools::@Graph graph = GraphTools::@Graph::New("test_0001",directed); … … 37 46 { Hight = Rand(edge.num, 1, 1, 10) }; 38 47 39 Real graph::edge.build(data );48 Real graph::edge.build(data,removeRepeatedEdges); 40 49 50 Real t1 = Copy(Time); 51 52 WriteLn("Creating time "<<(t1-t0)+" seconds"); -
tol_pkg/GraphTools/test/test_0001/test.tol
rea1b10f re7af41b 12 12 Real numWar0 = Copy(NWarning); 13 13 14 Real rndSeed = 0; 15 Real removeRepeatedEdges = True; 14 16 15 17 #Embed "../../_GraphTools.tol";
Note: See TracChangeset
for help on using the changeset viewer.
