Exemple #1
0
        public void WriteFile(string FileName)
        {
            try
            {
                using (StreamWriter writetext = new StreamWriter(FileName))
                {
                    // ghi danh sach dinh
                    writetext.WriteLine(dsDinh.Count);
                    for (int index = 0; index < dsDinh.Count; index++)
                    {
                        Dinh dinh = dsDinh[index];
                        writetext.WriteLine(dinh.ID + " " + dinh.x + " " + dinh.y + " " + dinh.Ten);
                    }

                    // ghi danh sach dinh
                    writetext.WriteLine(dsCanh.Count);
                    for (int index = 0; index < dsCanh.Count; index++)
                    {
                        Canh canh = dsCanh[index];
                        writetext.WriteLine(canh.ID + " " + canh.IDXP + " " + canh.IDKT + " " + canh.x1 + " " + canh.y1 + " " + canh.x2 + " " + canh.y2 + " " + canh.TrongSo + " " + canh.LoaiCanh);
                    }

                    // thong bao
                    MessageBox.Show("Lưu đồ thị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                MessageBox.Show("Lưu đồ thị thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private static void SaveGraph(int Di)
        {
            if (Di == -2)
            {
                if (!isFound)
                {
                    return;
                }
                ans.Add(dothiz);
                return;
            }
            DoThi z = dothi.Clone();

            for (int index = 0; index < z.dsDinh.Count; index++)
            {
                Dinh dinh = z.dsDinh[index];
                if (!kt[index] || index == S)
                {
                    dinh.mau = Color.Green;
                }
                else
                {
                    dinh.mau = Color.LightGray;
                }

                if (Di == index)
                {
                    dinh.mau = Color.OrangeRed;
                }
            }

            ans.Add(z);
        }
Exemple #3
0
        private static void SaveGraph(int IDcanh)
        {
            DoThi z = dothi.Clone();

            if (IDcanh >= 0)
            {
                flag[IDcanh] = true;
            }

            for (int index = 0; index < dothi.dsCanh.Count; index++)
            {
                Canh canh = z.dsCanh[index];
                if (flag[index])
                {
                    canh.mau = Color.Green;
                }
                else
                {
                    canh.mau = Color.LightGray;
                }

                if (index == IDcanh)
                {
                    canh.mau = Color.OrangeRed;
                }
            }

            for (int i = 0; i < dothi.dsDinh.Count; i++)
            {
                Dinh dinh = z.dsDinh[i];
                if (d[i] == oo)
                {
                    dinh.ThongTinThem = "D[" + dinh.Ten + "] = +oo";
                }
                else
                {
                    dinh.ThongTinThem = "D[" + dinh.Ten + "] = " + d[i];
                }

                if (kt[i] == false)
                {
                    dinh.mau = Color.Green;
                }
                else
                {
                    dinh.mau = Color.LightGray;
                }
            }

            ans.Add(z);
        }
Exemple #4
0
        private static void SaveGraph(int mod)
        {
            DoThi z = dothi.Clone();

            for (int index = 0; index < z.dsDinh.Count; index++)
            {
                Dinh dinh = z.dsDinh[index];

                if (kt[index])
                {
                    dinh.mau = Color.LightGray;
                }
                else
                {
                    dinh.mau = Color.Green;
                }

                if (mod == index)
                {
                    dinh.mau = Color.OrangeRed;
                }
            }

            if (mod == -2 && kt[T] == false)
            {
                // in đường đi cuối cùng
                int u = T;
                while (u != S)
                {
                    int x = trace[u];

                    // tô màu đỏ cạnh nối từ x đến u
                    int IDu = dothi.dsDinh[u].ID;
                    int IDx = dothi.dsDinh[x].ID;

                    // tìm cạnh 2 chiều
                    Canh canh = z.dsCanh
                                .Where(p => p.LoaiCanh == 0)
                                .Where(p => (p.IDXP == IDx && p.IDKT == IDu) || (p.IDXP == IDu && p.IDKT == IDx))
                                .FirstOrDefault();
                    if (canh != null)
                    {
                        canh.mau = Color.Red;
                    }
                    else
                    {
                        // tìm canhk 1 chiều
                        canh = z.dsCanh
                               .Where(p => p.LoaiCanh == 1)
                               .Where(p => (p.IDXP == IDx && p.IDKT == IDu))
                               .FirstOrDefault();
                        if (canh != null)
                        {
                            canh.mau = Color.Red;
                        }
                    }

                    u = trace[u];
                }
            }

            ans.Add(z);
        }
Exemple #5
0
        public void ReadFile(string FileName)
        {
            try
            {
                DoThi temp = new DoThi();
                using (StreamReader readtext = new StreamReader(FileName))
                {
                    // Load list
                    int cntDinh;
                    cntDinh = Int32.Parse(readtext.ReadLine());
                    for (int index = 0; index < cntDinh; index++)
                    {
                        Dinh dinh = new Dinh();

                        string   line = readtext.ReadLine();
                        string[] k    = line.Split(' ');

                        dinh.ID  = Int32.Parse(k[0]);
                        dinh.x   = Int32.Parse(k[1]);
                        dinh.y   = Int32.Parse(k[2]);
                        dinh.Ten = k[3];
                        dinh.mau = Color.Green;

                        temp.dsDinh.Add(dinh);
                    }

                    // Load list canh
                    int cntCanh;
                    cntCanh = Int32.Parse(readtext.ReadLine());
                    for (int index = 0; index < cntCanh; index++)
                    {
                        Canh canh = new Canh();

                        string   line = readtext.ReadLine();
                        string[] k    = line.Split(' ');

                        canh.ID       = Int32.Parse(k[0]);
                        canh.IDXP     = Int32.Parse(k[1]);
                        canh.IDKT     = Int32.Parse(k[2]);
                        canh.x1       = Int32.Parse(k[3]);
                        canh.y1       = Int32.Parse(k[4]);
                        canh.x2       = Int32.Parse(k[5]);
                        canh.y2       = Int32.Parse(k[6]);
                        canh.TrongSo  = Int32.Parse(k[7]);
                        canh.LoaiCanh = Int32.Parse(k[8]);
                        canh.mau      = Color.Black;

                        temp.dsCanh.Add(canh);
                    }
                }

                MessageBox.Show("Load đồ thị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                // lưu đồ thị theo đồ thị vừa đọc
                this.dsDinh = temp.dsDinh;
                this.dsCanh = temp.dsCanh;
            }
            catch
            {
                MessageBox.Show("Đọc đồ thị thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #6
0
 public void AddDinh(Dinh tg)
 {
     dsDinh.Add(tg);
 }
Exemple #7
0
        private static void SaveGraph(int mod)
        {
            DoThi z = dothi.Clone();

            for (int index = 0; index < z.dsDinh.Count; index++)
            {
                Dinh dinh = z.dsDinh[index];

                if (d[index] != oo)
                {
                    dinh.ThongTinThem = "D[" + dinh.Ten + "] = " + d[index];
                }
                else
                {
                    dinh.ThongTinThem = "D[" + dinh.Ten + "] = +oo";
                }
            }

            for (int index = 0; index < z.dsCanh.Count; index++)
            {
                Canh canh = z.dsCanh[index];

                canh.mau = Color.LightGray;
                if (kt[index])
                {
                    canh.mau = Color.Green;
                }
                if (index == mod)
                {
                    canh.mau = Color.OrangeRed;
                }
            }

            if (mod == -2 && d[T] != oo)
            {
                // in đường đi cuối cùng
                int u = T;
                while (u != S)
                {
                    int x = trace[u];

                    // tô màu đỏ cạnh nối từ x đến u
                    int IDu = dothi.dsDinh[u].ID;
                    int IDx = dothi.dsDinh[x].ID;

                    // tìm cạnh 2 chiều
                    Canh canh = z.dsCanh
                                .Where(p => p.LoaiCanh == 0 && p.TrongSo == d[u] - d[x])
                                .Where(p => (p.IDXP == IDx && p.IDKT == IDu) || (p.IDXP == IDu && p.IDKT == IDx))
                                .FirstOrDefault();
                    if (canh != null)
                    {
                        canh.mau = Color.Red;
                    }
                    else
                    {
                        // tìm canhk 1 chiều
                        canh = z.dsCanh
                               .Where(p => p.LoaiCanh == 1 && p.TrongSo == d[u] - d[x])
                               .Where(p => (p.IDXP == IDx && p.IDKT == IDu))
                               .FirstOrDefault();
                        if (canh != null)
                        {
                            canh.mau = Color.Red;
                        }
                    }

                    u = trace[u];
                }
            }

            ans.Add(z);
        }