public void DeserializeDivideProblem()
 {
     DivideProblem d = new DivideProblem();
     string xml = d.SerializeToXML();
     d = (DivideProblem)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;
        }
Esempio n. 3
0
 protected abstract string ReceivedDivideProblem(DivideProblem divideProblem);
 public void SerializeDivideProblem()
 {
     DivideProblem d = new DivideProblem();
     string xml = d.SerializeToXML();
     Assert.IsNotNull(xml);
 }
Esempio n. 5
0
        protected override string ReceivedStatus(Status status)
        {
            Debug.Assert(this.serverQueues != null, "null server queue");
            Node node = this.RegisteredComponents.NodeWithID(status.Id);

            NoOperation noOperationResponse = this.GenerateNoOperation();
            if (!this.ensureNode(node)) {
                return noOperationResponse.SerializeToXML();
            }

            switch (node.NodeType) {
                case NodeType.TaskManager:
                    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 to TM");
                        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();
                    //}
                    break;
                case NodeType.ComputationalNode: //TODO: check!!
                    bool busy = false;
                    if (status.Threads != null) {
                        Console.WriteLine("Threads field not null");
                        foreach (StatusThreadsThread stt in status.Threads) {
                            if (stt.ProblemInstanceIdSpecified || stt.TaskIdSpecified) {
                                busy = true;
                                Console.WriteLine("Busy = true");
                            }
                        }
                    }
                    if (this.serverQueues.ProblemsToSolve.Count > 0 && !busy) {
                        Console.WriteLine("Busy = true");
                        SolvePartialProblems partialProblems = this.serverQueues.ProblemsToSolve.Dequeue();
                        Console.WriteLine("Sending PartialProblems to CN");
                        return partialProblems.SerializeToXML();
                    }
                    break;
                case NodeType.Server: {
                        foreach (BackupServerQueue bsq in this.backupServerQueues) {
                            if (bsq.backupServerId == status.Id) {
                                Console.WriteLine("Sending queued message to BackupCS");
                                if(bsq.messages.Count > 0)
                                    return bsq.messages.Dequeue();
                            }
                        }
                    }
                    break;
                default:
                    break;
            }

            Debug.Assert(node != null, "Received unregistered node status");
            if (node == null) {
                Console.WriteLine("Received unregistered node status");
                return noOperationResponse.SerializeToXML();
            }

            if (!this.BackupMode)
            Console.WriteLine("Sending NoOp");
            return noOperationResponse.SerializeToXML();
        }
Esempio n. 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();
        }
Esempio n. 7
0
        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(this.BackupMode == true, "ReceivedDivideProblem received to primary Server");

            //NoOperation noOperationResponse = this.GenerateNoOperation();
            return null; //noOperationResponse.SerializeToXML();
        }
 protected override string ReceivedDivideProblem(DivideProblem divideProblem)
 {
     Debug.Assert(false, "Should not be here");
     return null;
 }