Changeset dc274ac in tol
- Timestamp:
- Nov 6, 2009, 4:33:42 PM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 17c9671
- Parents:
- f359e02
- File:
-
- 1 edited
-
tol_pkg/graphtools/graphtools.tol (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol_pkg/graphtools/graphtools.tol
rf359e02 rdc274ac 19 19 If(idx != 0, 20 20 { 21 WriteLn("[Graph ::Append.Indexed] Cannot add an existant element "22 "["<<idx+"]"+name,"E");21 WriteLn("[GraphTools::Append.Indexed] Cannot add an existant element "+ 22 Name(set)+"["<<idx+"] with name "+ name,"E"); 23 23 0 24 24 }, … … 46 46 Static Text _.autodoc.member.get = "Returns the stored value corresponding " 47 47 "to this feature related to an individual entity."; 48 Anything get(Matrix store, Real entity) ;48 Anything get(Matrix store, Real entity) 49 49 //////////////////////////////////////////////////////////////////////////// 50 50 }; … … 64 64 //////////////////////////////////////////////////////////////////////////// 65 65 { 66 @Feature.Numeric aux 66 @Feature.Numeric aux = 67 67 [[ 68 68 Text _.name = name; 69 69 Real _.position = position 70 ]] ;70 ]] 71 71 }; 72 72 73 73 //////////////////////////////////////////////////////////////////////////// 74 Anything get(Matrix value, Real entity)75 //////////////////////////////////////////////////////////////////////////// 76 { 77 MatDat( value, entity, _.position)74 Anything get(Matrix store, Real entity) 75 //////////////////////////////////////////////////////////////////////////// 76 { 77 MatDat(store, entity, _.position) 78 78 } 79 79 }; … … 108 108 109 109 //////////////////////////////////////////////////////////////////////////// 110 Anything get(Matrix value, Real entity)111 //////////////////////////////////////////////////////////////////////////// 112 { 113 Real idx = MatDat( value, entity, _.position);110 Anything get(Matrix store, Real entity) 111 //////////////////////////////////////////////////////////////////////////// 112 { 113 Real idx = MatDat(store, entity, _.position); 114 114 _.domain[idx] 115 115 } … … 125 125 //In each row of this matrix are stored the values or indexes of features 126 126 //related to an individual entity 127 Matrix _. value= Rand(0,0,0,0);127 Matrix _.data = Rand(0,0,0,0); 128 128 129 129 //////////////////////////////////////////////////////////////////////////// … … 137 137 138 138 //////////////////////////////////////////////////////////////////////////// 139 Static Text _.autodoc.member.add.feature = "Adds a new numerical feature"; 139 Static Text _.autodoc.member.add.feature.numeric = 140 "Adds a new numerical feature"; 140 141 Real add.feature.numeric(Text name) 141 142 //////////////////////////////////////////////////////////////////////////// … … 143 144 GraphTools::Append.Indexed( 144 145 _.feature, 145 @Feature.Numeric::New(name, Card(_.feature) ),146 @Feature.Numeric::New(name, Card(_.feature)+1), 146 147 name) 147 148 }; 148 149 149 150 //////////////////////////////////////////////////////////////////////////// 150 Static Text _.autodoc.member.add.feature="Adds a new non numerical feature"; 151 Static Text _.autodoc.member.add.feature.nonnumeric= 152 "Adds a new non numerical feature"; 151 153 Real add.feature.nonnumeric(Text name, Set domain) 152 154 //////////////////////////////////////////////////////////////////////////// … … 154 156 GraphTools::Append.Indexed( 155 157 _.feature, 156 @Feature.NonNumeric::New(name, Card(_.feature) , domain),158 @Feature.NonNumeric::New(name, Card(_.feature)+1, domain), 157 159 name) 158 160 }; … … 174 176 //////////////////////////////////////////////////////////////////////////// 175 177 { 176 (_.feature[feature])::get(_. value, entity)178 (_.feature[feature])::get(_.data, entity) 177 179 }; 178 180 … … 196 198 "name graphs in TOL. In abstract, a graph is a pair of sets \n" 197 199 " V : a finite set of vertices \n" 198 " E : a finite set of edges relating an input vertex with an output \n" ;200 " E : a finite set of edges relating an input vertex with an output \n" 199 201 "Each vertex has a set of features related with the system\n" 200 "Each edge also has its own set of features.\n" 202 "Each edge also has its own set of features.\n"; 201 203 202 204 //The identifier of the graph 203 205 Text _.name; 204 // Set of real numbers that will be indexed by name205 Set _.vertex;206 //Features of vertices. First feature must be the identifier of vertices 207 @FeatureSet _.vertex = @FeatureSet::New(?); 206 208 //Number of vertices 207 Real _.vertex.num = 0; 208 //Features of vertices209 @FeatureSet _. vertex.feature = 0;209 Real _.vertex.num = 0; 210 //Features of edges. First two features must be input and output vertex 211 @FeatureSet _.edge = @FeatureSet::New(?); 210 212 //Number of edges 211 Real _.edge.num = 0; 212 //Features of edges. First features must be input and output vertex 213 @FeatureSet _.edge.feature = 0; 213 Real _.edge.num = 0; 214 214 //Sparse matrix storing index of edge for each cell (out,in) 215 215 VMatrix _.edge.map = Rand(0,0,0,0); 216 216 217 217 //////////////////////////////////////////////////////////////////////////// 218 Static Text _.autodoc.member.New = "Creates a new instance of " 219 "Class @Graph"; 220 Static @Graph New(Text name) 221 //////////////////////////////////////////////////////////////////////////// 222 { 223 @Graph aux = 224 [[ 225 Text _.name = name 226 ]] 227 }; 228 229 //////////////////////////////////////////////////////////////////////////// 230 Real initialize(Set vertex.names) 231 //////////////////////////////////////////////////////////////////////////// 232 { 233 Real _.vertex.num := Card(vertex.names); 234 Set For(1,_.vertex.num, Real(Real k) 235 { 236 Text PutName(vertex.names[k], vertex.names[k]); 237 k 238 }); 239 Real _.vertex::add.feature.nonnumeric("Identifier", vertex.names); 240 Matrix _.vertex::_.data := DifEq(1/(1-B),Rand(_.vertex.num,1,1,1)); 241 Real _.edge::add.feature.numeric("Input"); 242 Real _.edge::add.feature.numeric("Output"); 243 True 244 }; 245 246 //////////////////////////////////////////////////////////////////////////// 247 Text _.autodoc.member.edge.build = ""; 248 Real edge.build(Matrix data) 249 //////////////////////////////////////////////////////////////////////////// 250 { 251 Matrix _.edge::_.data := data; 252 Real _.edge.num := Rows(data); 253 Matrix in = SubCol(data,[[1]]); 254 Matrix out = SubCol(data,[[2]]); 255 Matrix idx = DifEq(1/(1-B),Rand(_.edge.num,1,1,1)); 256 VMatrix triplet = Triplet(in|out|idx,_.vertex.num,_.vertex.num); 257 VMatrix _.edge.map := Convert(triplet,"Cholmod.R.Sparse"); 258 True 259 }; 260 261 //////////////////////////////////////////////////////////////////////////// 218 262 Text _.autodoc.member.vertex.index = "Returns the index of a vertex or 0 " 219 263 "if it not exists"; … … 225 269 226 270 //////////////////////////////////////////////////////////////////////////// 227 Text _.autodoc.member.vertex.add = "Adds and index a new vertex and " 228 "returns 0 if itŽs all right. If a vertex with given name exists already " 229 "then returns its index, else returns 0"; 230 Real vertex.add(Text name, Matrix feature.values) 231 //////////////////////////////////////////////////////////////////////////// 232 { 233 Real n = Card(_.vertex); 234 Real ok = Graph::Append.Indexed(_.vertex,n,name); 235 Matrix _.vertex.feature := _.vertex.feature << feature.values 236 }; 237 238 //////////////////////////////////////////////////////////////////////////// 239 Text _.autodoc.member.edge.build = ""; 240 Real edge.add(Matrix feature.data) 241 //////////////////////////////////////////////////////////////////////////// 242 { 243 Real c = Columns(data) 244 If(c<2, False, 245 { 246 _.edge.feature := SubCol(data,Range(3,c,1))); 247 True 248 }) 249 }; 271 Text _.autodoc.member.edge.index = "Returns the index of an edge or 0 " 272 "if it not exists"; 273 Real edge.index(Real in, Real out) 274 //////////////////////////////////////////////////////////////////////////// 275 { 276 VMatDat(_.edge.map, in, out) 277 } 250 278 251 279 }
Note: See TracChangeset
for help on using the changeset viewer.
