Exemplo n.º 1
0
        public void pull()
        {
            IKVPairInstance <IVertex, IIterator <IDataTriangle> > input_values_instance = (IKVPairInstance <IVertex, IIterator <IDataTriangle> >)Input_values.Instance;
            IVertexInstance ikey = (IVertexInstance)input_values_instance.Key;
            IIteratorInstance <IDataTriangle> ivalues = (IIteratorInstance <IDataTriangle>)input_values_instance.Value;
            IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value = (IIteratorInstance <IKVPair <IVertex, IDataTriangle> >)Output.Instance;
            object o; int v = ikey.Id;

            ICollection <int> vneighbors = g.neighborsOf(v);

            while (ivalues.fetch_next(out o))
            {
                int w = ((IDataTriangleInstance)o).V;
                int z = ((IDataTriangleInstance)o).W;
                if (vneighbors.Contains(z) && v < z)
                {
                    IList <KeyValuePair <int, int> > l;
                    if (!triangles.TryGetValue(v, out l))
                    {
                        l            = new List <KeyValuePair <int, int> > ();
                        triangles[v] = l;
                    }
                    l.Add(new KeyValuePair <int, int> (w, z));
                    count++;
                    //emite (v, w, z, output_value);
                }
            }
        }
Exemplo n.º 2
0
        public void gust0()
        {
            IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value_instance = (IIteratorInstance <IKVPair <IVertex, IDataTriangle> >)Output.Instance;
            IEnumerator <int> V = g.vertexSet().GetEnumerator();

            while (V.MoveNext())
            {
                int v = V.Current;
                if (!isGhost(v))
                {
                    ICollection <int> vneighbors = g.neighborsOf(v);
                    foreach (int w in vneighbors)
                    {
                        if (v < w)                           //buscam-se os vérices maiores que v e com partições distintas
                        {
                            if (partition[v - 1] != partition[w - 1])
                            {
                                IKVPairInstance <IVertex, IDataTriangle> item = (IKVPairInstance <IVertex, IDataTriangle>)Output.createItem();
                                ((IVertexInstance)item.Key).Id        = w;
                                ((IDataTriangleInstance)item.Value).V = v;
                                output_value_instance.put(item);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        }                                            // Isso é necessário no caso de IKey ser do tipo IVertex.

        #endregion

        #region Algorithm implementation
        public void startup_push()
        {
            IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value_instance = (IIteratorInstance <IKVPair <IVertex, IDataTriangle> >)Output.Instance;
            IEnumerator <int> V = g.vertexSet().GetEnumerator();

            while (V.MoveNext())
            {
                int v = V.Current;
                if (!isGhost(v))
                {
                    ICollection <int> vneighbors = g.neighborsOf(v);
                    foreach (int w in vneighbors)
                    {
                        if (v < w)                           //buscam-se os vérices maiores
                        {
                            if (isGhost(w))
                            {
                                IKVPairInstance <IVertex, IDataTriangle> item = (IKVPairInstance <IVertex, IDataTriangle>)Output.createItem();
                                IVertexInstance       ok = (IVertexInstance)item.Key;
                                IDataTriangleInstance ov = (IDataTriangleInstance)item.Value;
                                ok.Id = w;
                                ov.V  = v;
                                output_value_instance.put(item);
                            }
                            else
                            {
                                IList <KeyValuePair <int, int> > l;
                                if (!triangles.TryGetValue(v, out l))
                                {
                                    l            = new List <KeyValuePair <int, int> > ();
                                    triangles[v] = l;
                                }

                                IEnumerator <int> wneighbors = g.iteratorNeighborsOf(w);
                                while (wneighbors.MoveNext())
                                {
                                    int z = wneighbors.Current;
                                    if (w < z && vneighbors.Contains(z))
                                    {
                                        l.Add(new KeyValuePair <int, int> (w, z));

                                        count++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void gust1()
        {
            IIteratorInstance <IKVPair <IVertex, IDataTriangle> > output_value_instance = (IIteratorInstance <IKVPair <IVertex, IDataTriangle> >)Output.Instance;
            IKVPairInstance <IVertex, IDataTriangle> item;
            IEnumerator <int> next = messages.Keys.GetEnumerator();

            while (next.MoveNext())
            {
                int v = next.Current;
                IList <KeyValuePair <int, int> > l;
                messages.TryRemove(v, out l);

                ICollection <int> vneighbors = g.neighborsOf(v);                 // devolve ISet<int>, de modo que Contains() é O(1)
                foreach (KeyValuePair <int, int> kv in l)
                {
                    int z = kv.Key;
                    int w = kv.Value;
                    if (vneighbors.Contains(z))                        //Se z é vizinho de v, forma-se um triangulo

                    // Descomentar para imprimir todos os triangulos
//						item = (IKVPairInstance<IVertex,IDataTriangle>)Output.createItem ();
//						((IVertexInstance)item.Key).Id = v;     //v menor que w
//						((IDataTriangleInstance)item.Value).V = w; //w menor que z
//						((IDataTriangleInstance)item.Value).W = z;
//						output_value_instance.put (item);

                    {
                        count++;
                    }
                }
            }
            item = (IKVPairInstance <IVertex, IDataTriangle>)Output.createItem();
            ((IVertexInstance)item.Key).Id = count;
            //IDataTriangleInstance dt = ((IDataTriangleInstance)item.Value);
            //item.Value = dt;
            output_value_instance.put(item);
        }