예제 #1
0
파일: ExprTree.cs 프로젝트: otaviog/Fruki
 public EvalContext(SAN san, StatesSet stateSet, State state)
 {
     this.san = san;
     this.currStateSet = stateSet;
     this.state = state;
 }
예제 #2
0
파일: States.cs 프로젝트: otaviog/Fruki
 public State(State other)
 {
     this.states = other.states;
     this.cells = (int[]) other.cells.Clone();
 }
예제 #3
0
파일: SAN.cs 프로젝트: otaviog/Fruki
        public Tuple<int, int> GenerateDotVis(System.IO.TextWriter writer)
        {
            int transitionCount = 0;
            writer.WriteLine("digraph Markov {");

            StatesSet stateset = new StatesSet(autonomus);
            foreach (State state in stateset)
            {
                string sMarkovCurrState = stateset.StateToString(state);

                Dictionary<Event, LinkedList<PendingEdge>> synPendingEvents =
                    new Dictionary<Event, LinkedList<PendingEdge>>();

                for (int cntAut = 0; cntAut < stateset.AutonomusCount; cntAut++)
                {
                    Autonomus aut = autonomus.ElementAt(cntAut);
                    int nodeName = aut.NodeAt(state[cntAut]);
                    LinkedList<Edge> edges = aut.GetEdges(nodeName);

                    foreach (Edge edge in edges)
                    {
                        Event ev = null;
                        events.TryGetValue(edge.Event, out ev);

                        if (ev != null)
                        {
                            int idxToNodeName = aut.NodeNameIndex(edge.DestName);
                            float tax = edge.Tax * ev.Eval(this, stateset, state);
                            if (tax > 0.0f)
                            {
                                if (ev.Type == Event.EventType.LOC)
                                {
                                    State markovToState = new State(state);
                                    markovToState[cntAut] = idxToNodeName;

                                    PrintRelation(writer, sMarkovCurrState, stateset.StateToString(markovToState), tax);
                                    ++transitionCount;
                                }
                                else
                                {
                                    LinkedList<PendingEdge> penEvents;
                                    PendingEdge pendingEvent = new PendingEdge(cntAut, idxToNodeName);

                                    if (synPendingEvents.TryGetValue(ev, out penEvents))
                                    {
                                        penEvents.AddLast(pendingEvent);
                                    }
                                    else
                                    {
                                        penEvents = new LinkedList<PendingEdge>();
                                        penEvents.AddLast(pendingEvent);
                                        synPendingEvents[ev] = penEvents;
                                    }
                                }
                            }
                        } //  if (ev != null)
                        else
                        {
                            System.Console.WriteLine("Warnning: edge with direction " + edge.DestName + " has no event " + edge.Event);
                        }

                    } // foreach (Edge edge in edges)
                } //  for (int j = 0; j < stateset.Count; j++)

                foreach (KeyValuePair<Event, LinkedList<PendingEdge>> pending in synPendingEvents)
                {
                    Event ev = pending.Key;
                    LinkedList<PendingEdge> penEdges = pending.Value;

                    if ( penEdges.Count > 1 )
                    {
                        State toMarkovState = new State(state);
                        foreach (PendingEdge pedge in penEdges)
                        {
                            toMarkovState[pedge.AutonomusIdx] = pedge.DestNodeIdx;
                        }

                        float tax = ev.Eval(this, stateset, state);
                        if (tax > 0.0f)
                        {
                            PrintRelation(writer, sMarkovCurrState, stateset.StateToString(toMarkovState), tax);
                            ++transitionCount;
                        }
                    }
                }
            }

            writer.WriteLine("}");

            return new Tuple<int, int>(stateset.MaxStates, transitionCount);
        }
예제 #4
0
파일: States.cs 프로젝트: otaviog/Fruki
 public State(StatesSet states)
 {
     this.states = states;
     cells = new int[states.AutonomusCount];
 }
예제 #5
0
파일: Event.cs 프로젝트: otaviog/Fruki
 public float Eval(SAN san, StatesSet stateSet, State state)
 {
     if (exprTree != null)
     {
         return exprTree.Eval(new EvalContext(san, stateSet, state));
     }
     else
     {
         return 1.0f;
     }
 }