Beispiel #1
0
        public ExpertProjectInformation ReadFile()
        {
            ExpertProjectInformation result = new ExpertProjectInformation();

            using (var filestream = new FileStream(_readFileName,
                                                   FileMode.Open,
                                                   FileAccess.Read,
                                                   FileShare.ReadWrite))
            {
                using (var file = new StreamReader(filestream, System.Text.Encoding.UTF8, true, 128))
                {
                    string lineOfText;

                    int projectCount = -1, skillCount = -1, expertCount = -1, counter = 0;

                    while ((lineOfText = file.ReadLine()) != null)
                    {
                        //pierwsza linijka mowi nam ile jest rodzajow projektow, skillsow i ekspertow
                        if (counter == 0)
                        {
                            var tmp = lineOfText.Split(',').Select(x => int.Parse(x)).ToList();
                            result.ProjectCount = projectCount = tmp[0];
                            result.SkillCount   = skillCount = tmp[1];
                            result.ExpertCount  = expertCount = tmp[2];
                        }
                        else if (counter < projectCount + 1)
                        {
                            var projectRequierements = StringToList(lineOfText);
                            if (projectRequierements.Count != skillCount)
                            {
                                throw new Exception("projekt ma za malo skillsow podanych");
                            }
                            result.ProjectRequirements.Add(projectRequierements);
                        }
                        else
                        {
                            var expertSkills = StringToList(lineOfText);
                            if (expertSkills.Count != skillCount)
                            {
                                throw new Exception("projekt ma za malo skillsow podanych");
                            }
                            result.ExpertSkills.Add(expertSkills);
                        }
                        counter++;
                    }
                }
            }

            if (result.ExpertCount != result.ExpertSkills.Count || result.ProjectCount != result.ProjectRequirements.Count)
            {
                throw new Exception("nie zgada sie liczba linijek");
            }

            return(result);
        }
        public static Graph ExpertProjectInformationToGraph(ExpertProjectInformation expertProjectInformation)
        {
            var g = new AdjacencyMatrixGraph(true, expertProjectInformation.GetVerticesCount());

            //indeksowanie wierzcholkow
            //0 wejscie
            //expertProjectInformation.GetVerticesCount() - 1 ujscie
            //od 1 do ProjectCount wierzcholki projektow
            //od ProjectCount + 1 do ProjectCount + SkillCount wierzcholki skillsow
            //od ProjectCount + SkillCount + 1 do ProjectCount + SkillCount + ExpertCount wierzcholki eksperow

            for (int i = 0; i < expertProjectInformation.ProjectCount; i++)
            {
                g.AddEdge(0, i + 1, expertProjectInformation.ProjectRequirements[i].Sum());      //waga to suma wszystkich skillow potrzebnych w projekcie
            }

            for (int i = 0; i < expertProjectInformation.ProjectCount; i++)
            {
                for (int j = 0; j < expertProjectInformation.SkillCount; j++)
                {
                    if (expertProjectInformation.ProjectRequirements[i][j] != 0)
                    {
                        g.AddEdge(i + 1, expertProjectInformation.ProjectCount + 1 + j, expertProjectInformation.ProjectRequirements[i][j]);
                    }
                }
            }

            for (int i = 0; i < expertProjectInformation.ExpertCount; i++)
            {
                for (int j = 0; j < expertProjectInformation.SkillCount; j++)
                {
                    if (expertProjectInformation.ExpertSkills[i][j] != 0)
                    {
                        g.AddEdge(expertProjectInformation.ProjectCount + 1 + j,
                                  expertProjectInformation.ProjectCount + expertProjectInformation.SkillCount + 1 + i, expertProjectInformation.ExpertSkills[i][j]);
                    }
                }
            }

            for (int i = 0; i < expertProjectInformation.ExpertCount; i++)
            {
                g.AddEdge(expertProjectInformation.ProjectCount + expertProjectInformation.SkillCount + 1 + i, expertProjectInformation.GetVerticesCount() - 1);
            }

            return(g);
        }
 public BestAllocationFinder(ExpertProjectInformation expertProjectInformation)
 {
     ExpertProjectInformation = expertProjectInformation;
     FlowGraph = GraphConverter.ExpertProjectInformationToGraph(expertProjectInformation);
 }