//using global edge public void DistributeTokenusingGlobalEdge() { GraphLayout graphLayout = new GraphLayout(); LocalEdge LocalEdge = new LocalEdge(); IList <Node> Vertices = new List <Node>(); string message = "WERTYUHG"; // message lenght to debug .. it should rewal message strings lenght.. token length Vertices = graphLayout.GetGraphLayout(); GlobalEdge globalEdge = new GlobalEdge(); List <Tuple <Node, Node, int> > globaledegeswithdistanc = new List <Tuple <Node, Node, int> >(); globaledegeswithdistanc = globalEdge.SendGlobalEdge(Vertices[0], Vertices, message); //Logger logger = new Logger(); //foreach (var item in globaledegeswithdistanc) //{ // logger.LogWrite(item.Item1.ID.ToString(), // item.Item2.ID.ToString(), item.Item3.ToString(), item.Item2.ID.ToString()); //} }
/*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); }
private List<Tuple<Node>> GetDijikitras(Node sourceNode, Node destinationNode) { GraphLayout graphLayout = new GraphLayout(); LocalEdge LocalEdge = new LocalEdge(); IList<Node> Vertices = new List<Node>(); List<Tuple<Node, Node>> Edges = new List<Tuple<Node, Node>>(); List<Tuple<Node, Node,int>> EdgeswithDistance = new List<Tuple<Node, Node,int>>(); List<Tuple<Node>> shortestpath = new List<Tuple<Node>>(); Vertices = graphLayout.GetGraphLayout(); Edges = LocalEdge.GetGrapgEdges(Vertices); EdgeswithDistance = GetEdgesWithDistance(Edges); shortestpath = GetShortestPath(sourceNode, destinationNode, EdgeswithDistance); return shortestpath; }
public List <Tuple <Node, Token> > DitributeToken(List <Tuple <Node, Node> > Edges) { GraphLayout graphLayout = new GraphLayout(); LocalEdge LocalEdge = new LocalEdge(); IList <Node> Vertices = new List <Node>(); Vertices = graphLayout.GetGraphLayout(); Edges = LocalEdge.GetGrapgEdges(Vertices); List <Tuple <Node, Token> > VertexWithToken = new List <Tuple <Node, Token> >(); int IDcount = 1; int tokenId = 0; int distance; while (IDcount < Vertices.Count + 1) { for (int i = 0; i < Edges.Count; i++) { if (Edges?.Count != 0 && Edges[i].Item1.ID == IDcount) { tokenId++; Edges[i].Item1.IsToken = true; distance = GetDistance(Edges[i].Item1, Edges[i].Item2); VertexWithToken.Add(Tuple.Create(Edges[i].Item2, new Token(Edges[i].Item1.ID, Edges[i].Item2.ID, distance, tokenId))); } } IDcount++; } List <Tuple <Node, Token> > orderedVertexWithToken = new List <Tuple <Node, Token> >(); orderedVertexWithToken = VertexWithToken.OrderBy(x => x.Item1.ID).ToList(); //Logger logger = new Logger(); //foreach (var item in orderedVertexWithToken) //{ // logger.LogWrite(item.Item2.SourceID.ToString(), // item.Item2.DestinationID.ToString(),item.Item2.Distance.ToString(),item.Item1.ID.ToString()); //} return(VertexWithToken); }
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); }
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); }
//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); }