Beispiel #1
0
        static void TestOrderSumParallel()
        {
            int count = 100;

            // Los datos de entrada
            var data = OrderValues
                       .Samples(count);

            // Asociamos los datos con la regla de combinación
            var input = data
                        .Select(x => new OrderValuesSumMonoid(x) as Monoid <OrderValues>)
                        .ToList();

            // Reducción secuencial
            var seqRes = input.Aggregate(OrderValuesSumMonoid.Empty, (a, b) => a * b);

            Console.WriteLine("seqRes: {0}", seqRes);

            // Reducción en paralelo
            // Ejemplo ilustrativo, pueden ser varios servidores.
            var parRes = input.AsParallel().Aggregate(OrderValuesSumMonoid.Empty, (a, b) => a * b);

            Console.WriteLine("parRes: {0}", parRes);
            Console.WriteLine("seqRes == parRes: {0}", seqRes == parRes);
            Console.WriteLine();
        }
Beispiel #2
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is OrderValues))
            {
                return(false);
            }
            OrderValues other = (OrderValues)obj;

            return(Quantity == other.Quantity && Amount == other.Amount);
        }
        public static IEnumerable<OrderLine> Samples(int count)
        {
            Random rnd = new Random();

            var seq = Enumerable
                .Range(1, count)
                .Select(n =>
                {
                    var r = rnd.Next(1, 6);
                    var prod = new Product(string.Format("P{0}", r));
                    var vals = new OrderValues(r, 1.5 * (double)r);
                    return new OrderLine(prod, vals);
                });
            return seq;
        }
Beispiel #4
0
        public static IEnumerable <OrderLine> Samples(int count)
        {
            Random rnd = new Random();

            var seq = Enumerable
                      .Range(1, count)
                      .Select(n =>
            {
                var r    = rnd.Next(1, 6);
                var prod = new Product(string.Format("P{0}", r));
                var vals = new OrderValues(r, 1.5 * (double)r);
                return(new OrderLine(prod, vals));
            });

            return(seq);
        }
Beispiel #5
0
        public Order(string code, string text)
        {
            _code = code;
            var ic    = CultureInfo.InvariantCulture;
            var lines = text.Split('\n');

            _lines = new List <OrderLine>(lines.Length);
            foreach (var line in lines)
            {
                var     parts  = line.Split(',');
                Product prod   = new Product(parts[0]);
                double  q      = Double.Parse(parts[1], ic);
                double  a      = Double.Parse(parts[2], ic);
                var     values = new OrderValues(q, a);
                var     ol     = new OrderLine(prod, values);
                _lines.Add(ol);
            }
        }
 public OrderLine(Product product, OrderValues values)
 {
     this.Product = product;
     this.Values = values;
 }
Beispiel #7
0
 public OrderLine(Product product, OrderValues values)
 {
     this.Product = product;
     this.Values  = values;
 }