Exemplo n.º 1
0
        private void ExtractDelayedState(State st, HashSet <DelayedState.Key> same)
        {
            if (st.Instructions == null)
            {
                return;
            }

            foreach (Cdn.Instruction instruction in st.Instructions)
            {
                InstructionCustomOperator op = instruction as InstructionCustomOperator;

                if (op == null || !(op.Operator is OperatorDelayed))
                {
                    continue;
                }

                if (Options.Instance.DelayTimeStep <= 0)
                {
                    throw new Exception("The network uses the `delayed' operator but no delay time step was specified (--delay-time-step)...");
                }

                double delay = ComputeDelayedDelay(st.Instructions, st.Expression, op);

                OperatorDelayed  opdel = (OperatorDelayed)op.Operator;
                DelayedState.Key key   = new DelayedState.Key(opdel, delay);

                if (!same.Add(key))
                {
                    d_delays.Add(op, delay);
                    continue;
                }

                double size;

                size = delay / Options.Instance.DelayTimeStep;

                if (size % 1 > double.Epsilon)
                {
                    throw new Exception(String.Format("Time delay `{0}' is not a multiple of the delay time step `{1}'",
                                                      delay, Options.Instance.DelayTimeStep));
                }

                d_delays.Add(op, delay);

                DelayedState s = new DelayedState(op, delay, opdel.Expression, Cdn.RawC.State.Flags.None);
                AddState(null, s);

                // Create a new expression for the initial value of this state
                AddInitialize(new DelayedState(op, delay, opdel.InitialValue, Cdn.RawC.State.Flags.Initialization));
                d_delayedStates.Add(s);

                // Recurse into state
                ExtractDelayedState(s, same);
            }
        }
Exemplo n.º 2
0
            public Key(OperatorDelayed delayed, double delay)
            {
                d_delayed = delayed;
                d_delay   = delay;

                var    n = Tree.Node.Create(null, d_delayed.Expression);
                string s = n.Serialize();

                if (d_delayed.InitialValue != null)
                {
                    s += ", " + Tree.Node.Create(null, d_delayed.InitialValue).Serialize();
                }

                d_hash = s.GetHashCode();
            }
Exemplo n.º 3
0
        /*
         * Delay operator instructions are translated to a simple lookup in
         * the statetable where they delayed expressions are stored.
         */
        protected virtual string TranslateDelayed(InstructionCustomOperator instruction, Context context)
        {
            OperatorDelayed delayed = (OperatorDelayed)instruction.Operator;
            double          delay;

            if (!Knowledge.Instance.LookupDelay(instruction, out delay))
            {
                throw new NotSupportedException("Unable to determine delay of delayed operator");
            }

            DataTable.DataItem item = context.Program.StateTable[new DelayedState.Key(delayed, delay)];

            return(String.Format("{0}[{1}]",
                                 context.This(context.Program.StateTable),
                                 item.AliasOrIndex));
        }