Пример #1
0
        static public void worst_fit_dec(string Source, string Destination)
        {
            List <Audios> MyAudios  = new List <Audios>(BasicOperations.Audio_files);
            List <Folder> MyFolders = new List <Folder>(MyAudios.Count);

            BasicOperations.SortInDecreasing(MyAudios);
            string path = Destination;

            if (!Directory.Exists(path))
            {
                DirectoryInfo di = Directory.CreateDirectory(path);
            }
            string FileName    = path;
            string source      = Source;
            string destination = " ";
            int    count       = 0;

            for (int i = 0; i < BasicOperations.num_of_rec; i++)
            {
                long   max         = 0;
                int    index       = 0;
                bool   test        = false;
                Folder Temp_folder = new Folder();
                if (count == 0)
                {
                    Temp_folder.hours       = MyAudios[i].hours;
                    Temp_folder.min         = MyAudios[i].min;
                    Temp_folder.sec         = MyAudios[i].sec;
                    Temp_folder.free_space  = BasicOperations.max_size;
                    Temp_folder.free_space -= MyAudios[i].total_in_sec;
                    Temp_folder.FolderAudios.Add(MyAudios[i]);
                    MyFolders.Add(Temp_folder);
                    count++;
                }
                else
                {
                    for (int j = 0; j < count; j++)
                    {
                        if (MyFolders[j].free_space > max && MyFolders[j].free_space >= MyAudios[i].total_in_sec)
                        {
                            max   = MyFolders[j].free_space;
                            index = j;
                            test  = true;
                        }
                    }
                    if (test)
                    {
                        MyFolders[index].hours      += MyAudios[i].hours;
                        MyFolders[index].min        += MyAudios[i].min;
                        MyFolders[index].sec        += MyAudios[i].sec;
                        MyFolders[index].free_space -= MyAudios[i].total_in_sec;
                        MyFolders[index].FolderAudios.Add(MyAudios[i]);
                    }
                    else
                    {
                        Temp_folder.hours       = MyAudios[i].hours;
                        Temp_folder.min         = MyAudios[i].min;
                        Temp_folder.sec         = MyAudios[i].sec;
                        Temp_folder.free_space  = BasicOperations.max_size;
                        Temp_folder.free_space -= MyAudios[i].total_in_sec;
                        Temp_folder.FolderAudios.Add(MyAudios[i]);
                        MyFolders.Add(Temp_folder);
                        count++;
                    }
                }
            }

            FileName = "";
            for (int no = 0; no < MyFolders.Count; no++)
            {
                int size = MyFolders[no].FolderAudios.Count;
                path  = Destination;
                path += @"\f" + (no + 1);
                DirectoryInfo di = Directory.CreateDirectory(path);
                FileName = Destination + @"\f" + (no + 1) + "_MetaData.txt";
                System.IO.FileStream F = new FileStream(FileName, FileMode.Create);
                StreamWriter         w = new StreamWriter(F);
                w.WriteLine("f" + (no + 1));
                for (int index = 0; index < size; index++)
                {
                    source      = Source;
                    source     += @"\" + MyFolders[no].FolderAudios[index].name;
                    destination = path + @"\" + MyFolders[no].FolderAudios[index].name;
                    Task.Run(() =>
                    {
                        System.IO.File.Copy(source, destination);
                    });
                    w.WriteLine(MyFolders[no].FolderAudios[index].name + " " + MyFolders[no].FolderAudios[index].hours + ":" + MyFolders[no].FolderAudios[index].min + ":" + MyFolders[no].FolderAudios[index].sec);
                }
                MyFolders[no].ConvertUnits();
                w.WriteLine(MyFolders[no].hours + ":" + MyFolders[no].min + ":" + MyFolders[no].sec);
                w.Close();
            }
        }
Пример #2
0
        static public void worst_fitp_dec(string Source, string Destination)
        {
            List <Audios> MyAudios  = new List <Audios>(BasicOperations.Audio_files);
            List <Folder> MyFolders = new List <Folder>(MyAudios.Count);

            BasicOperations.SortInDecreasing(MyAudios);
            PriorityQueue <Folder> PQ = new PriorityQueue <Folder>();
            string path = Destination;

            if (!Directory.Exists(path))
            {
                DirectoryInfo di = Directory.CreateDirectory(path);
            }
            int    k           = 0;
            string FileName    = path;
            string source      = Source;
            string destination = "";
            int    count       = 0;

            for (int i = 0; i < BasicOperations.num_of_rec; i++)
            {
                if (count == 0)
                {
                    Folder Temp_folder = new Folder();
                    Folder temp        = new Folder();
                    Temp_folder.hours       = MyAudios[i].hours;
                    Temp_folder.min         = MyAudios[i].min;
                    Temp_folder.sec         = MyAudios[i].sec;
                    Temp_folder.free_space  = BasicOperations.max_size;
                    Temp_folder.free_space -= MyAudios[i].total_in_sec;
                    Temp_folder.FolderAudios.Add(MyAudios[i]);
                    Temp_folder.index = k;
                    MyFolders.Add(Temp_folder);
                    PQ.Enqueue(Temp_folder);
                    k++;
                    count++;
                }
                else
                {
                    if (PQ.Peek().free_space >= MyAudios[i].total_in_sec)
                    {
                        Folder Temp_folder = new Folder();
                        Folder temp        = new Folder();
                        temp = PQ.Peek();
                        PQ.Dequeue();
                        temp.hours      += MyAudios[i].hours;
                        temp.min        += MyAudios[i].min;
                        temp.sec        += MyAudios[i].sec;
                        temp.free_space -= MyAudios[i].total_in_sec;
                        MyFolders[temp.index].FolderAudios.Add(MyAudios[i]);
                        if (temp.free_space != 0)
                        {
                            PQ.Enqueue(temp);
                        }
                        else
                        {
                            count--;
                        }
                    }
                    else
                    {
                        Folder Temp_folder = new Folder();
                        Folder temp        = new Folder();
                        Temp_folder.index       = k;
                        Temp_folder.hours       = MyAudios[i].hours;
                        Temp_folder.min         = MyAudios[i].min;
                        Temp_folder.sec         = MyAudios[i].sec;
                        Temp_folder.free_space  = BasicOperations.max_size;
                        Temp_folder.free_space -= MyAudios[i].total_in_sec;
                        Temp_folder.FolderAudios.Add(MyAudios[i]);
                        Temp_folder.index = k;
                        MyFolders.Add(Temp_folder);
                        PQ.Enqueue(Temp_folder);
                        k++;
                        count++;
                    }
                }
            }

            FileName = "";
            for (int no = 0; no < MyFolders.Count; no++)
            {
                int size = MyFolders[no].FolderAudios.Count;
                path  = Destination;
                path += @"\f" + (no + 1);
                DirectoryInfo di = Directory.CreateDirectory(path);
                FileName = Destination + @"\f" + (no + 1) + "_MetaData.txt";
                System.IO.FileStream F = new FileStream(FileName, FileMode.Create);
                StreamWriter         w = new StreamWriter(F);
                w.WriteLine("f" + (no + 1));
                for (int index = 0; index < size; index++)
                {
                    source      = Source;
                    source     += @"\" + MyFolders[no].FolderAudios[index].name;
                    destination = path + @"\" + MyFolders[no].FolderAudios[index].name;
                    Task.Run(() =>
                    {
                        System.IO.File.Copy(source, destination);
                    });
                    w.WriteLine(MyFolders[no].FolderAudios[index].name + " " + MyFolders[no].FolderAudios[index].hours + ":" + MyFolders[no].FolderAudios[index].min + ":" + MyFolders[no].FolderAudios[index].sec);
                }
                w.WriteLine(MyFolders[no].hours + ":" + MyFolders[no].min + ":" + MyFolders[no].sec);
                w.Close();
            }
        }