public async Task <int> Invoke(EnvironmentVar enVar)
        {
            Task monitor = Task.Run(() =>
            {
                LocalFileAccess lfa = new LocalFileAccess();
                while (!_enVars.All(x => x.finishIndicate == true))
                {
                    for (int i = 0; i < _enVars.Length; i++)
                    {
                        if (_record.updateIndicate[i] == true)
                        {
                            /** update fitRecord to File **/
                            lfa.StoreListToLinesAppend(Directory.GetCurrentDirectory() + @"\OUT\MOGA\" + _enVars[i].pmProblem["Name"] + @"\CEOutput_" + i.ToString(), _record.currentGen[i]);
                            lfa.StoreListToLinesAppend(Directory.GetCurrentDirectory() + @"\OUT\MOGA\" + _enVars[i].pmProblem["Name"] + @"\CEOutput_" + i.ToString(), _record.currentCElist[i]);

                            List <string> tmpStr = new List <string>();
                            for (int j = 0; j < _record.currentFitnessList[i].Count; j++)
                            {
                                tmpStr.Add(_record.currentFitnessList[i][j].Item1 + " " + _record.currentFitnessList[i][j].Item2);
                            }
                            lfa.StoreListToLinesAppend(Directory.GetCurrentDirectory() + @"\OUT\MOGA\" + _enVars[i].pmProblem["Name"] + @"\CEOutput_" + i.ToString(), tmpStr);

                            for (int k = 0; k < _record.currentBestSolution[i].Length; k++)
                            {
                                if (_record.currentBestSolution[i][k] != null)
                                {
                                    lfa.StoreListToLinesAppend(Directory.GetCurrentDirectory() + @"\OUT\MOGA\" + _enVars[i].pmProblem["Name"] + @"\CEOutput_" + i.ToString(), _record.currentBestSolution[i][k]);
                                }
                            }
                            _record.updateDisplay[i] = true;
                            while (_record.updateDisplay[i] == true)
                            {
                                ;
                            }
                            _record.updateIndicate[i] = false;
                        }
                    }
                }
                for (int i = 0; i < _enVars.Length; i++)
                {
                    string timeElaspe = @"Total Time: " + Math.Round(_record.Watch[i].ElapsedMilliseconds * 1.0 / (1000 * 60), 3).ToString();
                    lfa.StoreListToLinesAppend(Directory.GetCurrentDirectory() + @"\OUT\MOGA\" + _enVars[i].pmProblem["Name"] + @"\CEOutput_" + i.ToString(), new List <string>()
                    {
                        timeElaspe
                    });
                }
            });
            await monitor;

            Console.WriteLine("Mointor Closed.");
            return(0);
        }
Exemplo n.º 2
0
        public async Task <int> Invoke(EnvironmentVar enVar)
        {
            Task t = Task.Run(() =>
            {
                for (int i = 0; i >= 3; i--)
                {
                    System.Threading.Thread.Sleep(1000);
                    Console.WriteLine("Starts in: {0}-{1}", i, a);
                }
            });
            await t;

            await _next(enVar);

            Console.WriteLine("All tasks are done");

            return(0);
        }
Exemplo n.º 3
0
        public async Task <int> Invoke(EnvironmentVar enVar)
        {
            int k = 0;

            for (int i = 0; i < _enVars.Length; i++)
            {
                _enVars[i]           = new EnvironmentVar();
                _enVars[i].pmProblem = _record.sutInfo;
                _enVars[i].initializeEnvironmentVar(i);
                apps[i] = new App();
            }
            Task <int>[] taskList = new Task <int> [_numOfThread];
            _next(null);   // Start Monitor
            while (k < _numOfTasks)
            {
                if (_numOfTasks - k < _numOfThread)
                {
                    _numOfThread = _numOfTasks - k;
                }
                for (int i = 0; i < _numOfThread; i++)
                {
                    apps[k + i].Use <TestMidWare>("NB");
                    //apps[k + i].Use<CACO.CustCACO>(_record, k+i);
                    apps[k + i].Use <MOGA.CustMOGA>(_record, k + i);
                    taskList[i] = apps[k + i].GetAppFunc().Invoke(_enVars[k + i]);
                    //taskList[i] = Task.Run(()=>{
                    //    Console.WriteLine("in tasks {0}",Task.CurrentId);
                    //    System.Threading.Thread.Sleep(5000);
                    //    Console.WriteLine("finish task {0}", Task.CurrentId);

                    //});
                }
                for (int i = 0; i < _numOfThread; i++)
                {
                    await taskList[i];
                }
                k = k + _numOfThread;
            }
            Console.WriteLine("All tasks are done");
            return(0);
        }
Exemplo n.º 4
0
        public Task <int> InvokeNext(EnvironmentVar env)
        {
            try
            {
                if (_queue.Count == 0)
                {
                    env.emptyQueue = true;

                    return(Task.Run <int>(() =>
                    {
                        return 0;
                    }));
                }
                var        Obj          = _queue.Dequeue();
                MethodInfo InvokeMethod = Obj.GetType().GetMethod("Invoke");
                return((Task <int>)InvokeMethod.Invoke(Obj, new object[] { env }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }