public void DeserializeSolvePartialProblems()
 {
     SolvePartialProblems d = new SolvePartialProblems();
     string xml = d.SerializeToXML();
     d = (SolvePartialProblems)xml.DeserializeXML();
     Assert.IsNotNull(d);
 }
        protected override string ReceivedDivideProblem(DivideProblem divideProblem)
        {
            /* Divide Problem is sent to TM to start the action of dividing the problem instance to smaller tasks.
             * TM is provided with information about the computational power of the cluster in terms of total number
             * of available threads. The same message is used to relay information for synchronizing info with Backup CS.
             */

            //Debug.Assert(false, "Unimplemented");

            //!!!!!!!!!!!!!!!!!!!
            ////we are not dividing yet - inserting everything into CommonData
            ////the same should be done in the ComputationalNode
            SolvePartialProblems solvePartialProblems = new SolvePartialProblems();
            solvePartialProblems.CommonData = divideProblem.Data;

            solvePartialProblems.Id = divideProblem.Id;
            solvePartialProblems.SolvingTimeoutSpecified = false;
            if(divideProblem.ProblemType != null)
                solvePartialProblems.ProblemType = divideProblem.ProblemType;

            CMSocket.Instance.SendMessage(this.Port, this.IP, solvePartialProblems.SerializeToXML(), this);

            return null;
        }
示例#3
0
 protected abstract string ReceivedSolvePartialProblems(SolvePartialProblems solvePartialProblems);
 public void SerializeSolvePartialProblems()
 {
     SolvePartialProblems d = new SolvePartialProblems();
     string xml = d.SerializeToXML();
     Assert.IsNotNull(xml);
 }
 protected override string ReceivedSolvePartialProblems(SolvePartialProblems solvePartialProblems)
 {
     Debug.Assert(false, "Should not be here");
     return null;
 }
示例#6
0
        protected override string ReceivedSolvePartialProblems(SolvePartialProblems solvePartialProblems)
        {
            /* Partial problems message is sent by the TM after dividing the problem into smaller partial problems.
             * The data in it consists of two parts – common for all partial problems and specific for the given task.
             * The same Partial Problems schema is used for the messages sent to be computed by the CN and to relay
             * information for synchronizing info with Backup CS.
             */

            this.serverQueues.ProblemsToSolve.Enqueue(solvePartialProblems);
            //if (this.BackupMode == true)
            //    return null;

            if (this.serverQueues.SolveRequests.Count > 0) {
                SolveRequest solveRequest = this.serverQueues.SolveRequests.Dequeue();
                DivideProblem divideProblem = new DivideProblem();
                divideProblem.Data = solveRequest.Data;
                divideProblem.Id = solveRequest.Id;
                Console.WriteLine("Sending DivideProblem as an ans to SolvePartiaProblems");
                return divideProblem.SerializeToXML();
            }

            //TM is not going to join the solutions
            //if (this.serverQueues.Solutions.Count > 0) {
            //    Solutions solutions = this.serverQueues.Solutions.Dequeue();
            //    return solutions.SerializeToXML();
            //}

            Console.WriteLine("Sending NoOp as an ans to SolvePartialProblems");
            return this.GenerateNoOperation().SerializeToXML();
        }
        protected override string ReceivedSolvePartialProblems(SolvePartialProblems solvePartialProblems)
        {
            ///// Hey here is the problem to solve! (undivided, everything is in CommonData)
            string problem = Utilities.Base64Decode(solvePartialProblems.CommonData);

            globalProblem = problem;
            //solvePartialProblems.Id;
            NodeWorker worker = new NodeWorker(solvePartialProblems.Id);
            worker.problemObject = ProblemLoader.loadnewExampleString(globalProblem);
            Workers.Add(worker);
            double sol = worker.calculateAlgorithm();
            Solutions solutions = new Solutions();
            solutions.Id = solvePartialProblems.Id;
            solutions.CommonData = Utilities.Base64Encode(sol.ToString());
            Console.WriteLine("How Long = " + this.Workers.First().HowLong);
            CMSocket.Instance.SendMessage(this.Port, this.IP, solutions.SerializeToXML(), this);
            return null;
        }