Esempio n. 1
0
        public static void GenerateRunnablesBank(List <IRunnable> runnables)
        {
            var       baseBalance = 100.0;
            BankAgent bank        = new BankAgent(baseBalance, (x) => Console.WriteLine(Math.Round(x, 4)), 0);

            runnables.Add(bank);
            runnables.Add(new SubBankAgent(bank, (y) => { return(y - 1.2); }, 0));
            runnables.Add(new SubBankAgent(bank, (y) => { return(y + 0.33); }, 1));
            runnables.Add(new SubBankAgent(bank, (y) => { return(y * 1.07); }, 2));
            runnables.Add(new SubBankAgent(bank, (y) => { return(y + Math.Sin(DateTime.UtcNow.Millisecond)); }, 3));
            runnables.Add(new SubBankAgent(bank, (y) => { return(y - Math.PI); }, 4));

            /*runnables.AddRange(runnables.GetRange(1, 5));
            *  runnables.AddRange(runnables.GetRange(1, 5));
            *  runnables.AddRange(runnables.GetRange(1, 5));
            *  runnables.AddRange(runnables.GetRange(1, 5));
            *  runnables.AddRange(runnables.GetRange(1, 5));*/
        }
Esempio n. 2
0
        public SubBankAgent(BankAgent agent, Func <double, double> action, int Id) : base(Id)
        {
            this.action = action;
            this.agent  = agent;
            myBalance   = agent.balance;
            mutex       = agent.mutex;
            o           = agent.o;
            Random r = new Random();

            while (!agent.pairs.TryAdd(Id, r.Next(50, 150)))
            {
                ;
            }
            queue = new ConcurrentQueue <Action>(new List <Action>
            {
                new Action(() => agent.pairs[Id] -= Convert.ToDouble(Id) * 1.2),
                new Action(() => agent.pairs[Id] += Convert.ToDouble(Id) * 0.33),
                new Action(() => agent.pairs[Id] *= Convert.ToDouble(Id) * 1.07),
                new Action(() => agent.pairs[Id] *= Convert.ToDouble(Id) * Math.Sin(DateTime.UtcNow.Millisecond)),
                new Action(() => agent.pairs[Id] -= Convert.ToDouble(Id) * Math.PI)
            });
        }