示例#1
0
 public Task Compute()
 {
     if (Simulated)
     {
         return(Task.Run(() =>
         {
             foreach (var bond in bonds)
             {
                 bond.OnResultComputed(PriceLib.ComputePrice(bond), null);
                 computingTime += PriceLib.EstimedTime(bond);
             }
         }));
     }
     else
     {
         return(Task.Run(() =>
         {
             var watch = new Stopwatch();
             watch.Start();
             foreach (var bond in bonds)
             {
                 Thread.Sleep(PriceLib.EstimedTime(bond) * 1000);
                 bond.OnResultComputed(PriceLib.ComputePrice(bond), null);
             }
             watch.Stop();
             computingTime += (int)watch.ElapsedMilliseconds / 1000;
         }));
     }
 }
示例#2
0
 public int EstimedTime(Bond bond)
 {
     if (GetAvailableNodeIndex(bond) != -1)
     {
         return(0);
     }
     return(PriceLib.EstimedTime(bond) + 8);
 }
示例#3
0
        public int GetAvailableNodeIndex(Bond bond)
        {
            /* Check if we can add the bond to a node without increasing the computation time.
             * Return the index of the node or -1 if we can't find one */
            if (nodes.Count == 0)
            {
                return(-1);
            }
            var longestComputation = nodes.Max(node => node.EstimedTime(bond)) - PriceLib.EstimedTime(bond);
            int index = 0;

            foreach (var node in nodes)
            {
                if (node.EstimedTime(bond) <= longestComputation)
                {
                    return(index);
                }
                index++;
            }
            return(-1);
        }
示例#4
0
 public int EstimedTime(Bond bond)
 {
     return(bonds.Select(PriceLib.EstimedTime).Sum() + PriceLib.EstimedTime(bond));
 }