Exemplo n.º 1
0
        private List <Token> ConstructSkeletonGraph(IList <Node> nodes, List <Tuple <Node, Node> > edges)
        {
            TokenDistribution tokenDistribution = new TokenDistribution();
            Token             token;


            IList <Node> Vertices = new List <Node>();
            List <Token> TokenwithDistanceMessage = new List <Token>();
            List <Tuple <Node, Node> > Edges      = new List <Tuple <Node, Node> >();

            //int MaxHopDistance = 15;

            Vertices = nodes;
            Edges    = edges;

            for (int i = 0; i < Vertices.Count; i++)
            {
                List <Tuple <Node, Node, int, int> > dupliccatetokenmessage = new List <Tuple <Node, Node, int, int> >();
                token = tokenDistribution.LocalBroadcast(Edges, Vertices[i], Vertices);

                for (int j = 0; j < token.TokenMessage.Count; j++)
                {
                    //if (token.TokenMessage[j].Item3 < MaxHopDistance)
                    //{
                    dupliccatetokenmessage.Add(token.TokenMessage[j]);

                    //}
                }
                Token duplicate = new Token(token.SourceID, dupliccatetokenmessage);
                TokenwithDistanceMessage.Add(duplicate);
            }
            return(TokenwithDistanceMessage);
        }
Exemplo n.º 2
0
        /*node to nodes within the max hop distance (Exact)*/
        private List <Token> ConstructSkeletonGraph()
        {
            TokenDistribution tokenDistribution = new TokenDistribution();
            Token             token;

            LocalEdge    localEdge   = new LocalEdge();
            GraphLayout  graphLayout = new GraphLayout();
            IList <Node> Vertices    = new List <Node>();
            List <Token> TokenwithDistanceMessage = new List <Token>();
            List <Tuple <Node, Node> > Edges      = new List <Tuple <Node, Node> >();

            int MaxHopDistance = 20;

            Vertices = graphLayout.GetGraphLayout();
            Edges    = localEdge.GetGrapgEdges(Vertices);

            for (int i = 0; i < Vertices.Count; i++)
            {
                List <Tuple <Node, Node, int, int> > dupliccatetokenmessage = new List <Tuple <Node, Node, int, int> >();
                token = tokenDistribution.LocalBroadcast(Edges, Vertices[i], Vertices);

                for (int j = 0; j < token.TokenMessage.Count; j++)
                {
                    if (token.TokenMessage[j].Item3 < MaxHopDistance)
                    {
                        dupliccatetokenmessage.Add(token.TokenMessage[j]);
                    }
                }

                Token duplicate = new Token(token.SourceID, dupliccatetokenmessage);
                TokenwithDistanceMessage.Add(duplicate);
            }
            return(TokenwithDistanceMessage);
        }
Exemplo n.º 3
0
        private List <Token> ConstructedSkeletonGraph(IList <Node> nodes, List <Tuple <Node, Node> > Edges)
        {
            TokenDistribution        tokenDistribution = new TokenDistribution();
            List <Token>             EveryNodesDistancWithinMaxHopDistance = new List <Token>();
            List <Token>             EveryNodesDistancWithinMaxHopDistanceofMarkedNodes = new List <Token>();
            List <Tuple <int, int> > tokencopies = new List <Tuple <int, int> >();
            List <Tuple <int, int> > tokencopieswithrespectivenodes = new List <Tuple <int, int> >();

            tokencopies = tokenDistribution.TokenMultiplication(nodes, Edges);
            tokencopieswithrespectivenodes        = tokenDistribution.GetNumberofNodeswithTokenCopies(tokencopies, nodes, Edges);
            EveryNodesDistancWithinMaxHopDistance = ConstructSkeletonGraph(nodes, Edges);

            //Marked nodes threshold of number of copies
            int TokenCopiesThreshold = 5000;

            for (int i = 0; i < EveryNodesDistancWithinMaxHopDistance.Count; i++)
            {
                for (int j = 0; j < tokencopieswithrespectivenodes.Count; j++)
                {
                    if (EveryNodesDistancWithinMaxHopDistance[i].SourceID == tokencopieswithrespectivenodes[j].Item1 && tokencopieswithrespectivenodes[j].Item2 <= TokenCopiesThreshold)
                    {
                        EveryNodesDistancWithinMaxHopDistanceofMarkedNodes.Add(EveryNodesDistancWithinMaxHopDistance[i]);
                    }
                }
            }

            return(EveryNodesDistancWithinMaxHopDistanceofMarkedNodes);
        }
Exemplo n.º 4
0
        private List<Tuple<Node, Node, int>> GetEdgesWithDistance(List<Tuple<Node, Node>> edges)
        {
            List<Tuple<Node, Node, int>> EdgeDistances = new List<Tuple<Node, Node, int>>();
            TokenDistribution tokenDistribution = new TokenDistribution();
            int distance;
            for (int i = 0; i < edges.Count; i++)
            {
                
                distance = tokenDistribution.GetDistance(edges[i].Item1, edges[i].Item2);
                EdgeDistances.Add(Tuple.Create(edges[i].Item1, edges[i].Item2, distance));
            }

            return EdgeDistances;
        }
        private List <Token> GetEveryNodesDistance(IList <Node> nodes, List <Tuple <Node, Node> > edges)
        {
            TokenDistribution tokenDistribution = new TokenDistribution();
            Token             token;


            IList <Node> Vertices = new List <Node>();
            List <Token> TokenwithDistanceMessage = new List <Token>();
            List <Tuple <Node, Node> > Edges      = new List <Tuple <Node, Node> >();



            Vertices = nodes;
            Edges    = edges;

            for (int i = 0; i < Vertices.Count; i++)
            {
                token = tokenDistribution.LocalBroadcast(Edges, Vertices[i], Vertices);
                TokenwithDistanceMessage.Add(token);
            }
            return(TokenwithDistanceMessage);
        }
Exemplo n.º 6
0
        private List <Token> GetEveryNodesDistance()
        {
            TokenDistribution tokenDistribution = new TokenDistribution();
            Token             token;

            LocalEdge    localEdge   = new LocalEdge();
            GraphLayout  graphLayout = new GraphLayout();
            IList <Node> Vertices    = new List <Node>();
            List <Token> TokenwithDistanceMessage = new List <Token>();
            List <Tuple <Node, Node> > Edges      = new List <Tuple <Node, Node> >();



            Vertices = graphLayout.GetGraphLayout();
            Edges    = localEdge.GetGrapgEdges(Vertices);

            for (int i = 0; i < Vertices.Count; i++)
            {
                token = tokenDistribution.LocalBroadcast(Edges, Vertices[i], Vertices);
                TokenwithDistanceMessage.Add(token);
            }
            return(TokenwithDistanceMessage);
        }
Exemplo n.º 7
0
        void Display()
        {
            IList <Node> nodes       = new List <Node>();
            GraphLayout  graphLayout = new GraphLayout();

            nodes = graphLayout.GetGraphLayout(); //recomment

            List <Token> skeletongraph           = new List <Token>();
            List <Token> Constructedskeltongraph = new List <Token>();

            foreach (var item in nodes)
            {
                Graph.Series["Vertices"].Points.AddXY(item.X, item.Y);
            }

            List <Tuple <Node, Node> > Edges = new List <Tuple <Node, Node> >();
            LocalEdge localEdge = new LocalEdge();

            Edges = localEdge.GetGrapgEdges(nodes); // recommment

            //Edges = localEdge.GetGrapgEdges(nodes);
            //has to be recommented

            TokenDistribution tokenDistribution = new TokenDistribution();

            //contruct a skeleton graph
            Constructedskeltongraph = ConstructedSkeletonGraph(nodes, Edges);

            APSP aPSP = new APSP();
            Node Sourcenode, Destinationnode;

            Sourcenode      = nodes[0];
            Destinationnode = nodes[nodes.Count - 1];

            SSSP sSSP = new SSSP();


            Graph.Series["SourceNode"].Points.AddXY(Sourcenode.X, Sourcenode.Y);
            Graph.Series["DestinationNode"].Points.AddXY(Destinationnode.X, Destinationnode.Y);

            if (Edges?.Count > 0)
            {
                foreach (var item in Edges)
                {
                    Graph.Series["Edges"].Points.AddXY(item.Item1.X, item.Item1.Y);
                    Graph.Series["Edges"].Points.AddXY(item.Item2.X, item.Item2.Y);
                }
            }
            // till here

            ////ExactAlgorithm

            //Stopwatch stopwatch = new Stopwatch();
            //stopwatch.Start();
            //var ExactApspshortestpath = aPSP.ExactAPSP(Sourcenode, Destinationnode);

            //foreach (var item in ExactApspshortestpath)
            //{
            //    Graph.Series["ExactAPSP"].Points.AddXY(item.Item1.X, item.Item1.Y);
            //    Graph.Series["ExactAPSP"].Points.AddXY(item.Item2.X, item.Item2.Y);

            //}
            //stopwatch.Stop();
            //var time = stopwatch.Elapsed;
            //int i = 0;

            ////Approximate APSP
            //Stopwatch stopwatch = new Stopwatch();
            //stopwatch.Start();

            //var ApproximateApspshortestpath = aPSP.ApproximateAPSP(Sourcenode, Destinationnode);
            //foreach (var item in ApproximateApspshortestpath)
            //{
            //    Graph.Series["ApproximateAPSP"].Points.AddXY(item.Item1.X, item.Item1.Y);
            //    Graph.Series["ApproximateAPSP"].Points.AddXY(item.Item2.X, item.Item2.Y);

            //}
            //stopwatch.Stop();
            //var time = stopwatch.Elapsed;
            //int i = 0;

            ////ExactAlgorithm

            //Stopwatch stopwatch = new Stopwatch();
            //stopwatch.Start();
            //var ExactApspshortestpath = aPSP.ExactAPSPAlgorithm(Sourcenode, Destinationnode);

            ////foreach (var item in ExactApspshortestpath)
            ////{
            ////    Graph.Series["ExactAPSP"].Points.AddXY(item.Item1.X, item.Item1.Y);
            ////    Graph.Series["ExactAPSP"].Points.AddXY(item.Item2.X, item.Item2.Y);

            ////}
            //stopwatch.Stop();
            //var time = stopwatch.Elapsed;
            //int i = 0;

            ////Exact SSSP
            //Stopwatch stopwatches = new Stopwatch();
            //stopwatches.Start();

            //var SSSPExactshortestpath = sSSP.ExactSSSP(Sourcenode, Destinationnode);
            ////foreach (var item in SSSPExactshortestpath)
            ////{
            ////    Graph.Series["ExactSSSP"].Points.AddXY(item.Item1.X, item.Item1.Y);


            ////}
            //stopwatches.Stop();
            //var timees = stopwatches.Elapsed;


            ////Approximate SSSP
            //Stopwatch stopwatch = new Stopwatch();
            //stopwatch.Start();

            //var SSSPApproximateshortestpath = sSSP.ApproximateSSSP(Sourcenode, Destinationnode);
            //foreach (var item in SSSPApproximateshortestpath)
            //{
            //    Graph.Series["ApproximateSSSP"].Points.AddXY(item.Item1.X, item.Item1.Y);


            //}
            //stopwatch.Stop();
            //var time = stopwatch.Elapsed;
            //int i = 0;


            //////Approximate SSSP111
            ////Stopwatch stopwatch = new Stopwatch();
            ////stopwatch.Start();

            ////var SSSPApproximateshortestpath = sSSP.Approximate1SSSP(Sourcenode, Destinationnode);
            //////foreach (var item in SSSPApproximateshortestpath)
            //////{
            //////    Graph.Series["ApproximateSSSP"].Points.AddXY(item.Item1.X, item.Item1.Y);


            //////}
            ////stopwatch.Stop();
            ////var time = stopwatch.Elapsed;
            ////int i = 0;

            //Exact SSSP algorrithm from paper

            Stopwatch stopwatchesp = new Stopwatch();

            stopwatchesp.Start();

            var SSSPApproximateshortestpathesp = sSSP.ExactSSSPAlgorithm(Sourcenode, Destinationnode, Constructedskeltongraph);

            //foreach (var item in SSSPApproximateshortestpath)
            //{
            //    Graph.Series["ApproximateSSSP"].Points.AddXY(item.Item1.X, item.Item1.Y);


            //}
            stopwatchesp.Stop();
            var time = stopwatchesp.Elapsed;


            //Approximate SSSP algorrithm from paper

            Stopwatch stopwatchasp = new Stopwatch();

            stopwatchasp.Start();

            var SSSPApproximateshortestpathasp = sSSP.ApproxSSSPAlgorithm(Sourcenode, Destinationnode, Constructedskeltongraph);

            //foreach (var item in SSSPApproximateshortestpath)
            //{
            //    Graph.Series["ApproximateSSSP"].Points.AddXY(item.Item1.X, item.Item1.Y);


            //}
            stopwatchasp.Stop();
            var timeasp = stopwatchasp.Elapsed;
            int i       = 0;

            ////Approximate own algorithm new
            //Stopwatch stopwatch = new Stopwatch();
            //stopwatch.Start();

            //var SSSPApproximateshortestpath = sSSP.ApprpxAprroxSSPAlgorithm(Sourcenode, Destinationnode);
            ////foreach (var item in SSSPApproximateshortestpath)
            ////{
            ////    Graph.Series["ApproximateSSSP"].Points.AddXY(item.Item1.X, item.Item1.Y);


            ////}
            //stopwatch.Stop();
            //var time = stopwatch.Elapsed;
            //int i = 0;

            //Dijikitras algorithm new
            Stopwatch stopwatchdi = new Stopwatch();

            stopwatchdi.Start();

            var SSSPApproximateshortestpath = sSSP.DijikitrasAlgorithm(Sourcenode, Destinationnode, Constructedskeltongraph);

            //foreach (var item in SSSPApproximateshortestpath)
            //{
            //    Graph.Series["ApproximateSSSP"].Points.AddXY(item.Item1.X, item.Item1.Y);


            //}
            stopwatchdi.Stop();
            var timedi = stopwatchdi.Elapsed;


            //Cluster SSSP

            Stopwatch stopwatchc = new Stopwatch();

            stopwatchc.Start();
            var ExactApspshortestpathcl = sSSP.ApprpxAprroxClusterAlgorithm(Sourcenode, Destinationnode, Constructedskeltongraph);

            //foreach (var item in ExactApspshortestpath)
            //{
            //    Graph.Series["ExactAPSP"].Points.AddXY(item.Item1.X, item.Item1.Y);
            //    Graph.Series["ExactAPSP"].Points.AddXY(item.Item2.X, item.Item2.Y);

            //}
            stopwatchc.Stop();
            var timec = stopwatchc.Elapsed;


            //Recursive SSSP

            Stopwatch stopwatchr = new Stopwatch();

            stopwatchr.Start();
            var ExactApspshortestpath = sSSP.ApproximateRecursiveSSPAlgorithm(Sourcenode, Destinationnode, Constructedskeltongraph);

            //foreach (var item in ExactApspshortestpath)
            //{
            //    Graph.Series["ExactAPSP"].Points.AddXY(item.Item1.X, item.Item1.Y);
            //    Graph.Series["ExactAPSP"].Points.AddXY(item.Item2.X, item.Item2.Y);

            //}
            stopwatchr.Stop();
            var timer = stopwatchr.Elapsed;


            //Min Edge Cover SSSP

            Stopwatch stopwatchm = new Stopwatch();

            stopwatchm.Start();
            var ExactApspshortestpath1 = sSSP.ApprpxMinFLowSSPAlgorithm(Sourcenode, Destinationnode, Constructedskeltongraph);

            //foreach (var item in ExactApspshortestpath)
            //{
            //    Graph.Series["ExactAPSP"].Points.AddXY(item.Item1.X, item.Item1.Y);
            //    Graph.Series["ExactAPSP"].Points.AddXY(item.Item2.X, item.Item2.Y);

            //}
            stopwatchm.Stop();
            var timem = stopwatchm.Elapsed;


            // debugging Section

            //List<Tuple<int, int>> tokencopies = new List<Tuple<int, int>>();
            //List<Tuple<int, int>> tokencopieswithrespectivenodes = new List<Tuple<int, int>>();
            //tokencopies =tokenDistribution.TokenMultiplication();
            //tokencopieswithrespectivenodes = tokenDistribution.GetNumberofNodeswithTokenCopies(tokencopies);
        }
Exemplo n.º 8
0
        //Construct Exact Algorithm From Graph from skeleton

        private List <Token> ConstructAlgoSkeletonGraph()
        {
            TokenDistribution tokenDistribution = new TokenDistribution();
            Token             token;

            LocalEdge    localEdge   = new LocalEdge();
            GraphLayout  graphLayout = new GraphLayout();
            IList <Node> Vertices    = new List <Node>();
            List <Token> TokenwithDistanceMessage = new List <Token>();
            List <Tuple <Node, Node> > Edges      = new List <Tuple <Node, Node> >();

            List <int> veticesNumber = new List <int>();


            int MaxHopDistance = 20;

            Vertices = graphLayout.GetGraphLayout();
            Edges    = localEdge.GetGrapgEdges(Vertices);

            for (int i = 0; i < Vertices.Count; i++)
            {
                veticesNumber.Add(Vertices[i].ID);
            }

            for (int i = 0; i < Vertices.Count; i++)
            {
                List <Tuple <Node, Node, int, int, double> > dupliccatetokenmessage = new List <Tuple <Node, Node, int, int, double> >();
                token = tokenDistribution.LocalBroadcast(Edges, Vertices[i], Vertices);

                for (int j = 0; j < token.TokenMessage.Count; j++)
                {
                    //within 2 hop counts
                    if (token.TokenMessage[j].Item4 < 3)
                    {
                        dupliccatetokenmessage.Add(Tuple.Create(token.TokenMessage[j].Item1,
                                                                token.TokenMessage[j].Item2, token.TokenMessage[j].Item3, token.TokenMessage[j].Item4,
                                                                (double)token.TokenMessage[j].Item3));
                    }
                    else
                    {
                        dupliccatetokenmessage.Add(Tuple.Create(token.TokenMessage[j].Item1,
                                                                token.TokenMessage[j].Item2, token.TokenMessage[j].Item3, token.TokenMessage[j].Item4,
                                                                double.PositiveInfinity));
                    }
                }
                List <Tuple <Node, Node, int, int, double> > Uniquedupliccatetokenmessage = new List <Tuple <Node, Node, int, int, double> >();
                Tuple <Node, Node, int, int, double>         unique;
                if (dupliccatetokenmessage?.Count != 0)
                {
                    for (int k = 0; k < veticesNumber.Count; k++)
                    {
                        if (veticesNumber[k] != dupliccatetokenmessage[0].Item1.ID)
                        {
                            unique = GetUniqueVeticesToken(veticesNumber[k], dupliccatetokenmessage);
                            Uniquedupliccatetokenmessage.Add(unique);
                        }
                        else
                        {
                            Uniquedupliccatetokenmessage.Add(Tuple.Create(dupliccatetokenmessage[i].Item1,
                                                                          dupliccatetokenmessage[k].Item1, 0, 0, (double)0));
                        }
                    }
                }
                var   orderedDuplicatemessage = Uniquedupliccatetokenmessage.OrderBy(x => x.Item2.ID).ToList();
                Token duplicate = new Token(token.SourceID, orderedDuplicatemessage);
                TokenwithDistanceMessage.Add(duplicate);
            }
            return(TokenwithDistanceMessage);
        }