コード例 #1
0
ファイル: MasterAgent.cs プロジェクト: drobo3233/MASMA
        private void SendMessage(StandardMessage standardMessage, string agentName, bool isLeft)
        {
            int             middle         = (standardMessage.Left + standardMessage.Right) / 2;
            StandardMessage currentMessage = new StandardMessage
            {
                Action = Actions.Sort,
                Left   = isLeft ? standardMessage.Left : middle + 1,
                Right  = isLeft ? middle : standardMessage.Right,
                SourceToDestination = !standardMessage.SourceToDestination
            };

            if (
                isLeft ?
                (middle - standardMessage.Left) > Utils.Threshold :
                (standardMessage.Right - middle - 1) > Utils.Threshold
                )
            {
                _calls.Push(currentMessage);
            }
            else
            {
                _expectedMerge++;
            }

            Send(agentName, currentMessage.ToString());
        }
コード例 #2
0
        public static void Display(StandardMessage messageName)
        {
            if (messageName == StandardMessage.NoMessage)
            {
                return;
            }
            var msg = typeof(StandardMessages).GetProperty(messageName.ToString()).GetValue(null);

            Console.WriteLine(msg);
        }
コード例 #3
0
ファイル: WorkerAgent.cs プロジェクト: drobo3233/MASMA
        public override void Act(ActressMas.Message message)
        {
            var standardMessage = new StandardMessage(message.Content);

            switch (standardMessage.Action)
            {
            case Actions.Sort:

                if (standardMessage.Right == standardMessage.Left)
                {
                    if (standardMessage.SourceToDestination)
                    {
                        Utils.Destination[standardMessage.Left] = Utils.Source[standardMessage.Left];
                    }

                    SendMergeMessage();
                }
                else if ((standardMessage.Right - standardMessage.Left) <= Utils.Threshold)
                {
                    Array.Sort(Utils.Source, standardMessage.Left,
                               standardMessage.Right - standardMessage.Left + 1);

                    if (standardMessage.SourceToDestination)
                    {
                        for (int i = standardMessage.Left; i <= standardMessage.Right; i++)
                        {
                            Utils.Destination[i] = Utils.Source[i];
                        }
                    }

                    SendMergeMessage();
                }
                else
                {
                    standardMessage.Action = Actions.Split;
                    Send(Agents.MasterAgent, standardMessage.ToString());
                }

                break;
            }
        }