Changeset f7b99ac in tol


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

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

Location:
tol_pkg/graphtools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tol_pkg/graphtools/graphtools.tol

    r17c9671 rf7b99ac  
    169169  };
    170170
    171 
    172171  ////////////////////////////////////////////////////////////////////////////
    173172  Text _.autodoc.member.get = "Returns the value of a feature for an entity";
    … …  
    176175  ////////////////////////////////////////////////////////////////////////////
    177176  {
    178     (_.feature[feature])::get(_.data, entity)
     177    @Feature.Abstract f = _.feature[feature];
     178    f::get(_.data, entity)
    179179  };
    180180
    … …  
    185185  ////////////////////////////////////////////////////////////////////////////
    186186  {
    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    })
    188191  }
    189192
    … …  
    204207  //The identifier of the graph
    205208  Text _.name;
     209  //Indicates if the graph is directed or symmetric
     210  Real _.directed;
    206211  //Features of vertices. First feature must be the identifier of vertices
    207212  @FeatureSet _.vertex = @FeatureSet::New(?);
    … …  
    214219  //Sparse matrix storing index of edge for each cell (out,in)
    215220  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
    217224  ////////////////////////////////////////////////////////////////////////////
    218225  Static Text _.autodoc.member.New = "Creates a new instance of "
    219226  "Class @Graph";
    220   Static @Graph New(Text name)
     227  Static @Graph New(Text name, Real directed)
    221228  ////////////////////////////////////////////////////////////////////////////
    222229  {
    223230    @Graph aux =
    224231    [[
    225       Text _.name = name
     232      Text _.name = name;
     233      Real _.directed = directed
    226234    ]]
    227235  };
    … …  
    239247    Real _.vertex::add.feature.nonnumeric("Identifier", vertex.names);
    240248    Matrix _.vertex::_.data := DifEq(1/(1-B),Rand(_.vertex.num,1,1,1));
     249    Real _.edge::add.feature.numeric("Output");
    241250    Real _.edge::add.feature.numeric("Input");
    242     Real _.edge::add.feature.numeric("Output");
    243251    True
    244252  };
    … …  
    249257  ////////////////////////////////////////////////////////////////////////////
    250258  {
    251     Matrix _.edge::_.data := data;
    252259    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));
    255265    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);
    257267    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    });
    258277    True
    259278  };
    … …  
    271290  Text _.autodoc.member.edge.index = "Returns the index of an edge or 0 "
    272291  "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_));
    276297    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)
    277306  }
    278307
  • tol_pkg/graphtools/test/test_0001/test.tol

    r17c9671 rf7b99ac  
    1414#Embed "../../graphtools.tol";
    1515
    16 Real vertex.num =   20000;
    17 Real edge.num   =  300000;
     16Real vertex.num =  2000;
     17Real edge.num   =  300;
    1818
    19 WriteLn("Creating graph with  "<<vertex.num+ " vertices and "<<
     19WriteLn("Creating graph with  "<<vertex.num+ " vertices and close to "<<
    2020        edge.num+" edges ...");
    2121Real t0 = Copy(Time);
    2222
    23 GraphTools::@Graph graph = GraphTools::@Graph::New("test_0001");
     23GraphTools::@Graph graph = GraphTools::@Graph::New("test_0001",True);
    2424
    2525Real graph::initialize(Set { vertex.names = For(1,vertex.num,Text(Real k)
    2626{
    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")
    2929})});
    3030
    … …  
    3232Real graph::_.edge::add.feature.numeric("Hight");
    3333
    34 Real graph::edge.build(Matrix { data =
     34
     35Matrix data =
    3536  { InOut  = RandCombination(edge.num,vertex.num,2) } |
    3637  { 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
     40Real graph::edge.build(data);
     41
     42
     43Real edge.idx = IntRand(1,edge.num);
     44Set edge.info = graph::edge.get.all(edge.idx);
     45Real edge.idx.1 = graph::edge.index(edge.info[1], edge.info[2]);
     46Real edge.idx.2 = graph::edge.index(edge.info[2], edge.info[1]);
     47
     48WriteLn("edge.idx = "<<edge.idx);
     49WriteLn("edge.idx.1 = "<<edge.idx.1);
     50WriteLn("edge.idx.2 = "<<edge.idx.2);
     51
     52Real ok.1 = edge.idx.1==edge.idx;
     53Real ok.2 = edge.idx.2==edge.idx;
    3954
    4055Real t1 = Copy(Time);
Note: See TracChangeset for help on using the changeset viewer.