Beispiel #1
0
            public void Bind(long depTime)
            {
                long curTime = depTime;
                Tn   emitter = _a.Source[Segments[0].Inst];

                for (int i = 0; i < Segments.Length; i++)
                {
                    Tp   pipe = Segments[i].Realize(_a);
                    Tn   tmpEmitter;
                    long tmpDepTime;
                    if (_a.IsPipeBound(pipe, curTime, out tmpEmitter, out tmpDepTime))
                    {
                        Debug.Assert(object.Equals(emitter, tmpEmitter));
                        Debug.Assert(depTime == tmpDepTime);
                    }
                    else
                    {
                        _a.BindPipe(pipe, curTime, emitter, depTime);
                    }
                    curTime += _a.Delay[pipe];
                }
            }
Beispiel #2
0
        private IEnumerable <Path> FindPaths(long depTime, Tn source, Tn target)
        {
            var s      = new Stack <Tuple <Tp, long> >();
            var parent = new Dictionary <Tp, Tp>();

            foreach (Tp pipe in _a.Succs[source])
            {
                long delay = _a.Delay[pipe];
                if (delay == 0 && !object.Equals(_a.Sink[pipe], target))
                {
                    continue;
                }

                Tn   emitter;
                long emitTime;
                if (_a.IsPipeBound(pipe, depTime, out emitter, out emitTime) &&
                    !(emitTime == depTime && object.Equals(emitter, source)))
                {
                    continue;
                }

                s.Push(Tuple.Create(pipe, depTime + delay));
            }
            while (s.Any())
            {
                var  tup     = s.Pop();
                Tp   curPipe = tup.Item1;
                long curTime = tup.Item2;
                Tn   cur     = _a.Sink[curPipe];
                if (object.Equals(cur, target))
                {
                    var pipes = new Stack <Pipe>();
                    Tp  curp  = curPipe;
                    do
                    {
                        pipes.Push((RealPipe)curp);
                        if (object.Equals(_a.Source[curp], source))
                        {
                            break;
                        }
                        else
                        {
                            curp = parent[curp];
                        }
                    } while (true);
                    yield return(new Path(_a, pipes.ToArray()));
                }
                else if (!_a.IsEndpoint[cur])
                {
                    foreach (Tp pipe in _a.Succs[cur])
                    {
                        Tn   succ    = _a.Sink[pipe];
                        long succdly = _a.Delay[pipe];
                        if (succdly == 0 && !object.Equals(succ, target))
                        {
                            continue;
                        }

                        Tn   emitter;
                        long emitTime;
                        if (_a.IsPipeBound(pipe, curTime, out emitter, out emitTime) &&
                            !(emitTime == depTime && object.Equals(emitter, source)))
                        {
                            continue;
                        }

                        parent[pipe] = curPipe;
                        s.Push(Tuple.Create(pipe, curTime + succdly));
                    }
                }
            }
        }