Changeset dc274ac in tol


Ignore:
Timestamp:
Nov 6, 2009, 4:33:42 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
17c9671
Parents:
f359e02
Message:

First working version

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1619 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol_pkg/graphtools/graphtools.tol

    rf359e02 rdc274ac  
    1919  If(idx != 0,
    2020  {
    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");
    2323    0
    2424  },
    … …  
    4646  Static Text _.autodoc.member.get = "Returns the stored value corresponding "
    4747  "to this feature related to an individual entity.";
    48   Anything get(Matrix store, Real entity);
     48  Anything get(Matrix store, Real entity)
    4949  ////////////////////////////////////////////////////////////////////////////
    5050};
    … …  
    6464  ////////////////////////////////////////////////////////////////////////////
    6565  {
    66     @Feature.Numeric aux
     66    @Feature.Numeric aux =
    6767    [[
    6868      Text _.name = name;
    6969      Real _.position  = position
    70     ]];
     70    ]]
    7171  };
    7272 
    7373  ////////////////////////////////////////////////////////////////////////////
    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)
    7878  }
    7979};
    … …  
    108108
    109109  ////////////////////////////////////////////////////////////////////////////
    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);
    114114    _.domain[idx]
    115115  }
    … …  
    125125  //In each row of this matrix are stored the values or indexes of features
    126126  //related to an individual entity
    127   Matrix _.value = Rand(0,0,0,0);
     127  Matrix _.data = Rand(0,0,0,0);
    128128
    129129  ////////////////////////////////////////////////////////////////////////////
    … …  
    137137
    138138  ////////////////////////////////////////////////////////////////////////////
    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";
    140141  Real add.feature.numeric(Text name)
    141142  ////////////////////////////////////////////////////////////////////////////
    … …  
    143144    GraphTools::Append.Indexed(
    144145      _.feature,
    145       @Feature.Numeric::New(name, Card(_.feature)),
     146      @Feature.Numeric::New(name, Card(_.feature)+1),
    146147      name)
    147148  };
    148149
    149150  ////////////////////////////////////////////////////////////////////////////
    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";
    151153  Real add.feature.nonnumeric(Text name, Set domain)
    152154  ////////////////////////////////////////////////////////////////////////////
    … …  
    154156    GraphTools::Append.Indexed(
    155157      _.feature,
    156       @Feature.NonNumeric::New(name, Card(_.feature), domain),
     158      @Feature.NonNumeric::New(name, Card(_.feature)+1, domain),
    157159      name)
    158160  };
    … …  
    174176  ////////////////////////////////////////////////////////////////////////////
    175177  {
    176     (_.feature[feature])::get(_.value, entity)
     178    (_.feature[feature])::get(_.data, entity)
    177179  };
    178180
    … …  
    196198  "name graphs in TOL. In abstract, a graph is a pair of sets \n"
    197199  "  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"
    199201  "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";
    201203
    202204  //The identifier of the graph
    203205  Text _.name;
    204   //Set of real numbers that will be indexed by name
    205   Set _.vertex;
     206  //Features of vertices. First feature must be the identifier of vertices
     207  @FeatureSet _.vertex = @FeatureSet::New(?);
    206208  //Number of vertices
    207   Real _.vertex.num = 0;
    208   //Features of vertices
    209   @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(?);
    210212  //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; 
    214214  //Sparse matrix storing index of edge for each cell (out,in)
    215215  VMatrix _.edge.map = Rand(0,0,0,0);
    216216 
    217217  ////////////////////////////////////////////////////////////////////////////
     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  ////////////////////////////////////////////////////////////////////////////
    218262  Text _.autodoc.member.vertex.index = "Returns the index of a vertex or 0 "
    219263  "if it not exists";
    … …  
    225269
    226270  ////////////////////////////////////////////////////////////////////////////
    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  }
    250278
    251279}
Note: See TracChangeset for help on using the changeset viewer.