Exemple #1
0
 public EvalContext(SAN san, StatesSet stateSet, State state)
 {
     this.san = san;
     this.currStateSet = stateSet;
     this.state = state;
 }
Exemple #2
0
 public State(State other)
 {
     this.states = other.states;
     this.cells = (int[]) other.cells.Clone();
 }
Exemple #3
0
        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);
        }
Exemple #4
0
 public string StateToString(State state)
 {
     StringBuilder builder = new StringBuilder();
     for (int i = 0; i < AutonomusCount; i++)
     {
         builder.Append(autList.ElementAt(i).NodeAt(state[i]));
     }
     return builder.ToString();
 }
Exemple #5
0
 public float Eval(SAN san, StatesSet stateSet, State state)
 {
     if (exprTree != null)
     {
         return exprTree.Eval(new EvalContext(san, stateSet, state));
     }
     else
     {
         return 1.0f;
     }
 }