Changeset f7b99ac in tol
- Timestamp:
- Nov 6, 2009, 7:35:44 PM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- e8916d6
- Parents:
- 17c9671
- Location:
- tol_pkg/graphtools
- Files:
-
- 2 edited
-
graphtools.tol (modified) (8 diffs)
-
test/test_0001/test.tol (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol_pkg/graphtools/graphtools.tol
r17c9671 rf7b99ac 169 169 }; 170 170 171 172 171 //////////////////////////////////////////////////////////////////////////// 173 172 Text _.autodoc.member.get = "Returns the value of a feature for an entity"; … … 176 175 //////////////////////////////////////////////////////////////////////////// 177 176 { 178 (_.feature[feature])::get(_.data, entity) 177 @Feature.Abstract f = _.feature[feature]; 178 f::get(_.data, entity) 179 179 }; 180 180 … … 185 185 //////////////////////////////////////////////////////////////////////////// 186 186 { 187 SetRow(EvalSet(_.feature, Anything(Real f) { get(entity, f) })) 187 EvalSet(_.feature, Anything get.all.cycle(@FeatureSet f) 188 { 189 f::get(_.data, entity) 190 }) 188 191 } 189 192 … … 204 207 //The identifier of the graph 205 208 Text _.name; 209 //Indicates if the graph is directed or symmetric 210 Real _.directed; 206 211 //Features of vertices. First feature must be the identifier of vertices 207 212 @FeatureSet _.vertex = @FeatureSet::New(?); … … 214 219 //Sparse matrix storing index of edge for each cell (out,in) 215 220 VMatrix _.edge.map = Rand(0,0,0,0); 216 221 VMatrix _.edge.map.rep = Rand(0,0,0,0); 222 Real _.edge.check.rep = ?; 223 217 224 //////////////////////////////////////////////////////////////////////////// 218 225 Static Text _.autodoc.member.New = "Creates a new instance of " 219 226 "Class @Graph"; 220 Static @Graph New(Text name )227 Static @Graph New(Text name, Real directed) 221 228 //////////////////////////////////////////////////////////////////////////// 222 229 { 223 230 @Graph aux = 224 231 [[ 225 Text _.name = name 232 Text _.name = name; 233 Real _.directed = directed 226 234 ]] 227 235 }; … … 239 247 Real _.vertex::add.feature.nonnumeric("Identifier", vertex.names); 240 248 Matrix _.vertex::_.data := DifEq(1/(1-B),Rand(_.vertex.num,1,1,1)); 249 Real _.edge::add.feature.numeric("Output"); 241 250 Real _.edge::add.feature.numeric("Input"); 242 Real _.edge::add.feature.numeric("Output");243 251 True 244 252 }; … … 249 257 //////////////////////////////////////////////////////////////////////////// 250 258 { 251 Matrix _.edge::_.data := data;252 259 Real _.edge.num := Rows(data); 253 Matrix in = SubCol(data,[[1]]); 254 Matrix out = SubCol(data,[[2]]); 260 Matrix out_ = SubCol(data,[[1]]); 261 Matrix in_ = SubCol(data,[[2]]); 262 Matrix out = If(_.directed, out_, Min(in_, out_)); 263 Matrix in = If(_.directed, in_, Max(in_, out_)); 264 Matrix _.edge::_.data := out | in | SubCol(data,Range(3,Columns(data),1)); 255 265 Matrix idx = DifEq(1/(1-B),Rand(_.edge.num,1,1,1)); 256 VMatrix triplet = Triplet( in|out|idx,_.vertex.num,_.vertex.num);266 VMatrix triplet = Triplet(out|in|idx,_.vertex.num,_.vertex.num); 257 267 VMatrix _.edge.map := Convert(triplet,"Cholmod.R.Sparse"); 268 Matrix idx.rep = Rand(_.edge.num,1,1,1); 269 VMatrix triplet.rep = Triplet(out|in|idx.rep,_.vertex.num,_.vertex.num); 270 VMatrix _.edge.map.rep := Convert(triplet.rep,"Cholmod.R.Sparse"); 271 Real _.edge.check.rep := VMatMax(_.edge.map.rep)>1; 272 If(_.edge.check.rep, 273 { 274 WriteLn("[GraphTools::@Graph "+_.name+"::edge.build()] "+ 275 "There are repeated edges","E") 276 }); 258 277 True 259 278 }; … … 271 290 Text _.autodoc.member.edge.index = "Returns the index of an edge or 0 " 272 291 "if it not exists"; 273 Real edge.index(Real in, Real out) 274 //////////////////////////////////////////////////////////////////////////// 275 { 292 Real edge.index(Real out_, Real in_) 293 //////////////////////////////////////////////////////////////////////////// 294 { 295 Real out = If(_.directed, out_, Min(in_, out_)); 296 Real in = If(_.directed, in_, Max(in_, out_)); 276 297 VMatDat(_.edge.map, in, out) 298 }; 299 300 //////////////////////////////////////////////////////////////////////////// 301 Text _.autodoc.member.edge.get.all = ""; 302 Set edge.get.all(Real idx) 303 //////////////////////////////////////////////////////////////////////////// 304 { 305 _.edge::get.all(idx) 277 306 } 278 307 -
tol_pkg/graphtools/test/test_0001/test.tol
r17c9671 rf7b99ac 14 14 #Embed "../../graphtools.tol"; 15 15 16 Real vertex.num = 20000;17 Real edge.num = 300 000;16 Real vertex.num = 2000; 17 Real edge.num = 300; 18 18 19 WriteLn("Creating graph with "<<vertex.num+ " vertices and "<<19 WriteLn("Creating graph with "<<vertex.num+ " vertices and close to "<< 20 20 edge.num+" edges ..."); 21 21 Real t0 = Copy(Time); 22 22 23 GraphTools::@Graph graph = GraphTools::@Graph::New("test_0001" );23 GraphTools::@Graph graph = GraphTools::@Graph::New("test_0001",True); 24 24 25 25 Real graph::initialize(Set { vertex.names = For(1,vertex.num,Text(Real k) 26 26 { 27 "Key_"<<FormatReal(k," %6.0f")<<28 "_"+FormatReal(IntRand(0,999999999),"% 9.0lf")27 "Key_"<<FormatReal(k,"0%6.0f")<< 28 "_"+FormatReal(IntRand(0,999999999),"%09.0lf") 29 29 })}); 30 30 … … 32 32 Real graph::_.edge::add.feature.numeric("Hight"); 33 33 34 Real graph::edge.build(Matrix { data = 34 35 Matrix data = 35 36 { InOut = RandCombination(edge.num,vertex.num,2) } | 36 37 { Length = Rand(edge.num, 1, 10, 100) } | 37 { Hight = Rand(edge.num, 1, 1, 10) } 38 }); 38 { Hight = Rand(edge.num, 1, 1, 10) }; 39 40 Real graph::edge.build(data); 41 42 43 Real edge.idx = IntRand(1,edge.num); 44 Set edge.info = graph::edge.get.all(edge.idx); 45 Real edge.idx.1 = graph::edge.index(edge.info[1], edge.info[2]); 46 Real edge.idx.2 = graph::edge.index(edge.info[2], edge.info[1]); 47 48 WriteLn("edge.idx = "<<edge.idx); 49 WriteLn("edge.idx.1 = "<<edge.idx.1); 50 WriteLn("edge.idx.2 = "<<edge.idx.2); 51 52 Real ok.1 = edge.idx.1==edge.idx; 53 Real ok.2 = edge.idx.2==edge.idx; 39 54 40 55 Real t1 = Copy(Time);
Note: See TracChangeset
for help on using the changeset viewer.
