/* -*- mode: C++ -*- */ ////////////////////////////////////////////////////////////////////////////// // FILE : graphtools.tol // PURPOSE: Defines NameBlock GraphTools ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// NameBlock GraphTools = ////////////////////////////////////////////////////////////////////////////// [[ ////////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.Append.Indexed = "Adds and index a new element to a " "set and returns 0 if it´s all right. If an element with given name exists " "already then returns its index, else returns 0"; Real Append.Indexed(Set set, Anything newElement, Text name) ////////////////////////////////////////////////////////////////////////////// { Real idx = FindIndexByName(set, name ); If(idx != 0, { WriteLn("[GraphTools::Append.Indexed] Cannot add an existant element "+ Name(set)+"["<1; If(_.edge.check.rep, { WriteLn("[GraphTools::@Graph "+_.name+"::edge.build()] "+ "There are repeated edges","W") }); True }; //////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.get.vertex.names = "Returns the names of all " "vertices"; Set get.vertex.names(Real void) //////////////////////////////////////////////////////////////////////////// { ((_.vertex::_.feature)[1])::_.domain }; //////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.get.vertex.name = "Returns the name of one " "vertex"; Text get.vertex.name(Real idx) //////////////////////////////////////////////////////////////////////////// { (((_.vertex::_.feature)[1])::_.domain)[idx] }; //////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.get.vertex.index = "Returns the index of a vertex or 0 " "if it not exists"; Real get.vertex.index(Text name) //////////////////////////////////////////////////////////////////////////// { FindIndexByName(((_.vertex::_.feature)[1])::_.domain, name ) }; //////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.get.vertex.features = "Returns all the features for " "an vertex"; Set get.vertex.features(Real vertex.idx) //////////////////////////////////////////////////////////////////////////// { _.vertex::get.all(vertex.idx) }; //////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.get.vertex.feature = "Returns specified feature for " "an vertex. Feature identifier can be the name (Text) or the position " "(Real)"; Anything get.vertex.feature( Real vertex.idx, Anything feature.id) //Text name or Real num //////////////////////////////////////////////////////////////////////////// { _.edge::get(vertex.idx, feature.id) }; //////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.get.edge.index = "Returns the index of an edge or 0 " "if it not exists"; Real get.edge.index(Real out_, Real in_) //////////////////////////////////////////////////////////////////////////// { Real out = If(_.directed, out_, Min(in_, out_)); Real in = If(_.directed, in_, Max(in_, out_)); Real edge.idx = VMatDat(_.edge.map, out, in); edge.idx / VMatDat(_.edge.adjacency, out, in) }; //////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.edge.exists = "Returns true if exists the edge from " "out_ to in_"; Real edge.exists(Real out_, Real in_) //////////////////////////////////////////////////////////////////////////// { get.edge.index(out_, in_)!=0 }; //////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.get.edge.features = "Returns all the features for " "an edge"; Set get.edge.features(Real edge.idx) //////////////////////////////////////////////////////////////////////////// { _.edge::get.all(edge.idx) }; //////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.get.edge.feature = "Returns specified feature for " "an edge. Feature identifier can be the name (Text) or the position (Real"; Anything get.edge.feature( Real edge.idx, Anything feature.id) //Text name or Real num //////////////////////////////////////////////////////////////////////////// { _.edge::get(edge.idx, feature.id) } /* PENDIENTE! : Funciones de adyacencia o vecindad de vértices http://www.absoluteastronomy.com/topics/Adjacency_matrix //////////////////////////////////////////////////////////////////////////// Crea las matrices de adyancencia hasta un orden pedido por el usuario y las guarda en un set. Sólo crea las que no existan aún. Sólo devuelve la del orden solicitado. Matrix get.adyacency(Real order) //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// Devuelve los vértices adyacentes de salida de orden dado para el vértice especificado. V -> ... (n-1) ... -> U Set get.adyacency.output(Real V, Real order) //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// Devuelve los vértices adyacentes U de entrada de orden dado para el vértice especificado. U -> ... (n-1) ... -> V Set get.adyacency.input(Real V, Real order) //////////////////////////////////////////////////////////////////////////// */ } ]];