Exemplo n.º 1
0
        public List <Expert> Run(List <Project> projects, List <Expert> experts, int featureCount)
        {
            List <int> sumExperts = Expert.SumExperts(experts, featureCount);

            Printer.Print(sumExperts, "Sum of experts' features:");
            Expert.CalculateExpertsWeights(experts, sumExperts); //must be executed each time when sum changes
            Expert.SortExperts(experts, sumExperts);
            Printer.PrintVector(experts, "Experts after sorting:");
            return(Assignment(projects, experts, featureCount, sumExperts));
        }
Exemplo n.º 2
0
        private List <Expert> Assignment(List <Project> projects, List <Expert> experts, int featureCount, List <int> sumExperts)
        {
            int indProj     = 0;
            var oldSum      = new List <int>();
            int sumProjects = Project.SumProjects(projects);
            var usedExperts = new List <Expert>();

            int[] usedFeatures = new int[featureCount];
            int   oldProjects  = 0;
            var   projectSum   = Project.SumProjectsVector(projects, featureCount);

            while (AreExpertsAssignable(projectSum, sumExperts) && (experts.Count > 0 || sumProjects > 0))
            {
                SetUsedFeatures(projectSum, sumExperts, usedFeatures);
                oldProjects = sumProjects;
                int diff     = 0;
                int indSmall = GetSmallestIndex(sumExperts, usedFeatures);
                if (indSmall == -1)
                {
                    break;
                }
                if (projects[indProj]._projectVector[indSmall] > 0)
                {
                    if (projects[indProj]._projectVector[indSmall] < sumExperts[indSmall])
                    {
                        diff         = projects[indProj]._projectVector[indSmall];
                        sumProjects -= projects[indProj]._projectVector[indSmall];
                        projects[indProj]._projectVector[indSmall] = 0;
                        projectSum[indSmall] -= diff;
                    }
                    else
                    {
                        diff = sumExperts[indSmall];
                        projects[indProj]._projectVector[indSmall] -= sumExperts[indSmall];
                        sumProjects          -= sumExperts[indSmall];
                        projectSum[indSmall] -= diff;
                    }
                }
                Expert.RemoveExperts(experts, usedExperts, diff, projects[indProj], indSmall);
                Expert.RemoveExpertsFromSum(usedExperts, sumExperts, diff);
                if (indProj == projects.Count - 1)
                {
                    indProj = 0;
                }
                else
                {
                    indProj++;
                }
            }
            return(usedExperts);
        }
Exemplo n.º 3
0
        public void ProcessInput(List <Project> projects, List <Expert> experts, ref int featureCount, string filename)
        {
            string fullPath = Path.Combine(Environment.CurrentDirectory, _path, filename);

            using (StreamReader sr = new StreamReader(fullPath))
            {
                //getting data from first line
                string   currentLine  = sr.ReadLine();
                string[] values       = currentLine.Split(_separator);
                int      projectCount = Convert.ToInt32(values[0]);
                int      expertCount  = Convert.ToInt32(values[1]);
                featureCount = Convert.ToInt32(values[2]);
                //reading projects
                int ind  = 0;
                int temp = projectCount;
                while (temp != 0)
                {
                    currentLine = sr.ReadLine();
                    char     delimiter_p = _separator;
                    string[] values_p    = currentLine.Split(delimiter_p);

                    List <int> proj = new List <int>();
                    for (int i = 0; i < featureCount; i++)
                    {
                        proj.Insert(i, Convert.ToInt32(values_p[i]));
                    }
                    Project p = new Project(proj, ind);
                    projects.Insert(ind, p);
                    ind++;
                    temp--;
                }
                //reading experts
                ind  = 0;
                temp = expertCount;
                while (temp != 0)
                {
                    currentLine = sr.ReadLine();
                    char       delimiter_p = _separator;
                    string[]   values_p    = currentLine.Split(delimiter_p);
                    List <int> exp         = new List <int>();
                    for (int i = 0; i < featureCount; i++)
                    {
                        exp.Insert(i, Convert.ToInt32(values_p[i]));
                    }
                    Expert e = new Expert(exp, -1);
                    experts.Insert(ind, e);
                    ind++;
                    temp--;
                }
            }
        }
Exemplo n.º 4
0
        public static void CalculateExpertsWeights(List <Expert> le, List <int> sum)
        {
            //finding sumWeight vector (weights of each feature)
            List <int> sumTemp   = new List <int>(sum);
            List <int> sumWeight = new List <int>(sumTemp);
            int        features  = sumTemp.Count;
            int        temp      = 0;

            while (temp != features)
            {
                int max    = -1;
                int maxind = -1;
                for (int i = 0; i < features; i++)
                {
                    if (sumTemp.ElementAt(i) > max)
                    {
                        max    = sumTemp.ElementAt(i);
                        maxind = i;
                    }
                }
                sumTemp[maxind]   = -99;
                sumWeight[maxind] = temp + 1;
                temp++;
            }

            //assigning weights to experts
            for (int j = 0; j < le.Count; j++)
            {
                int weight = 0;
                for (int y = 0; y < sum.Count; y++)
                {
                    weight += le[j].expertVector[y] * sumWeight[y];
                }
                le[j] = new Expert(le[j].expertVector, weight);
            }
        }