示例#1
0
        /*******************************************************************/
        /************************ PRIVATE METHODS **************************/
        /*******************************************************************/

        /*******************************************************************/
        /************************* PUBLIC METHODS **************************/
        /*******************************************************************/

        public void Start()
        {
            switch (currentTask.Status)
            {
            case TaskStatus.Dividing:

                byte[][] dividedProblems = taskSolver.DivideProblem(4);

                PartialProblem[] partialProblems = new PartialProblem[dividedProblems.Count()];
                for (int i = 0; i < dividedProblems.Count(); i++)
                {
                    partialProblems[i] = new PartialProblem((ulong)currentTask.ID, dividedProblems[i], (ulong)NodeID);
                }
                SolvePartialProblemsMessage solvePartialProblemsMessage = new SolvePartialProblemsMessage(currentTask.Type, (ulong)currentTask.ID, currentTask.CommonData, (ulong)4, partialProblems);
                Console.Write(">>Sending solve partial problems message. ");
                messageProcessor.Communicate(solvePartialProblemsMessage);
                this.statusThread.State = StatusThreadState.Idle;
                this.currentTask        = null;

                break;

            case TaskStatus.Solving:

                byte[]     solvedPartialProblem = taskSolver.Solve(currentTask.BaseData, new TimeSpan(0, 0, 5));
                Solution[] solutions            = new Solution[1];
                //TODO subTask id, timeout checking , computations time
                solutions[0] = new Solution((ulong)currentTask.ID, false, SolutionsSolutionType.Partial, 4000, solvedPartialProblem);

                SolutionsMessage solutionMessage = new SolutionsMessage(currentTask.Type, (ulong)currentTask.ID, currentTask.CommonData, solutions);
                Console.WriteLine(">>Sending solution message. ");
                messageProcessor.Communicate(solutionMessage);
                statusThread.State = StatusThreadState.Idle;
                this.currentTask   = null;
                break;

            case TaskStatus.Merging:
                byte[][] partialSolutions = new byte[currentTask.subTasks.Count()][];
                for (int i = 0; i < currentTask.subTasks.Count(); i++)
                {
                    partialSolutions[i] = currentTask.subTasks[i].BaseData;
                }
                byte[] mergedSolution = taskSolver.MergeSolution(partialSolutions);

                Solution[] solution = new Solution[1];
                //TODO subTask id, timeout checking , computations time
                solution[0] = new Solution((ulong)currentTask.ID, false, SolutionsSolutionType.Final, 4000, mergedSolution);
                SolutionsMessage finalSolutionMessage = new SolutionsMessage(currentTask.Type, (ulong)currentTask.ID, currentTask.CommonData, solution);
                messageProcessor.Communicate(finalSolutionMessage);
                this.statusThread.State = StatusThreadState.Idle;
                this.currentTask        = null;
                break;
            }
            // Implement in private methods:
            // Depending on what has to be computed
            // run a task solver method.

            // TODO collect result.
        }
示例#2
0
        static void Main(string[] args)
        {
            /************ Create node object ************/
            RegisterType type            = RegisterType.TaskManager;
            byte         parallelThreads = 5;

            string[] problems = { "DVRP" };

            NetworkNode node = new NetworkNode(type, parallelThreads, problems);
            //NetworkNode node = new NetworkNode();

            /************ Setup connection ************/
            string inputLine = "";

            foreach (string arg in args)
            {
                inputLine += arg + " ";
            }

            InputParser inputParser = new InputParser(inputLine);

            inputParser.ParseInput();

            IPAddress address = inputParser.Address;
            int       port    = inputParser.Port;

            SmartConsole.PrintLine("I'm a " + node.Type, SmartConsole.DebugLevel.Advanced);
            NetworkClient client = new NetworkClient(address, port);

            /************ Setup Logic modules ************/

            // system tracker
            SystemTracker systemTracker = new SystemTracker(node);

            MessageHandler messageHandler = new MessageHandler(systemTracker, client);

            MessageProcessor messageProcessor = new MessageProcessor(messageHandler, client, node);

            node.MessageProcessor = messageProcessor;

            /************ Init all threads ************/
            for (int i = 0; i < parallelThreads; i++)
            {
                node.TaskThreads[i] = new TaskThread(i, problems[0], messageProcessor, (int)node.Id);
            }

            /************ Register ************/
            client.Connect();
            SmartConsole.PrintLine("Sending Register message", SmartConsole.DebugLevel.Advanced);
            messageProcessor.Communicate(node.ToRegisterMessage());

            KeepAliveTimer keepAliveTimer = new KeepAliveTimer(messageProcessor, systemTracker);

            /************ Start Logic modules ************/
            keepAliveTimer.Start();

            Object mutex = new Object();

            // TODO Thread pool waiting

            lock (mutex)
            {
                Monitor.Wait(mutex);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            RegisterType type            = RegisterType.ComputationalClient;
            byte         parallelThreads = 5;

            string[] problems = { "DVRP" };

            SolveRequestMessage solveRequestMessage = new SolveRequestMessage();

            string inputLine = "";

            foreach (string arg in args)
            {
                inputLine += arg + " ";
            }

            InputParser inputParser = new InputParser(inputLine);

            inputParser.ParseInput();

            IPAddress address = inputParser.Address;
            int       port    = inputParser.Port;

            NetworkNode node = new NetworkNode(type, parallelThreads, problems)
            {
                Timeout = CLIENT_REQUEST_FREQUENCY
            };



            SmartConsole.PrintLine("ComputationalClient starting work", SmartConsole.DebugLevel.Advanced);

            NetworkClient client = new NetworkClient(address, port);

            for (; ;)
            {
                /*************** Register *****************/

                doWork = true;

                SmartConsole.PrintLine("Type in a file path", SmartConsole.DebugLevel.Advanced);
                String filePath = Console.ReadLine();
                solveRequestMessage = loadDataFromDisc(filePath);

                /******  setup logic modules *****************/
                SystemTracker    systemTracker    = new SystemTracker(node);
                MessageHandler   messageHandler   = new MessageHandler(systemTracker, client);
                MessageProcessor messageProcessor = new MessageProcessor(messageHandler, client, node);
                KeepAliveTimer   keepAliveTimer   = new KeepAliveTimer(messageProcessor, systemTracker);

                messageHandler.keepAliveTimer = keepAliveTimer;

                node.MessageProcessor = messageProcessor;

                /************ send solve request *****************/
                client.Connect();

                messageProcessor.Communicate(solveRequestMessage);
                COMP_TIME = DateTime.Now;

                while (doWork)
                {
                    Thread.Sleep(1000);
                }

                /*Object mutex = new Object();
                 *
                 * lock (mutex)
                 * {
                 *  Monitor.Wait(mutex);
                 * }*/
            }
        }