예제 #1
0
        public override void Evaluate(int SpreadMax)
        {
            SpreadMax = 0;
            if (!FSet[0])
            {
                FOutput.SliceCount = 0;
                FOutput.Flush();

                return;
            }

            foreach (var name in Pins.Keys)
            {
                var pin = ToISpread(Pins[name]);
                pin.Sync();
                SpreadMax = Math.Max(pin.SliceCount, SpreadMax);
            }

            FOutput.SliceCount = SpreadMax;
            for (var i = 0; i < SpreadMax; i++)
            {
                var message = new Message {
                    Address = FAddress[i]
                };

                foreach (var name in Pins.Keys)
                {
                    message.AssignFrom(name, GetISpreadData(Pins[name], i));
                }

                FOutput[i] = message;
            }

            FOutput.Flush();
        }
예제 #2
0
        public virtual void OnImportsSatisfied()
        {
            link = new BehaviorLink(FAgents);
            FOutput.SliceCount = 1;
            FOutput[0]         = link;
            FOutput.Flush();

            FOutput.Disconnected += disconnect;
//            FMainLoop.OnPrepareGraph += init;
            FMainLoop.OnResetCache += init;
        }
예제 #3
0
        public override void OnImportsSatisfied()
        {
            base.OnImportsSatisfied();
            FInput.Connected += connect;

            link = new BehaviorLink(FAgents);
            FOutput.SliceCount = 1;
            FOutput[0]         = link;
            FOutput.Flush();

            FOutput.Disconnected     += disconnect;
            FMainLoop.OnPrepareGraph += init;
        }
예제 #4
0
            public override void Evaluate(int SpreadMax)
            {
                SpreadMax = FInput.SliceCount;

                if (!FInput.IsChanged)
                {
                    //				FLogger.Log(LogType.Debug, "skip set");
                    return;
                }


                if (FInput.SliceCount == 0 || FInput[0] == null)
                {
                    FOutput.SliceCount = 0;
                    return;
                }

                for (int i = 0; i < SpreadMax; i++)
                {
                    Message message = FInput[i];
                    foreach (string name in FPins.Keys)
                    {
                        var pin = (IEnumerable)ToISpread(FPins[name])[i];
                        message.AssignFrom(name, pin);
                    }
                }

                FOutput.AssignFrom(FInput);
                FOutput.Flush();
            }
예제 #5
0
        public override void Evaluate(int SpreadMax)
        {
            if (FInput.IsAnyInvalid())
            {
                FOutput.FlushNil();
                return;
            }

            bool doFlush = false;

            // is any Update slice checked?
            var anyUpdate = FUpdate.Any();

            // Flush upstream changes through the plugin
            if (FInput.IsChanged)
            {
                FOutput.SliceCount = 0;
                FOutput.AssignFrom(FInput); // push change from upstream if valid
                doFlush = true;
            }
            else if (!anyUpdate)
            {
                return;                                                               // if no update and no change, no need to flush!
            }
            bool newData = FPins.Any(pinName => pinName.Value.ToISpread().IsChanged); // changed pins

            newData |= !FAutoSense[0];                                                // assume newData, if AutoSense is off.

            if (anyUpdate && newData)
            {
                int messageIndex = 0;
                foreach (var message in FInput)
                {
                    if (FUpdate[messageIndex])
                    {
                        doFlush |= CopyFromPins(message, messageIndex, FAutoSense[0]);
                    }

                    messageIndex++;
                }
            }

            if (doFlush)
            {
                FOutput.Flush();
            }


            if (RemovePinsFirst)
            {
                RetryConfig();
            }
        }
예제 #6
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();
            }
        }
예제 #7
0
        public override void Evaluate(int SpreadMax)
        {
            TypeUpdate();

            SpreadMax = 0;
            if (!FSet[0])
            {
                //				FLogger.Log(LogType.Debug, "skip join");
                FOutput.SliceCount = 0;
                FOutput.Flush();
                return;
            }

            foreach (string name in FPins.Keys)
            {
                var pin = ToISpread(FPins[name]);
                pin.Sync();
                SpreadMax = Math.Max(pin.SliceCount, SpreadMax);
            }


            FOutput.SliceCount = SpreadMax;
            for (int i = 0; i < SpreadMax; i++)
            {
                Message message = new Message();

                message.Address = FAddress[i];
                foreach (string name in FPins.Keys)
                {
                    message.AssignFrom(name, (IEnumerable)ToISpread(FPins[name])[i]);
                }
                FOutput[i] = message;

                // FLogger.Log(LogType.Debug, "== Message "+i+" == \n" + message.ToString());
                //	foreach (string name in message.GetDynamicMemberNames()) FLogger.Log(LogType.Debug, message[name].GetType()+" "+ name);
            }
            FOutput.Flush();
        }
예제 #8
0
        protected virtual bool UpKeep(bool force = false)
        {
            if (!force && !Keep.IsChanged)
            {
                if (!Keep.QuickMode && FChangeOut.SliceCount != 0)
                {
                    FChangeOut.SliceCount = 0;
                    FChangeOut.Flush();
                    FChangeIndexOut.SliceCount = 0;
                    FChangeIndexOut.Flush();
                }

                return(false);
            }

            if (Keep.QuickMode)
            {
                Keep.Sync();
            }
            else
            {
                IEnumerable <int> indexes;
                var changes = Keep.Sync(out indexes);

                FChangeIndexOut.SliceCount = 0;
                FChangeIndexOut.AssignFrom(indexes);
                FChangeIndexOut.Flush();

                FChangeOut.SliceCount = 0;
                FChangeOut.AssignFrom(changes);
                FChangeOut.Flush();
            }

            FOutput.FlushResult(Keep);
            FCountOut.FlushInt(Keep.Count);

            return(true);
        }
예제 #9
0
        public void Evaluate(int SpreadMax)
        {
            if (IsFirstFrame || FInit[0])
            {
                FOutput.AssignFrom(FDefault);
                IsFirstFrame = false;
            }
            else
            {
                FOutput.AssignFrom(LastFrameAgents);
            }

            FOutput.Flush();
        }
예제 #10
0
        /// <summary>
        /// Flush all output pins.
        /// </summary>
        protected void FinishEvaluation()
        {
            FReturnCode.SliceCount = FAgents.Count;
            int i = 0;

            foreach (Agent agent in FAgents)
            {
                FReturnCode[i] = agent.ReturnCode.ToString();
                i++;
            }
            FReturnCode.Flush();

            FOutput.SliceCount = Math.Max(1, FAgents.Count);
            FOutput[0]         = link;
            FOutput.Flush();
        }
예제 #11
0
        #pragma warning restore

        public void Evaluate(int SpreadMax)
        {
            SpreadMax = FInput.SliceCount;

            if (FInput.SliceCount == 0 || FInput[0] == null)
            {
                FOutput.SliceCount = 0;
                return;
            }

            FOutput.SliceCount = SpreadMax;


            for (int i = 0; i < SpreadMax; i++)
            {
                Message message = FInput[i];

                if (Update[i])
                {
                    for (int keyCount = 0; keyCount < FKey.SliceCount; keyCount++)
                    {
                        SpreadList attr = message[FKey[keyCount]];
                        if (attr != null)
                        {
                            var typeOld = attr[0].GetType();
                            var typeNew = FValue[keyCount][0].GetType();
                            if (!(typeOld == typeNew))
                            {
                                attr.Clear();
                                for (int j = 0; j < FValue[i].SliceCount; j++)
                                {
                                    attr.Add(Convert.ChangeType(FValue[keyCount][j], typeOld));
                                }
                            }
                            else
                            {
                                attr.Clear();
                                attr.AssignFrom(FValue[i]);
                            }
                        }
                    }
                }
                FOutput[i] = message;
            }

            FOutput.Flush();
        }
예제 #12
0
        public void Evaluate(int SpreadMax)
        {
            SpreadMax = FInput.SliceCount;

            if (FInput.IsAnyInvalid())
            {
                SpreadMax = 0;
            }
            FKill.Sync();

            for (int i = 0; i < SpreadMax; i++)
            {
                var agent = FInput[i];
                agent.Killed = FKill[i];
            }
            FOutput.AssignFrom(FInput);
            FOutput.Flush();
        }
예제 #13
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();
        }
예제 #14
0
        public void Evaluate(int SpreadMax)
        {
            SpreadMax = FInput.SliceCount;

            if (FInput.IsAnyInvalid())
            {
                SpreadMax = 0;
            }

            FHistoryCount.Sync();

            FTransform.SliceCount = SpreadMax;
            FPosition.SliceCount  = SpreadMax;
            FVelocity.SliceCount  = SpreadMax;
            FForceSum.SliceCount  = SpreadMax;

            for (int i = 0; i < SpreadMax; i++)
            {
                IAgent agent = FInput[i];
                agent["HistoryCount"].First = FHistoryCount[i];

                FPosition[i].AssignFrom(agent.PositionHistory());
                FVelocity[i].AssignFrom(agent.VelocityHistory());
                FForceSum[i].AssignFrom(agent.ForceSumHistory());

                var rot       = VMath.PolarVVVV(agent.VelocityHistory(0));
                var transform = VMath.RotateY(VMath.Pi / 2) * VMath.Rotate(rot) * VMath.Translate(agent.PositionHistory(0));


                FTransform[i] = transform;
            }
            FOutput.AssignFrom(FInput);


            FTransform.Flush();
            FPosition.Flush();
            FVelocity.Flush();
            FForceSum.Flush();

            FOutput.Flush();
        }
예제 #15
0
        public void Evaluate(int SpreadMax)
        {
            SpreadMax        = FInput.SliceCount;
            FLink.SliceCount = 1;
            Link.RemotePin   = FInput;
            FLink[0]         = Link;

            if (FClone[0])
            {
                FOutput.SliceCount = SpreadMax;
                for (int i = 0; i < SpreadMax; i++)
                {
                    FOutput[i] = (T)FInput[i].Clone();
                }
            }
            else
            {
                FOutput.AssignFrom(FInput);
            }

            FOutput.Flush();
        }
예제 #16
0
            public override void Evaluate(int SpreadMax)
            {
                SpreadMax = FInput.SliceCount;
                bool isChanged = false;

                foreach (string name in Pins.Keys)
                {
                    var pin = ToIDiffSpread(Pins[name]);
                    if (pin.IsChanged)
                    {
                        isChanged = true;
                    }
                }

                if (!isChanged && !FInput.IsChanged)
                {
                    //				FLogger.Log(LogType.Debug, "skip set");
                    return;
                }


                if (FInput.SliceCount == 0 || FInput[0] == null)
                {
                    FOutput.SliceCount = 0;
                    return;
                }
                for (int i = 0; i < SpreadMax; i++)
                {
                    Message message = FInput[i];
                    foreach (string name in Pins.Keys)
                    {
                        var pin = GetISpreadData(Pins[name], i);
                        message.AssignFrom(name, pin);
                    }
                }
                FOutput.AssignFrom(FInput);
                FOutput.Flush();
            }
예제 #17
0
        public void Evaluate(int SpreadMax)
        {
            FKilled.SliceCount = 0;
            if (FClear[0])
            {
                FKilled.AssignFrom(FAgents);
                FAgents.Clear();
            }

            if (FDeleteNow[0])
            {
                var del = FDeleteIndex.ToList();

                int size = FAgents.Count();

                for (int i = 0; i < del.Count; i++)
                {
                    del[i] = VMath.Zmod(del[i], size);
                }
                del.Sort();

                for (int i = 0; i < del.Count; i++)
                {
//                    if (FAgents.Count > i)
                    FAgents.RemoveAt(del[i] - i);
                }
            }

            var killed = from a in FAgents
                         where a.Killed
                         select a;

            FKilled.AddRange(killed);
            FAgents.RemoveAll(IsKilled);

            if (!FAdd.IsAnyInvalid())
            {
                var count = FAgents.Count;
                foreach (var agent in FAdd)
                {
                    if (agent != null && !Limited(count))
                    {
                        FAgents.Add(agent);
                        count++;
                    }
                }
                FAgents.Sort();
            }

            FTick.Sync();
            if (!FInput.IsAnyInvalid() && FInput.PluginIO.IsConnected && FTick[0])
            {
                FInput[0].Agents.Clear();
                FInput[0].Agents.AddRange(FAgents);

                foreach (var agent in FInput[0].Agents)
                {
                    agent.ReturnCode = ReturnCodeEnum.Success;
                }

                FInput.Sync();

                FOutput.SliceCount = 0;
                FOutput.AssignFrom(FInput[0].Agents);
            }
            else
            {
                FOutput.SliceCount = 0;
                FOutput.AssignFrom(FAgents);
            }
            FOutput.Flush();
            FKilled.Flush();
        }
예제 #18
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();
        }
예제 #19
0
        public void Evaluate(int SpreadMax)
        {
            SpreadMax = FInput.IsAnyInvalid() ? 0 : FInput.SliceCount;

            if (SpreadMax == 0)
            {
                if (FOutput.SliceCount != 0)
                {
                    FOutput.FlushNil();
                    FTimeStamp.FlushNil();
                    FTopic.FlushNil();
                    FConfigOut.FlushNil();
                }
                return;
            }

            if (!FInput.IsChanged)
            {
                return;
            }

            FOutput.SliceCount            =
                FTopic.SliceCount         =
                    FConfigOut.SliceCount = SpreadMax;

            var timeConnected = FTimeStamp.IsConnected; // treat the time pin a little different, because it can be quite slow. time type is a struct that gets copied within the pin

            FTimeStamp.SliceCount = timeConnected? SpreadMax : 0;

            for (int i = 0; i < SpreadMax; i++)
            {
                Message m = FInput[i];
                FOutput[i] = m.ToString();
                FTopic[i]  = m.Topic;
                if (timeConnected)
                {
                    FTimeStamp[i] = m.TimeStamp;
                }
                ;

                FConfigOut[i] = FInput[i].Formular.Configuration;

                if (FPrint[i])
                {
                    //StringBuilder sb = new StringBuilder();
                    //sb.AppendLine("\t === \t ["+i+"]\t ===");
                    //sb.AppendLine(FInput[i].ToString());
                    //sb.AppendLine();
                    //FLogger.Log(LogType.Message, sb.ToString());

                    FLogger.Log(LogType.Message, "\t === \t [" + i + "]\t ===");
                    FLogger.Log(LogType.Message, JsonConvert.SerializeObject(FInput[i], FJsonSettings));
                }
            }

            if (timeConnected)
            {
                FTimeStamp.Flush();
            }

            FTopic.Flush();
            FOutput.Flush();
            FConfigOut.Flush();
        }
예제 #20
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();
        }
예제 #21
0
        public override void Evaluate(int SpreadMax)
        {
            InitDX11Graph();

            bool warnPinSafety = false;

            if (RemovePinsFirst)
            {
                warnPinSafety = RetryConfig();
            }

            if (FInput.IsAnyInvalid())
            {
                FOutput.FlushNil();

                if (warnPinSafety)
                {
                    throw new PinConnectionException("Manually remove unneeded links first! [Edit]. ID = [" + PluginHost.GetNodePath(false) + "]");
                }
                return;
            }

            bool doFlush = false;

            // is any Update slice checked?
            var anyUpdate = FUpdate.Any();

            // Flush upstream changes through the plugin
            if (FInput.IsChanged)
            {
                FOutput.SliceCount = 0;
                FOutput.AssignFrom(FInput); // push change from upstream if valid
                doFlush = true;
            }
            else if (!anyUpdate)
            {
                if (warnPinSafety)
                {
                    throw new PinConnectionException("Manually remove unneeded links first! [Edit]. ID = [" + PluginHost.GetNodePath(false) + "]");
                }

                return; // if no update and no change, no need to flush!
            }

            bool newData = FPins.Any(pinName => pinName.Value.ToISpread().IsChanged); // changed pins

            newData |= FForce[0];                                                     // assume newData, if AutoSense is off.

            if (anyUpdate && newData)
            {
                int messageIndex = 0;
                foreach (var message in FInput)
                {
                    if (FUpdate[messageIndex])
                    {
                        doFlush |= CopyFromPins(message, messageIndex, !FForce[0]);
                    }

                    messageIndex++;
                }
            }

            if (doFlush)
            {
                FOutput.Flush();
            }

            if (warnPinSafety)
            {
                throw new PinConnectionException("Manually remove unneeded links first! [Edit]. ID = [" + PluginHost.GetNodePath(false) + "]");
            }
        }