Ejemplo n.º 1
0
        private static void SaveGraph(int mod)
        {
            DoThi z = dothi.Clone();

            for (int i = 1; i <= z.dsCanh.Count; i++)
            {
                Canh canh = z.dsCanh[i - 1];
                if (kt[i] == true)
                {
                    canh.mau = Color.Green;
                    continue;
                }

                if (i == mod)
                {
                    canh.mau = Color.OrangeRed;
                }
                else
                {
                    canh.mau = Color.LightGray;
                }
            }

            ans.Add(z);
        }
        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);
        }
Ejemplo n.º 3
0
 public static List <DoThi> Run(DoThi a)
 {
     ans   = new List <DoThi>();
     dothi = a.Clone();
     InitGraph();
     return(ans);
 }
        public static List <DoThi> Test(DoThi a, int IDs, int IDt)
        {
            List <DoThi> ans = new List <DoThi>();

            DoThi tg = a.Clone();

            foreach (Dinh dinh in tg.dsDinh)
            {
                dinh.mau = Color.Aqua;
                if (dinh.ID != IDs)
                {
                    dinh.ThongTinThem = "D[" + dinh.Ten + "] = +oo";
                }
                else
                {
                    dinh.ThongTinThem = "D[" + dinh.Ten + "] = 0";
                }
            }

            ans.Add(tg);
            foreach (Dinh dinh in a.dsDinh)
            {
                DoThi z = tg.Clone();
                z.dsDinh.Where(p => p.ID == dinh.ID).FirstOrDefault().mau = Color.Orange;
                tg = z;
                ans.Add(z);
            }

            return(ans);
        }
 public static List <DoThi> Run(DoThi a, int IDs)
 {
     ans   = new List <DoThi>();
     dothi = a.Clone();
     S     = IndexOf(IDs);
     InitGraph();
     return(ans);
 }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public DoThi Clone()
        {
            DoThi ans = new DoThi();

            foreach (Dinh dinh in this.dsDinh)
            {
                Dinh zdinh;
                zdinh = (Dinh)dinh.Clone();
                ans.AddDinh(zdinh);
            }

            foreach (Canh canh in this.dsCanh)
            {
                Canh zcanh;
                zcanh = (Canh)canh.Clone();
                ans.AddCanh(zcanh);
            }
            return(ans);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
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);
        }