예제 #1
0
        protected override void Behave(IEnumerable <IAgent> agents)
        {
            FCurrentAgentCount.Sync();
            FMaxAgentCount.Sync();

            FStarveCount.Sync();
            FCloneCount.Sync();
            FRadius.Sync();


            FCloneOut.SliceCount = 0;
            var diff = FMaxAgentCount[0] - FCurrentAgentCount[0];

            var starve = FStarveCount[0];
            var clone  = FCloneCount[0];
            var radius = FRadius[0];

            foreach (dynamic agent in agents)
            {
                var closeBy = from peer in agents
                              where peer != agent
                              where VMath.Dist((Vector3D)peer["Position"].First, (Vector3D)agent["Position"].First) < radius
                              select peer;

                if (closeBy.Count() < starve)
                {
                    agent.Feed(0.005);

                    if (agent.Health < 0.1)
                    {
                        agent.Killed     = true;
                        agent.ReturnCode = ReturnCodeEnum.Failure;
                    }
                }

                if ((closeBy.Count() >= clone))
                {
                    if (agent.Health >= 0.9)
                    {
                        if (diff > 0)
                        {
                            agent.Burn(0.5);
                            FCloneOut.Add((Agent)agent.Clone());
                            diff--;
                        }
                    }
                }

                FCloneOut.Flush();
            }
        }
예제 #2
0
        public void Evaluate(int SpreadMax)
        {
            FAgents.SliceCount = 0;
            SpreadMax          = FCount.CombineWith(FInsert);
            for (int i = 0; i < SpreadMax; i++)
            {
                if (FInsert[i])
                {
                    for (int j = 0; j < FCount[i]; j++)
                    {
                        var a = new Agent();


                        FAgents.Add(a);
                    }
                }
            }
            FAgents.Flush();
        }
예제 #3
0
#pragma warning restore

        public override void Evaluate(int SpreadMax)
        {
            if (FInput.IsAnyInvalid())
            {
                SpreadMax = 0;
                FOutput.FlushNil();
                FSuccess.FlushBool(false);
                FMatch.FlushNil();

                return;
            }
            else
            {
                SpreadMax = FInput.SliceCount;
            }

            var update = false;

            if (FTopic.IsChanged || FExtendedMode.IsChanged || FUseFields.IsChanged || Parser == null)
            {
                if (Parser == null)
                {
                    Parser = new Dictionary <string, IEnumerable <FormularFieldDescriptor> >();
                }
                else
                {
                    Parser.Clear();
                }

                for (int i = 0; i < FTopic.SliceCount; i++)
                {
                    var fields = (
                        from f in FUseFields[i]
                        select Formular[f.Name]
                        ).ToList();
                    Parser[FTopic[i]] = fields;
                }
                update = true;
            }

            if (!update && !FInput.IsChanged)
            {
                return;
            }

            FSuccess.SliceCount = SpreadMax;
            FOutput.SliceCount  = 0;
            FMatch.SliceCount   = 0;

            for (int i = 0; i < SpreadMax; i++)
            {
                var stream = FInput[i];
                stream.Position = 0;

                var address = OSCExtensions.PeekAddress(stream);
                stream.Position = 0;

                var isMatch = (
                    from a in FTopic
                    where address == a
                    select true
                    ).Any();

                Message message = isMatch? OSCExtensions.FromOSC(stream, Parser, FExtendedMode[0]) : null;

                if (message != null)
                {
                    FOutput.Add(message);
                    FSuccess[i] = true;
                    FMatch.Add(FTopic.IndexOf(address));
                }
                else
                {
                    FSuccess[i] = false;
                }
            }
            FOutput.Flush();
            FSuccess.Flush();
            FMatch.Flush();
        }
예제 #4
0
        public void Evaluate(int SpreadMax)
        {
            if (FSocket.SliceCount == 0 || (FSocket.SliceCount == 1 && FSocket[0] == null))
            {
                FOutput.SliceCount = 0;
                FOutput.Flush();

                FSocketBin.SliceCount = 1;
                FSocketBin[0]         = 0;

                FOnData[0] = false;
                return;
            }

            FSocketBin.SliceCount = SpreadMax;
            FOutput.SliceCount    = 0;


            FMeta.SliceCount        = 0;
            FMetaBinSize.SliceCount = 0;
            var doMeta = FMeta.IsConnected || FMetaBinSize.IsConnected;

            for (int socketid = 0; socketid < SpreadMax; socketid++)
            {
                var socket = (NetMQSocket)FSocket[socketid];
                if (socket == null)
                {
                    FOnData[socketid]    = false;
                    FSocketBin[socketid] = 0;
                    continue;
                }

                bool more = socket.HasIn;
                var  sBin = 0;
                FOnData[socketid] = more;

                while (more)
                {
                    try
                    {
                        var msg = socket.ReceiveMultipartMessage(2); // expect 2, but read all, nonetheless

                        if (doMeta)
                        {
                            var mBin = 0;
                            for (int i = 0; i < msg.FrameCount - 2; i++)
                            {
                                var stream = new MemoryStream();
                                var f      = msg[i];

                                stream.Write(f.Buffer, 0, f.BufferSize);

                                FMeta.Add(stream);
                                mBin++;
                            }
                            FMetaBinSize.Add(mBin);
                        }

                        var payload = System.Text.Encoding.UTF8.GetString(msg.Last.ToByteArray());
                        var result  = JsonConvert.DeserializeObject(payload);

                        if (result is JObject)
                        {
                            FOutput.Add((result as JObject).ToObject <Message>());
                            sBin++;
                        }
                    }
                    catch (Exception e)
                    {
                        FLogger.Log(LogType.Warning, "vvvv-ZeroMQ: Received Data is not a valid Message. " + e);
                    }
                    more = socket.HasIn;
                }

                FSocketBin[socketid] = sBin;
            }

            if (FOutput.SliceCount == 0)
            {
                FOnData[0] = false;
            }
            else
            {
                FOnData[0] = true;
            }

            FOutput.Flush();
            FMeta.Flush();
            FMetaBinSize.Flush();
        }