Exemplo n.º 1
0
        public static SolvePartialProblemsMessage CreateSolvePartialProblemsMessage()
        {
            string problemType = "TSP";
            ulong id = 12;
            byte[] commonData = { 1, 23, 25, 2, 5, 5, 5, 5, 2, 26, 87 };
            ulong solvingTimeout = 1000;

            // fields for PartialProblem1
            ulong taskId1 = 123;
            byte[] data1 = { 24, 252, 6, 43, 57, 88 };
            ulong nodeId1 = 1;
            PartialProblem partialProblem1 = new PartialProblem(taskId1, data1, nodeId1);

            // fields for PartialProblem2
            ulong taskId2 = 321;
            byte[] data2 = { 24, 252, 6, 43, 57, 88 };
            ulong nodeId2 = 2;
            PartialProblem partialProblem2 = new PartialProblem(taskId2, data2, nodeId2);

            PartialProblem[] partialProblems = { partialProblem1, partialProblem2 };

            SolvePartialProblemsMessage expectedMessage = new SolvePartialProblemsMessage(problemType, id, commonData,
                                            solvingTimeout, partialProblems);
            return expectedMessage;
        }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            PartialProblem problem = obj as PartialProblem;


            return(TaskId == problem.TaskId && NodeID == problem.NodeID &&
                   Enumerable.SequenceEqual(Data, problem.Data));
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="problemType">
 ///     The problem type name as given by TaskSolver and Client
 /// </param>
 /// <param name="id">
 ///     The ID of the problem instance assigned by the server
 /// </param>
 /// <param name="commonData">
 ///     The data to be sent to all Computational Nodes
 /// </param>
 /// <param name="solvingTimeout">
 ///     Optional time limit – set by Client (in ms)
 /// </param>
 /// <param name="partialProblems">
 ///     The partial problems to be computed
 /// </param>
 public SolvePartialProblemsMessage(string problemType, ulong id, byte[] commonData,
                                 ulong solvingTimeout, PartialProblem[] partialProblems)
 {
     ProblemType = problemType;
     Id = id;
     CommonData = commonData;
     SolvingTimeout = solvingTimeout;
     PartialProblems = partialProblems;
     SolvingTimeoutSpecified = true;
 }
        public void Parse_XMLString_SolvePartialProblemsMessage()
        {
            /*********** Actual message ***********/
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"xml_samples\SolvePartialProblems.xml");

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(path);
            string xmlStr = xmlDoc.OuterXml;

            string name = Message.GetMessageName(xmlStr);
            SolvePartialProblemsMessage actualMessage = null;

            if (name == SolvePartialProblemsMessage.ELEMENT_NAME)
                actualMessage = SolvePartialProblemsMessage.Construct(xmlStr);

            /*********** Expected message ***********/
            string problemType = "TSP";
            ulong id = 12;
            byte[] commonData = { 1, 23, 25, 2, 5, 5, 5, 5, 2, 26, 87 };
            ulong solvingTimeout = 1000;

            // fields for PartialProblem1
            ulong taskId1 = 123;
            byte[] data1 = { 24, 252, 6, 43, 57, 88 };
            ulong nodeId1 = 1;
            PartialProblem partialProblem1 = new PartialProblem(taskId1, data1, nodeId1);

            // fields for PartialProblem2
            ulong taskId2 = 321;
            byte[] data2 = { 24, 252, 6, 43, 57, 88 };
            ulong nodeId2 = 2;
            PartialProblem partialProblem2 = new PartialProblem(taskId2, data2, nodeId2);

            PartialProblem[] partialProblems = { partialProblem1, partialProblem2 };

            SolvePartialProblemsMessage expectedMessage = new SolvePartialProblemsMessage(problemType, id, commonData,
                                            solvingTimeout, partialProblems);

            Assert.AreEqual(expectedMessage, actualMessage);
        }
        public void Parse_SolvePartialProblemMessage_XMLString()
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"xml_samples\SolvePartialProblems.xml");

            string problemType = "TSP";
            ulong id = 12;
            byte[] commonData = { 1, 23, 25, 2, 5, 5, 5, 5, 2, 26, 87 };
            ulong solvingTimeout = 1000;

            // fields for PartialProblem1
            ulong taskId1 = 123;
            byte[] data1 = { 24, 252, 6, 43, 57, 88 };
            ulong nodeId1= 1;
            PartialProblem partialProblem1 = new PartialProblem(taskId1, data1, nodeId1);

            // fields for PartialProblem2
            ulong taskId2 = 321;
            byte[] data2 = { 24, 252, 6, 43, 57, 88 };
            ulong nodeId2 = 2;
            PartialProblem partialProblem2 = new PartialProblem(taskId2, data2, nodeId2);

            PartialProblem[] partialProblems = { partialProblem1, partialProblem2 };

            SolvePartialProblemsMessage message = new SolvePartialProblemsMessage(problemType, id, commonData, 
                                            solvingTimeout, partialProblems);

            string actualXmlStr = message.ToXmlString();

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(path);
            string expectedXmlStr = xmlDoc.OuterXml;

            Assert.AreEqual(expectedXmlStr, actualXmlStr);
        }
        /// <summary>
        /// function sending PartialProblems message
        /// </summary>
        /// <param name="numOfTask"></param>
        /// <param name="partialList"></param>
        /// <param name="messagePackage"></param>
        /// <returns></returns>
        private bool SendPartialProblemsMessage(int numOfTask, List<PartialProblem> partialList, MessagePackage messagePackage)
        {
            PartialProblem[] partialProblems = new PartialProblem[partialList.Count];
            for (int j = 0; j < partialList.Count; j++)
            {
                partialProblems[j] = partialList[j];
            }
            SolvePartialProblemsMessage solvePartialProblemsMessage = new SolvePartialProblemsMessage(taskTracker.Tasks[numOfTask].Type, (ulong)taskTracker.Tasks[numOfTask].ID, taskTracker.Tasks[numOfTask].CommonData, (ulong)4, partialProblems);
            server.Send(messagePackage.Socket, solvePartialProblemsMessage);

            SmartConsole.PrintLine("Solve Partial Problems Message has been send (to Computational node). Number of subTasks." + partialList.Count, SmartConsole.DebugLevel.Advanced);

            return true;
        }
Exemplo n.º 7
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.
        }