コード例 #1
0
        /// <summary>
        /// writes results (all possible module lists) to a file
        /// </summary>
        /// <param name="fileName">file name to write to</param>
        /// <param name="lists">all possible module lists</param>
        static void SaveResults(string fileName, ModuleListContainer lists)
        {
            using (StreamWriter writer = new StreamWriter(fileName)) {
                if (lists == null || lists.Count == 0)
                {
                    writer.WriteLine("Nėra įmanomų modulių priklausomybės sąrašų");
                }
                else
                {
                    writer.WriteLine("Visi įmanomi modulių priklausomybės sąrašai:");

                    for (int i = 0; i < lists.Count; i++)
                    {
                        ModuleList list = lists.GetModuleList(i);

                        for (int j = 0; j < list.Count; j++)
                        {
                            writer.WriteLine("{0} {1}", list.GetModule(j).Code, list.GetModule(j).Name);
                        }

                        writer.WriteLine();
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// entry point of the program
        /// </summary>
        /// <param name="args">arguments for the program</param>
        static void Main(string[] args)
        {
            ModuleList allModules = ReadData("U2.txt");

            WriteInitialDataToFile("PradDuomenys.txt", allModules);

            FindDependentModules(allModules);
            ModuleListContainer lists = FindAllPosibleModuleLists(allModules);

            SaveResults("Rezultatai.txt", lists);
        }
コード例 #3
0
        /// <summary>
        /// finds all possible module dependency lists
        /// </summary>
        /// <param name="modules">list of all modules</param>
        /// <returns>ModuleListContainer with all possible lists in it</returns>
        static ModuleListContainer FindAllPosibleModuleLists(ModuleList modules)
        {
            if (ZeroListsPossible(modules))
            {
                return(null);
            }

            ModuleListContainer moduleLists = new ModuleListContainer(10000);

            for (int i = 0; i < modules.Count; i++)
            {
                CreateModuleLists(moduleLists, modules, modules.GetModule(i));
            }

            return(moduleLists);
        }
コード例 #4
0
        /// <summary>
        /// creates all possible lists where specific module is in positions from
        /// it's needed modules count to the number of modules that depend on it
        /// </summary>
        /// <param name="lists">module list container containing all formed dependency lists</param>
        /// <param name="modules">all modules that can be chosen</param>
        /// <param name="module">module which will be placed in specific positions</param>
        static void CreateModuleLists(ModuleListContainer lists, ModuleList modules, Module module)
        {
            int neededModulesCount    = module.GetNeededModules().Length;
            int dependentModulesCount = module.DependentModulesCount;

            for (int j = neededModulesCount; j < modules.Count - dependentModulesCount; j++)
            {
                ModuleList list = new ModuleList(modules.Count);
                ModuleList unnecessaryModules = FindUnnecessaryModules(modules, module);
                AddNeededModulesToTheList(modules, list, module.GetNeededModules());
                list.AddAll(unnecessaryModules);
                list.MoveModuleTo(module, j);

                AddDependentModulesToTheList(modules, list, module.DependentModules, module.DependentModulesCount);

                if (!lists.Contains(list) && ValidList(list))
                {
                    lists.AddModuleList(list);
                }
            }
        }