Beispiel #1
0
        private void Collaborate(Task task, CollaborationNetwork network, Community cm)
        {
            List<Community.WebServiceInfo> webserviceInfos = cm.Members;
            Random rnd = new Random(DateTime.Now.Millisecond);
            Thread.Sleep(5);
            double rndPortion = Math.Round(rnd.NextDouble(), 4);
            this.hasCollaborated = true;
            this.taskPortionDone = rndPortion; // main web service task portion
            cm.Members[this.id].NumberOfTasksDone++;
            Thread.Sleep(5);
            double rndQoS = generateProvidedQoSCollabrative();
            System.Console.Write(this.QoS + ":" + rndQoS);
            this.providedQoS = rndQoS;
            this.budget += (int)((1 - Constants.CooperationFeePercentage) * task.Fee);
            this.totalIncome += (int)((1 - Constants.CooperationFeePercentage) * task.Fee);
            task.PerformedQoS = rndQoS;
            double networkPortion = 1 - rndPortion;
            //int numberOfCollaborators = rnd.Next(1, network.MembersIds.Count);

            //double networkMembersPortion = Math.Round((double)networkPortion / numberOfCollaborators, 2);

            double networkQoS = 0;

            List<WebService> collaborationNetwork = new List<WebService>();
            List<WebService> networkMembers = new List<WebService>();
            for (int i = 0; i < network.MembersIds.Count; i++)
            {
                networkMembers.Add(webserviceInfos.Find(delegate(Community.WebServiceInfo wsInfo) { return wsInfo.Webservice.Id == network.MembersIds[i]; }).Webservice);
            }
            networkMembers.RemoveAll(delegate(WebService ws) { return (ws.Id == this.id) || (ws.readyToCompete == true); });
            List<WebService> tempNetwork = networkMembers;
            int numberOfCollaborators = rnd.Next(1, networkMembers.Count);
            double networkMembersPortion = Math.Round((double)networkPortion / numberOfCollaborators, 2);
            while (numberOfCollaborators > 0)
            {
                int j = rnd.Next(0, tempNetwork.Count);
                numberOfCollaborators--;
                ((WebService)tempNetwork[j]).isCollaborated = true;
                collaborationNetwork.Add((WebService)tempNetwork[j]);
                tempNetwork.RemoveAt(j);
            }

            String collaborativeMemberIds = "";
            collaborationNetwork.ForEach(delegate(WebService ws)
                                {
                                    ws.taskPortionDone = networkMembersPortion;
                                    Thread.Sleep(5);
                                    ws.providedQoS = Math.Max(0, ws.qos - (Math.Round(rnd.NextDouble(), 4) / Constants.QoSVarianceModifier));
                                    cm.Members[ws.id].NumberOfTasksDone++;
                                    ws.budget += (int)((Constants.CooperationFeePercentage / collaborationNetwork.Count) * task.Fee);
                                    ws.totalIncome += (int)((Constants.CooperationFeePercentage / collaborationNetwork.Count) * task.Fee);
                                    networkQoS += ws.providedQoS;
                                    collaborativeMemberIds += ws.id + ", ";
                                });
            char[] charsToRemove = ", ".ToCharArray();
            collaborativeMemberIds = collaborativeMemberIds.TrimEnd(charsToRemove);
            Environment.outputLog.AppendText("Web service " + this.id + " Cooperates with " + collaborativeMemberIds + "\n");
            this.providedQoS = (Constants.ResponsibleWSQoSPortion * this.providedQoS) + ((1 - Constants.ResponsibleWSQoSPortion) * networkQoS); // main web service provided QoS (provided QoS for the task)
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        public void StartDoingTask(Task task, Community community)
        {
            if (task != null)
            {
                double resultQoS;
                Random rnd = new Random(DateTime.Now.Millisecond);

                if ((this.type == Constants.WebserviceType.Coopetitive) || (this.type == Constants.WebserviceType.Random))
                {
                    double rndDecision = rnd.NextDouble();
                    if ((rndDecision > Constants.DoingAloneProbability) && (rndDecision <= Constants.CollaborateProbability))
                    {
                        CollaborationNetwork net = community.IntraNetworks.Find(delegate(CollaborationNetwork nw) { return nw.Id == this.networkId; });
                        if (net != null)
                        {
                            int cooperativeMembersInNetwork = net.MembersIds.FindAll(delegate(int wsId) { return community.Members[wsId].Webservice.readyToCompete == false; }).Count;
                            if (cooperativeMembersInNetwork > 1)
                            {
                                Collaborate(task, net, community);
                            }
                            else
                            {
                                this.taskPortionDone = 1;
                                Thread.Sleep(5);
                                double rndQoS = generateProvidedQoS();

                                this.providedQoS = rndQoS;
                                this.hasCollaborated = false;
                                resultQoS = this.providedQoS;
                                task.PerformedQoS = rndQoS;

                                community.Members[this.id].NumberOfTasksDone++;

                                if (task.QoS < this.providedQoS + 0.05)
                                {
                                    this.budget += task.Fee; // Should be changed based on the provided QoS
                                    this.totalIncome += task.Fee;
                                }
                            }
                        }
                        else
                        {
                            this.taskPortionDone = 1;
                            Thread.Sleep(5);
                            double rndQoS = generateProvidedQoS();

                            this.providedQoS = rndQoS;
                            this.hasCollaborated = false;
                            resultQoS = this.providedQoS;
                            task.PerformedQoS = rndQoS;

                            community.Members[this.id].NumberOfTasksDone++;

                            if (task.QoS < this.providedQoS + 0.05)
                            {
                                this.budget += task.Fee; // Should be changed based on the provided QoS
                                this.totalIncome += task.Fee;
                            }
                        }
                    }
                    else
                    {
                        this.taskPortionDone = 1;
                        Thread.Sleep(5);
                        double rndQoS = generateProvidedQoS();

                        this.providedQoS = rndQoS;
                        this.hasCollaborated = false;
                        resultQoS = this.providedQoS;
                        task.PerformedQoS = rndQoS;

                        community.Members[this.id].NumberOfTasksDone++;

                        if (task.QoS < this.providedQoS + 0.05)
                        {
                            this.budget += task.Fee; // Should be changed based on the provided QoS
                            this.totalIncome += task.Fee;
                        }
                    }
                }
                else if (this.type == Constants.WebserviceType.JustCompetitive)
                {
                    this.taskPortionDone = 1;
                    Thread.Sleep(5);
                    double rndQoS = generateProvidedQoS();

                    this.providedQoS = rndQoS;
                    this.hasCollaborated = false;
                    resultQoS = this.providedQoS;
                    task.PerformedQoS = rndQoS;

                    community.Members[this.id].NumberOfTasksDone++;
                    if (task.QoS < this.providedQoS + 0.05)
                    {
                        this.budget += task.Fee; // Should be changed based on the provided QoS
                        this.totalIncome += task.Fee;
                    }
                }
            }

            if (this.Type == Constants.WebserviceType.Random) {
                Random rnd = new Random();
                //if (rnd.NextDouble() > 0.9)
                //    this.budget++;
            }
            if (this.Type == Constants.WebserviceType.Coopetitive)
            {
                Random rnd = new Random();
                if (rnd.NextDouble() > 0.9)
                    this.budget++;
            }
            if (this.Type == Constants.WebserviceType.JustCompetitive)
            {
                Random rnd = new Random();
                if (rnd.NextDouble() > 0.5)
                    this.budget--;
            }
            /*
            if (this.Type == Constants.WebserviceType.Coopetitive)
            {
                Random rnd = new Random();
                if (rnd.NextDouble() > 0.98)
                    this.budget -= 18;
                if (rnd.NextDouble() > 0.80)
                    this.budget -= 1;
            }
             */
        }
Beispiel #4
0
        private void Collaborate(Task task, CollaborationNetwork network, Community cm)
        {
            List <Community.WebServiceInfo> webserviceInfos = cm.Members;
            Random rnd = new Random(DateTime.Now.Millisecond);

            Thread.Sleep(5);
            double rndPortion = Math.Round(rnd.NextDouble(), 4);

            this.hasCollaborated = true;
            this.taskPortionDone = rndPortion; // main web service task portion
            cm.Members[this.id].NumberOfTasksDone++;
            Thread.Sleep(5);
            double rndQoS = Math.Max(0, this.qos - (Math.Round(rnd.NextDouble(), 4) / Constants.QoSVarianceModifier));

            this.providedQoS  = rndQoS;
            this.budget      += (int)((1 - Constants.CooperationFeePercentage) * task.Fee);
            this.totalIncome += (int)((1 - Constants.CooperationFeePercentage) * task.Fee);
            double networkPortion = 1 - rndPortion;
            //int numberOfCollaborators = rnd.Next(1, network.MembersIds.Count);

            //double networkMembersPortion = Math.Round((double)networkPortion / numberOfCollaborators, 2);
            double networkQoS = 0;

            List <WebService> collaborationNetwork = new List <WebService>();
            List <WebService> networkMembers       = new List <WebService>();

            for (int i = 0; i < network.MembersIds.Count; i++)
            {
                networkMembers.Add(webserviceInfos.Find(delegate(Community.WebServiceInfo wsInfo) { return(wsInfo.Webservice.Id == network.MembersIds[i]); }).Webservice);
            }
            networkMembers.RemoveAll(delegate(WebService ws) { return((ws.Id == this.id) || (ws.readyToCompete == true)); });
            List <WebService> tempNetwork = networkMembers;
            int    numberOfCollaborators  = rnd.Next(1, networkMembers.Count);
            double networkMembersPortion  = Math.Round((double)networkPortion / numberOfCollaborators, 2);

            while (numberOfCollaborators > 0)
            {
                int j = rnd.Next(0, tempNetwork.Count);
                numberOfCollaborators--;
                ((WebService)tempNetwork[j]).isCollaborated = true;
                collaborationNetwork.Add((WebService)tempNetwork[j]);
                tempNetwork.RemoveAt(j);
            }

            String collaborativeMemberIds = "";

            collaborationNetwork.ForEach(delegate(WebService ws)
            {
                ws.taskPortionDone = networkMembersPortion;
                Thread.Sleep(5);
                ws.providedQoS = Math.Max(0, ws.qos - (Math.Round(rnd.NextDouble(), 4) / Constants.QoSVarianceModifier));
                cm.Members[ws.id].NumberOfTasksDone++;
                ws.budget              += (int)((Constants.CooperationFeePercentage / collaborationNetwork.Count) * task.Fee);
                ws.totalIncome         += (int)((Constants.CooperationFeePercentage / collaborationNetwork.Count) * task.Fee);
                networkQoS             += ws.providedQoS;
                collaborativeMemberIds += ws.id + ", ";
            });
            char[] charsToRemove = ", ".ToCharArray();
            collaborativeMemberIds = collaborativeMemberIds.TrimEnd(charsToRemove);
            Environment.outputLog.AppendText("Web service " + this.id + " Cooperates with " + collaborativeMemberIds + "\n");
            this.providedQoS = (Constants.ResponsibleWSQoSPortion * this.providedQoS) + ((1 - Constants.ResponsibleWSQoSPortion) * networkQoS); // main web service provided QoS (provided QoS for the task)
        }
Beispiel #5
0
        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
        }
Beispiel #6
0
        public void StartDoingTask(Task task, Community community)
        {
            if (task != null)
            {
                double resultQoS;
                Random rnd = new Random(DateTime.Now.Millisecond);

                if ((this.type == Constants.WebserviceType.Coopetitive) || (this.type == Constants.WebserviceType.Random))
                {
                    double rndDecision = rnd.NextDouble();
                    if ((rndDecision > Constants.DoingAloneProbability) && (rndDecision <= Constants.CollaborateProbability))
                    {
                        CollaborationNetwork net = community.IntraNetworks.Find(delegate(CollaborationNetwork nw) { return(nw.Id == this.networkId); });
                        if (net != null)
                        {
                            int cooperativeMembersInNetwork = net.MembersIds.FindAll(delegate(int wsId) { return(community.Members[wsId].Webservice.readyToCompete == false); }).Count;
                            if (cooperativeMembersInNetwork > 1)
                            {
                                Collaborate(task, net, community);
                            }
                            else
                            {
                                this.taskPortionDone = 1;
                                Thread.Sleep(5);
                                double rndQoS = Math.Max(0, this.qos - (Math.Round(rnd.NextDouble(), 4) / Constants.QoSVarianceModifier));

                                this.providedQoS     = rndQoS;
                                this.hasCollaborated = false;
                                resultQoS            = this.providedQoS;

                                community.Members[this.id].NumberOfTasksDone++;
                                this.budget      += task.Fee; // Should be changed based on the provided QoS
                                this.totalIncome += task.Fee;
                            }
                        }
                        else
                        {
                            this.taskPortionDone = 1;
                            Thread.Sleep(5);
                            double rndQoS = Math.Max(0, this.qos - (Math.Round(rnd.NextDouble(), 4) / Constants.QoSVarianceModifier));

                            this.providedQoS     = rndQoS;
                            this.hasCollaborated = false;
                            resultQoS            = this.providedQoS;

                            community.Members[this.id].NumberOfTasksDone++;
                            this.budget      += task.Fee; // Should be changed based on the provided QoS
                            this.totalIncome += task.Fee;
                        }
                    }
                    else
                    {
                        this.taskPortionDone = 1;
                        Thread.Sleep(5);
                        double rndQoS = Math.Max(0, this.qos - (Math.Round(rnd.NextDouble(), 4) / Constants.QoSVarianceModifier));

                        this.providedQoS     = rndQoS;
                        this.hasCollaborated = false;
                        resultQoS            = this.providedQoS;

                        community.Members[this.id].NumberOfTasksDone++;
                        this.budget      += task.Fee; // Should be changed based on the provided QoS
                        this.totalIncome += task.Fee;
                    }
                }
                else if (this.type == Constants.WebserviceType.JustCompetitive)
                {
                    this.taskPortionDone = 1;
                    Thread.Sleep(5);
                    double rndQoS = Math.Max(0, this.qos - (Math.Round(rnd.NextDouble(), 4) / Constants.QoSVarianceModifier));

                    this.providedQoS     = rndQoS;
                    this.hasCollaborated = false;
                    resultQoS            = this.providedQoS;

                    community.Members[this.id].NumberOfTasksDone++;
                    this.budget      += task.Fee; // Should be changed based on the provided QoS
                    this.totalIncome += task.Fee;
                }
            }
        }
Beispiel #7
0
        public void Simulation(int numberOfRun)
        {
            excel.createHeaders(row, col, "cmId", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsId", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsNetwork", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsQoS", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsType", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsGrowthFactor", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsReputation", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsNTD", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsBudget", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsTotalIncome", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsCompeted", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsHasCollaborated", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsIsCollaborated", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsTaskQoS", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsTaskFee", "A", "B", 2, true, 10, "n");
            excel.createHeaders(row, ++col, "wsProvidedQoS", "A", "B", 2, true, 10, "n");

            for (int j = 0; j < Communities.Count; j++)
            {
                Community cm = Communities[j];
                col = 1;
                int currentrow = row;
                int currentcol = col;

                for (int i = 0; i < cm.Members.Count; i++)
                {
                    Community.WebServiceInfo wsInfo = cm.Members[i];

                    wsInfo.Webservice.Budget -= Constants.MembershipFee;
                    if (wsInfo.Webservice.Budget < 0)
                    {
                        wsInfo.Webservice.Budget = 0;
                    }

                    // Checking growth factor by web services
                    wsInfo.Webservice.CoopetitionDecision(wsInfo.NumberOfTasksDone, numberOfRun);
                    // Insert CommunityId to the excel file
                    excel.InsertData(row + 1, col, cm.Id.ToString(), "", "", "");
                    // Insert Webservice data to the excel file
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.Id.ToString(), "", "", "");
                    String strNetworkMembers = "";
                    if (wsInfo.Webservice.NetworkId != -1)
                    {
                        CollaborationNetwork net = cm.IntraNetworks.Find(delegate(CollaborationNetwork nw) { return(nw.Id == wsInfo.Webservice.NetworkId); });
                        foreach (int memberid in net.MembersIds)
                        {
                            strNetworkMembers += memberid + ", ";
                        }
                    }
                    char[] charsToRemove = ", ".ToCharArray();
                    strNetworkMembers = strNetworkMembers.TrimEnd(charsToRemove);
                    excel.InsertData(row + 1, ++col, strNetworkMembers, "", "", "");
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.QoS.ToString(), "", "", "");
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.Type.ToString(), "", "", "");
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.GrowthFactor.ToString(), "", "", "");
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.Reputation.ToString(), "", "", "");
                    row++;
                    currentcol = col;
                    col        = 1;
                }

                // Task allocation to competitive web services
                cm.OfferTaskToWebservice();

                row = currentrow;
                col = currentcol;
                for (int i = 0; i < cm.Members.Count; i++)
                {
                    Community.WebServiceInfo wsInfo = cm.Members[i];
                    // Doing the tasks by web services
                    wsInfo.Webservice.StartDoingTask(wsInfo.CurrentAssignedTask, cm);
                    // Insert Webservice data to the excel file
                    excel.InsertData(row + 1, ++col, wsInfo.NumberOfTasksDone.ToString(), "", "", "");
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.Budget.ToString(), "", "", "");
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.TotalIncome.ToString(), "", "", "");
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.ReadyToCompete.ToString(), "", "", "");
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.HasCollaborated.ToString(), "", "", "");
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.IsCollaborated.ToString(), "", "", "");
                    if (wsInfo.CurrentAssignedTask != null)
                    {
                        excel.InsertData(row + 1, ++col, wsInfo.CurrentAssignedTask.QoS.ToString(), "", "", "");
                        excel.InsertData(row + 1, ++col, wsInfo.CurrentAssignedTask.Fee.ToString(), "", "", "");
                    }
                    else
                    {
                        excel.InsertData(row + 1, ++col, "", "", "", "");
                        excel.InsertData(row + 1, ++col, "", "", "", "");
                    }
                    excel.InsertData(row + 1, ++col, wsInfo.Webservice.ProvidedQoS.ToString(), "", "", "");
                    row++;
                    col = currentcol;
                }

                // Service evaluation and reputation update by Master web service
                cm.UpdateMemberReputation();
            }
        }
Beispiel #8
0
        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();
        }
Beispiel #9
0
        public void Initialization(Constants.SimulationType simulationType)
        {
            CreateInitializationTables(); // Adding coloumns titles to drWsInitialValues

            DataSetTools dsTools = new DataSetTools();

            dataSet = dsTools.parseDateSet("c:\\projects\\QWS_Dataset_v2.txt"); // Gather all dataset webservice metrics and QoS

            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); // adds a row of task[i] to dtTaskInitialValues
                Thread.Sleep(5);
                //outputLog.AppendText("Task: " + task.QoS + ", fee: " + task.Fee + "\n");
            }

            // 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); // adds ws to dtWsInitialValues
            }

            Communities.Add(community);

            // Collaboration Network Initialization
            outputLog.AppendText("Initializating Collaboration Network...\n");
            InitializeNetworks(simulationType);

            // Computing thresholds and probabilities
        }
Beispiel #10
0
        public void StartDoingTask(Task task, Community community)
        {
            if (task != null)
            {
                double resultQoS;
                Random rnd = new Random(DateTime.Now.Millisecond);

                if ((this.type == Constants.WebserviceType.Coopetitive) || (this.type == Constants.WebserviceType.Random))
                {
                    double rndDecision = rnd.NextDouble();
                    if ((rndDecision > Constants.DoingAloneProbability) && (rndDecision <= Constants.CollaborateProbability))
                    {
                        CollaborationNetwork net = community.IntraNetworks.Find(delegate(CollaborationNetwork nw) { return(nw.Id == this.networkId); });
                        if (net != null)
                        {
                            int cooperativeMembersInNetwork = net.MembersIds.FindAll(delegate(int wsId) { return(community.Members[wsId].Webservice.readyToCompete == false); }).Count;
                            if (cooperativeMembersInNetwork > 1)
                            {
                                Collaborate(task, net, community);
                            }
                            else
                            {
                                this.taskPortionDone = 1;
                                Thread.Sleep(5);
                                double rndQoS = generateProvidedQoS();

                                this.providedQoS     = rndQoS;
                                this.hasCollaborated = false;
                                resultQoS            = this.providedQoS;
                                task.PerformedQoS    = rndQoS;

                                community.Members[this.id].NumberOfTasksDone++;

                                if (task.QoS < this.providedQoS + 0.05)
                                {
                                    this.budget      += task.Fee; // Should be changed based on the provided QoS
                                    this.totalIncome += task.Fee;
                                }
                            }
                        }
                        else
                        {
                            this.taskPortionDone = 1;
                            Thread.Sleep(5);
                            double rndQoS = generateProvidedQoS();

                            this.providedQoS     = rndQoS;
                            this.hasCollaborated = false;
                            resultQoS            = this.providedQoS;
                            task.PerformedQoS    = rndQoS;

                            community.Members[this.id].NumberOfTasksDone++;

                            if (task.QoS < this.providedQoS + 0.05)
                            {
                                this.budget      += task.Fee; // Should be changed based on the provided QoS
                                this.totalIncome += task.Fee;
                            }
                        }
                    }
                    else
                    {
                        this.taskPortionDone = 1;
                        Thread.Sleep(5);
                        double rndQoS = generateProvidedQoS();

                        this.providedQoS     = rndQoS;
                        this.hasCollaborated = false;
                        resultQoS            = this.providedQoS;
                        task.PerformedQoS    = rndQoS;

                        community.Members[this.id].NumberOfTasksDone++;

                        if (task.QoS < this.providedQoS + 0.05)
                        {
                            this.budget      += task.Fee; // Should be changed based on the provided QoS
                            this.totalIncome += task.Fee;
                        }
                    }
                }
                else if (this.type == Constants.WebserviceType.JustCompetitive)
                {
                    this.taskPortionDone = 1;
                    Thread.Sleep(5);
                    double rndQoS = generateProvidedQoS();

                    this.providedQoS     = rndQoS;
                    this.hasCollaborated = false;
                    resultQoS            = this.providedQoS;
                    task.PerformedQoS    = rndQoS;

                    community.Members[this.id].NumberOfTasksDone++;
                    if (task.QoS < this.providedQoS + 0.05)
                    {
                        this.budget      += task.Fee; // Should be changed based on the provided QoS
                        this.totalIncome += task.Fee;
                    }
                }
            }

            if (this.Type == Constants.WebserviceType.Random)
            {
                Random rnd = new Random();
                //if (rnd.NextDouble() > 0.9)
                //    this.budget++;
            }
            if (this.Type == Constants.WebserviceType.Coopetitive)
            {
                Random rnd = new Random();
                if (rnd.NextDouble() > 0.9)
                {
                    this.budget++;
                }
            }
            if (this.Type == Constants.WebserviceType.JustCompetitive)
            {
                Random rnd = new Random();
                if (rnd.NextDouble() > 0.5)
                {
                    this.budget--;
                }
            }

            /*
             * if (this.Type == Constants.WebserviceType.Coopetitive)
             * {
             *  Random rnd = new Random();
             *  if (rnd.NextDouble() > 0.98)
             *      this.budget -= 18;
             *  if (rnd.NextDouble() > 0.80)
             *      this.budget -= 1;
             * }
             */
        }