Exemplo n.º 1
0
        public override void main()
        {
            IIntegerInstance  input_key   = (IIntegerInstance)Input_key.Instance;
            IPageNodeInstance input_value = (IPageNodeInstance)Input_value.Instance;
            IIteratorInstance <IKVPair <IString, IDouble> > output = (IIteratorInstance <IKVPair <IString, IDouble> >)Output_data.Instance;

            double slice = input_value.PgrankInstance;
            int    size  = input_value.NeighborsInstance.Count;

            IEnumerator <int> iterator = input_value.NeighborsInstance.GetEnumerator();

            while (iterator.MoveNext())
            {
                string n = iterator.Current.ToString();
                IKVPairInstance <IString, IDouble> kvpair = (IKVPairInstance <IString, IDouble>)Output_data.createItem();
                ((IStringInstance)kvpair.Key).Value   = n;
                ((IDoubleInstance)kvpair.Value).Value = slice / size;
                output.put(kvpair);
            }
            if (size == 0)
            {
                IKVPairInstance <IString, IDouble> kvpair = (IKVPairInstance <IString, IDouble>)Output_data.createItem();
                ((IStringInstance)kvpair.Key).Value   = "X";
                ((IDoubleInstance)kvpair.Value).Value = slice;
                output.put(kvpair);
            }
            IKVPairInstance <IString, IDouble> KV = (IKVPairInstance <IString, IDouble>)Output_data.createItem();

            ((IStringInstance)KV.Key).Value   = input_key.Value.ToString();
            ((IDoubleInstance)KV.Value).Value = 0.0;
            output.put(KV);
        }
Exemplo n.º 2
0
        public void emite()
        {
            string saida = ((IStringInstance)Input_data.Instance).Value;
            IIteratorInstance <IKVPair <IInteger, IPageNode> > output = (IIteratorInstance <IKVPair <IInteger, IPageNode> >)Output_data.Instance;

            double X = 0.0;

            string[] lines = saida.Split(new char[] { System.Environment.NewLine[0] });
            string[] pr    = lines[0].Split(' ');
            if (pr [0].Equals("X"))
            {
                X = double.Parse(pr [1]) / dic.Count;
            }
            else
            {
                System.Console.WriteLine("Error of index to X");
            }
            lines [0] = "";

            foreach (string line in lines)
            {
                if (!line.Trim().Equals(""))
                {
                    string[] prank = line.Split(' ');
                    //if (b && !prank [0].Equals ("X")) {
                    IKVPairInstance <IInteger, IPageNode> kvpair = dic [int.Parse(prank [0])];
                    IPageNodeInstance no = (IPageNodeInstance)kvpair.Value;
                    no.PgrankInstance = double.Parse(prank [1]) + X;
                    output.put(kvpair);
                    //}
                }
            }
            output.finish();
        }
Exemplo n.º 3
0
        public object newInstance(int _id)
        {
            object            o    = newInstance();
            IPageNodeInstance page = (IPageNodeInstance)o;

            page.IdInstance = _id;
            return(this.Instance = page);
        }
Exemplo n.º 4
0
        public override void main()
        {
            Console.WriteLine("################################*IAplicacaoImpl Start ###############################");
            IDoubleInstance tDouble = (IDoubleInstance)T_double.Instance;
            IKVPairInstance <IString, IDouble> tKVPair = (IKVPairInstance <IString, IDouble>)T_kvpair.Instance;  //.newInstance ();
            IIntegerInstance             tInteger      = (IIntegerInstance)T_integer.Instance;
            IIteratorInstance <IInteger> tIterator     = (IIteratorInstance <IInteger>)T_iterator.Instance;      //.newInstance ();
            IStringInstance tString = (IStringInstance)T_string.Instance;

            tDouble.Value  = 0.8;
            tInteger.Value = 8;
            tString.Value  = "Tipo String";

            ((IStringInstance)tKVPair.Key).Value   = tString.Value;
            ((IDoubleInstance)tKVPair.Value).Value = tDouble.Value;

            tIterator.put(tInteger);
            tIterator.finish();

            object o; int count = 0;

            while (tIterator.fetch_next(out o))
            {
                IIntegerInstance oI = (IIntegerInstance)o;
                Console.WriteLine("Item Iterator " + (count++) + ": " + oI.Value);
            }
            Console.WriteLine("tDouble.Value=" + tDouble.Value + " : " + "tInteger.Value=" + tInteger.Value + " : " + "tString.Value=" + tString.Value);
            Console.WriteLine("tKVPair.Key=" + ((IStringInstance)tKVPair.Key).Value + " : " + "tKVPair.Value=" + ((IDoubleInstance)tKVPair.Value).Value);

            IPageNodeInstance instance = (IPageNodeInstance)T_aplicacao_node.Instance;

            ((IIntegerInstance)instance.IdInstance).Value = 8;
            IIntegerInstance item = (IIntegerInstance)T_aplicacao_node.Edge_node.createItem();

            item.Value = 7;

            instance.NeighborsInstance.put(item);
            instance.NeighborsInstance.put(((IIntegerInstance)instance.IdInstance));
            instance.NeighborsInstance.finish();
            while (instance.NeighborsInstance.fetch_next(out o))
            {
                IIntegerInstance II = (IIntegerInstance)o;
                Console.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%% Valor no Iterator=" + II.Value);
            }
            Console.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%% Resultado Id_node=" + ((IIntegerInstance)instance.IdInstance).Value + " PGRank=" + instance.PgrankInstance.Value);

            Console.WriteLine("################################ IAplicacaoImpl End ###############################");
        }
Exemplo n.º 5
0
        private void createPageNodes(string fileContent)
        {
            IIteratorInstance <IKVPair <IInteger, IPageNode> >       output     = (IIteratorInstance <IKVPair <IInteger, IPageNode> >)Output_data.Instance;
            IDictionary <int, IDictionary <int, IPageNodeInstance> > dictionary = new Dictionary <int, IDictionary <int, IPageNodeInstance> >();

            IList <IKVPairInstance <IInteger, IPageNode> > PAGENODES = new List <IKVPairInstance <IInteger, IPageNode> >();

            string[] lines = fileContent.Split(new char[] { System.Environment.NewLine[0] });
            foreach (string line in lines)
            {
                if (!line.Trim().Equals(""))
                {
                    IPageNodeInstance V, W, temp = null;
                    IDictionary <int, IPageNodeInstance> referenceV, referenceW = null;

                    int[]    KEY  = new int[2];
                    string[] vwID = line.Split(' ');
                    for (int k = 0; k < 2; k++)
                    {
                        KEY [k] = int.Parse(vwID [k]);
                    }
                    if (!dictionary.TryGetValue(KEY [0], out referenceV))
                    {
                        IKVPairInstance <IInteger, IPageNode> kvpair = (IKVPairInstance <IInteger, IPageNode>)Output_data.createItem();

                        V            = (IPageNodeInstance)kvpair.Value;
                        V.IdInstance = KEY [0];
                        ((IIntegerInstance)kvpair.Key).Value = V.IdInstance;

                        referenceV           = new Dictionary <int, IPageNodeInstance> ();
                        dictionary [KEY [0]] = referenceV;
                        referenceV [KEY [0]] = V;

                        PAGENODES.Add(kvpair);
                    }
                    if (!dictionary.TryGetValue(KEY [1], out referenceW))
                    {
                        IKVPairInstance <IInteger, IPageNode> kvpair = (IKVPairInstance <IInteger, IPageNode>)Output_data.createItem();

                        W            = (IPageNodeInstance)kvpair.Value;
                        W.IdInstance = KEY [1];
                        ((IIntegerInstance)kvpair.Key).Value = W.IdInstance;

                        referenceW           = new Dictionary <int, IPageNodeInstance> ();
                        dictionary [KEY [1]] = referenceW;
                        referenceW [KEY [1]] = W;

                        PAGENODES.Add(kvpair);
                    }
                    if (!referenceV.TryGetValue(KEY [1], out temp))
                    {
                        V = referenceV [KEY [0]];
                        W = referenceW [KEY [1]];
                        referenceV [KEY [1]] = W;
                        V.NeighborsInstance.Add(W.IdInstance);
                    }
                }
            }
            IEnumerator <IKVPairInstance <IInteger, IPageNode> > iterator = PAGENODES.GetEnumerator();

            while (iterator.MoveNext())
            {
                IKVPairInstance <IInteger, IPageNode> kvpair = iterator.Current;
                IIntegerInstance k = (IIntegerInstance)kvpair.Key;
                output.put(kvpair);
                dic [k.Value] = kvpair;
            }
            output.finish();
        }