public void CreateGraphInput(Constants.SimulationType simulationType) { ExcelManipulation excelGraph = new ExcelManipulation(); excelGraph.CreateExcelFile(); int grrow = 1; int grcol = 1; excelGraph.createHeaders(grrow, grcol, "Run No", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Simulation Type", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Total Budget", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Average Budget", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Average Reputation", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Min Reputation", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Max Reputation", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Growth Factor ws5", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Growth Factor ws10", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Growth Factor ws15", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Comp prob ws5", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Comp prob ws10", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Comp prob ws15", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Coop prob ws6", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Coop prob ws11", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Coop prob ws16", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Reward Chance ws5", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Reward Chance ws10", "A", "B", 2, true, 10, "n"); excelGraph.createHeaders(grrow, ++grcol, "Reward Chance ws15", "A", "B", 2, true, 10, "n"); for (int i = 0; i < avgBudget.Count; i++) { grrow++; grcol = 1; excelGraph.InsertData(grrow, grcol, i.ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, simulationType.ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, totalBudget[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, avgBudget[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, avgReputation[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, minReputation[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, maxReputation[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, growthFactor5[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, growthFactor10[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, growthFactor15[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, compProb5[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, compProb10[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, compProb15[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, coopProb6[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, coopProb11[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, coopProb16[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, rewardChance5[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, rewardChance10[i].ToString(), "", "", ""); excelGraph.InsertData(grrow, ++grcol, rewardChance15[i].ToString(), "", "", ""); } long ticks = DateTime.Now.Ticks; excelGraph.SaveDocument("coopetitionGraph_" + simulationType + "_" + ticks + ".xls"); }
private void InitializeUsingDataTables(Constants.SimulationType simulationType) { outputLog.AppendText("/*********************** Strategy: " + simulationType.ToString() + " ***********************/\n"); // Generate tasks TaskPool.Clear(); outputLog.AppendText("Generating Tasks...\n"); foreach (DataRow drTask in dtTaskInitialValues.Rows) { Task task = new Task(); task.Id = Int32.Parse(drTask[colTaskId].ToString()); task.QoS = double.Parse(drTask[colTaskQoS].ToString()); task.Fee = Int32.Parse(drTask[colTaskFee].ToString()); task.Assigned = Boolean.Parse(drTask[colTaskAssigned].ToString()); TaskPool.Add(task); } // Generate communities outputLog.AppendText("Generating Communities...\n"); Communities.RemoveAt(0); Community community = new Community(1); community.TaskPool = TaskPool; // Generate web services outputLog.AppendText("Generating " + Constants.NumberOfWebservices + " of Web Services...\n"); community.Members.Clear(); community.IntraNetworks.Clear(); foreach (DataRow drWs in dtWsInitialValues.Rows) { WebService ws = new WebService(); ws.Id = Int32.Parse(drWs[colWsId].ToString()); ws.QoS = double.Parse(drWs[colWsQoS].ToString()); ws.GrowthFactor = double.Parse(drWs[colWsGrowthFactor].ToString()); ws.Reputation = double.Parse(drWs[colWsReputation].ToString()); ws.Budget = Int32.Parse(drWs[colWsBudget].ToString()); switch (simulationType) { case Constants.SimulationType.AllCompetitive: ws.Type = Constants.WebserviceType.JustCompetitive; break; case Constants.SimulationType.AllRandom: ws.Type = Constants.WebserviceType.Random; break; case Constants.SimulationType.Coopetitive: ws.Type = Constants.WebserviceType.Coopetitive; break; } ws.CommunityId = Int32.Parse(drWs[colCmId].ToString()); ws.NetworkId = Int32.Parse(drWs[colWsNetwork].ToString()); community.AddMember(ws); } Communities.Add(community); // Collaboration Network Initialization outputLog.AppendText("Initializating Collaboration Network...\n"); InitializeNetworksUsingDataTable(); }
public void Run(Constants.SimulationType simulationType) { if (dtWsInitialValues.Rows.Count == 0) { Initialization(simulationType); } else { InitializeUsingDataTables(simulationType); } long start = DateTime.Now.Ticks; for (int i = 0; i < Constants.NumberOfRuns; i++) { outputLog.AppendText("Iteration #" + i + "...\n"); outputLog.ScrollToCaret(); excel.CreateExcelFile(); row = 1; col = 1; Simulation(i + 1); long ticks = DateTime.Now.Ticks; excel.SaveDocument("coopetition_" + i.ToString() + "_" + ticks + ".xls"); double totBudget = 0; double totRep = 0; double maxRep = 0; double minRep = 1; for (int j = 0; j < Communities[0].Members.Count; j++) { totBudget += Communities[0].Members[j].Webservice.Budget; totRep += Communities[0].Members[j].Webservice.Reputation; if (Communities[0].Members[j].Webservice.Reputation > maxRep) maxRep = Communities[0].Members[j].Webservice.Reputation; if (Communities[0].Members[j].Webservice.Reputation < minRep) minRep = Communities[0].Members[j].Webservice.Reputation; } avgBudget.Add((double)totBudget / Communities[0].Members.Count); totalBudget.Add(totBudget); avgReputation.Add((double)totRep / Communities[0].Members.Count); minReputation.Add(minRep); maxReputation.Add(maxRep); growthFactor5.Add(Communities[0].Members[5].Webservice.GrowthFactor); growthFactor10.Add(Communities[0].Members[10].Webservice.GrowthFactor); growthFactor15.Add(Communities[0].Members[15].Webservice.GrowthFactor); compProb5.Add(Communities[0].Members[5].Webservice.CompetedProbability); compProb10.Add(Communities[0].Members[10].Webservice.CompetedProbability); compProb15.Add(Communities[0].Members[15].Webservice.CompetedProbability); coopProb6.Add(1 - Communities[0].Members[6].Webservice.CompetedProbability); coopProb11.Add(1 - Communities[0].Members[11].Webservice.CompetedProbability); coopProb16.Add(1 - Communities[0].Members[16].Webservice.CompetedProbability); rewardChance5.Add((double)Communities[0].Members[5].Webservice.NumberOfRewarded / (i+1)); rewardChance10.Add((double)Communities[0].Members[10].Webservice.NumberOfRewarded / (i + 1)); rewardChance15.Add((double)Communities[0].Members[15].Webservice.NumberOfRewarded / (i + 1)); ReleaseTasks(); } long end = DateTime.Now.Ticks; outputLog.AppendText("Simulation took: " + (int)((end-start)/10000) + " ms\n"); outputLog.AppendText("Done!\n"); outputLog.ScrollToCaret(); CreateGraphInput(simulationType); avgBudget.Clear(); totalBudget.Clear(); avgReputation.Clear(); maxReputation.Clear(); minReputation.Clear(); MessageBox.Show("Done!"); }
private void InitializeNetworks(Constants.SimulationType simulationType) { Random rnd = new Random(DateTime.Now.Millisecond); foreach (Community community in Communities) { if ((simulationType == Constants.SimulationType.Coopetitive || simulationType == Constants.SimulationType.AllRandom)) { int NetworkSize = (community.Members.Count - 3) / Constants.NumberOfNetworksInCommunity; Environment.outputLog.AppendText("NetworkSize: " + NetworkSize + "\n"); Environment.outputLog.AppendText("Member Count: " + community.Members.Count + "\n"); for (int i = 0; i < Constants.NumberOfNetworksInCommunity; i++) { CollaborationNetwork network = new CollaborationNetwork(i, community.Id); for (int j = 0; j < NetworkSize; j++) { int wsId = rnd.Next(0, community.Members.Count); while (community.Members[wsId].Webservice.NetworkId != -1) { Thread.Sleep(10); wsId = rnd.Next(0, community.Members.Count); } network.MembersIds.Add(wsId); WebService ws = community.Members.Find(delegate(Community.WebServiceInfo wsInfo) { return wsInfo.Webservice.Id == wsId; }).Webservice; ws.NetworkId = network.Id; dtWsInitialValues.Rows[ws.Id][colWsNetwork] = ws.NetworkId; } community.IntraNetworks.Add(network); } } else { foreach (Community.WebServiceInfo wsInfo in community.Members) { // For all competitve members, there is no need to have intra networks wsInfo.Webservice.NetworkId = -1; } } } }
public void Initialization(Constants.SimulationType simulationType) { CreateInitializationTables(); DataSetTools dsTools = new DataSetTools(); dataSet = dsTools.parseDateSet("c:\\projects\\QWS_Dataset_v2.txt"); outputLog.AppendText("/*********************** Strategy: " + simulationType.ToString() + " ***********************/\n"); // Generate tasks outputLog.AppendText("Generating Tasks...\n"); for (int i = 0; i < Constants.NumberOfTasks; i++) { Task task = new Task(i); TaskPool.Add(task); FillTaskTable(i, task); } // Generate communities outputLog.AppendText("Generating Communities...\n"); Community community = new Community(1); community.TaskPool = TaskPool; // Generate web services outputLog.AppendText("Generating " + Constants.NumberOfWebservices + " of Web Services...\n"); for (int i = 0; i < Constants.NumberOfWebservices; i++) { WebService ws = new WebService(i); switch (simulationType) { case Constants.SimulationType.AllCompetitive: ws.Type = Constants.WebserviceType.JustCompetitive; break; case Constants.SimulationType.AllRandom: ws.Type = Constants.WebserviceType.Random; break; case Constants.SimulationType.Coopetitive: ws.Type = Constants.WebserviceType.Coopetitive; break; } community.AddMember(ws); ws.CommunityId = community.Id; FillWsTable(i, ws); } Communities.Add(community); // Collaboration Network Initialization outputLog.AppendText("Initializating Collaboration Network...\n"); InitializeNetworks(simulationType); // Computing thresholds and probabilities }