示例#1
0
        //private void Marire(Retea retea)
        //{
        //   Console.WriteLine("\n\n");
        //   Console.WriteLine(retea.ToString());

        //   Drum drum = CreeazaDrum(retea);
        //   Console.WriteLine(drum.AsString(retea));

        //   drum.Arce.ForEach(arc => arc.Flux += drum.GetCapacitateRezidualaMin(retea));

        //   //todo: check if arcs are updated by reference
        //}

        private void Marire(Retea retea)
        {
            //Console.WriteLine("\n\n");
            //Console.WriteLine(retea.ToString());

            Drum drum = CreeazaDrum(retea);
            //Console.WriteLine(drum.AsString(retea));


            double r = drum.GetCapacitateRezidualaMin(retea);

            Console.WriteLine($"{drum.AsString(retea)} | r(D)={r}");
            if (r > 0)
            {
                drum.Arce.ForEach(arc => {
                    arc.Flux += r;

                    Arc arcRetea   = retea.Arce.FirstOrDefault(a => a.X.Id == arc.X.Id && a.Y.Id == arc.Y.Id);
                    arcRetea.Flux += r;

                    Arc arcInvers = retea.Arce.FirstOrDefault(a => a.X.Id == arc.Y.Id && a.Y.Id == arc.X.Id);

                    if (arcInvers == null)
                    {
                        arcInvers = new Arc(arc.Y, arc.X, 0, 0);
                        retea.Arce.Add(arcInvers);
                    }
                    else
                    {
                        if (arcInvers.GetCapacitateReziduala(retea) <= 0)
                        {
                            retea.Arce.Remove(arcInvers);
                        }
                    }

                    if (arcRetea.GetCapacitateReziduala(retea) <= 0)
                    {
                        retea.Arce.Remove(arcRetea);
                    }
                });

                Console.WriteLine("\n\n");
                Console.WriteLine(retea.ToString());
                Console.WriteLine($"Max value: {retea.GetValoareMaxima()}");
            }

            //todo: check if arcs are updated by reference
        }
        private void Marire(Retea retea)
        {
            Console.WriteLine("\n\n");
            Console.WriteLine($"MARIRE FLUX NR.{_nrIteratie}: ");

            _nrIteratie++;

            // Predecesori
            List <Nod> predecesori = new List <Nod>();

            retea.Noduri.ForEach(n => predecesori.Add(n.Predecesor));

            Console.Write("Predecesori: ");
            predecesori.ForEach(p => Console.Write($"{((p != null) ? p.ToString() : "-")}, "));

            // Creare drum
            Drum   drum  = CreeazaDrum(retea);
            double rDrum = drum.GetCapacitateRezidualaMin(retea);

            Console.WriteLine($"{drum.AsString(retea)} | r(D)={rDrum}");
            Console.WriteLine();

            if (rDrum > 0)
            {
                drum.Arce.ForEach(arc => {
                    arc.Flux += rDrum;

                    Arc arcInvers = retea.Arce.FirstOrDefault(a => a.X.Id == arc.Y.Id && a.Y.Id == arc.X.Id);

                    if (arcInvers == null)
                    {
                        arcInvers = new Arc(arc.Y, arc.X, 0, 0);
                        retea.Arce.Add(arcInvers);
                    }
                });

                Console.WriteLine(retea.ToString());
                Console.WriteLine($"Max value: {retea.GetValoareMaxima()}");
            }
        }