Beispiel #1
0
        public static Dictionary <string, bool> CreateDictBasedOnAutomata(GeneNode automata)
        {
            Dictionary <string, bool> result = new Dictionary <string, bool>();

            if (automata == null || automata.Transitions == null || !automata.Transitions.Any())
            {
                return(null);
            }

            int i = 0;

            automata.Visit(l =>
            {
                var tr = BDDSolver.GetTransitions(l);

                if (tr == null)
                {
                    return;
                }

                tr
                .ForEach(
                    f =>
                {
                    var key   = Formater.FormatParameter(f.Key, i);
                    var value = f.Value.Value;

                    result[key] = value;
                });
                i++;
            });


            return(result);
        }
        public static AutomateObject CreateViewAutomata(GeneNode node)
        {
            var res = new AutomateObject();

            var nodes = new List <GeneNode>();

            node.Visit((g) => nodes.Add(g));

            var trans = new List <Edge>();


            node.Visit((g) =>
            {
                if (g.Transitions != null && g.Transitions.Any())
                {
                    g.Transitions.ForEach(f =>
                    {
                        trans.Add(new Edge
                        {
                            source = g.NodeName,
                            target = f.Node.NodeName,
                        });
                    });
                }
            });

            res.nodes = nodes
                        .Select(a => new Node()
            {
                id    = a.NodeName,
                label = FormatNodeLabel(a), size = 3
            }).ToList();

            res.edges =
                trans.Select(d => new Edge()
            {
                id     = d.source + "_" + d.target,
                source = d.source,
                target = d.target,
                color  = "#3300ff",
                type   = "arrow",
                label  = d.label    //+ " " + CreateLabel(d)
            })
                .ToList();

            return(res);
        }
Beispiel #3
0
        public void CreateSpecString(GeneNode geneNode, StringBuilder predicatesBuilder, StringBuilder observationBuilder, HashSet <string> alreadyTakenNames, ref int currentCondition)
        {
            HashSet <GeneNode>          nodesVisited = new HashSet <GeneNode>();
            Dictionary <string, string> Conditions   = new Dictionary <string, string>();
            var    z         = currentCondition;
            string OneName   = "";
            bool   stopVisit = false;

            geneNode.Visit(v =>
            {
                if (!nodesVisited.Contains(v) && v != null &&
                    v.CurrentCondition != null &&
                    v.CurrentCondition.Any() &&
                    !stopVisit)
                {
                    //$Conditions1 := { S1 = 0 and S2 = 1};

                    var conditionName = $"$Condition{z}";
                    var joinCondition = JoinCondition(v.CurrentCondition);

                    if (Conditions.ContainsKey(joinCondition))
                    {
                        conditionName = Conditions[joinCondition];
                    }
                    else
                    {
                        Conditions.Add(joinCondition, conditionName);
                    }


                    observationBuilder.AppendLine(
                        $"{conditionName} := {joinCondition}");

                    var connector = (v.Transitions == null || !v.Transitions.Any()) ? "" : " and ";

                    var name = CreateName(v.NodeName, alreadyTakenNames, out OneName);

                    predicatesBuilder.AppendLine($"{name} |= {conditionName} {connector}");

                    if (v.IsLoopFixedPoint())
                    {
                        predicatesBuilder.AppendLine($"fixpoint({name})");
                        stopVisit = true;
                    }

                    z++;

                    nodesVisited.Add(v);
                }
            });

            currentCondition = z;
            alreadyTakenNames.Add(OneName);
        }
Beispiel #4
0
        private static Expression CreateExpressionBasedOnAutomata(GeneNode automata)
        {
            Expression goal1 = null;

            if (automata == null || automata.Transitions == null || !automata.Transitions.Any())
            {
                return(null);
            }

            int i = 0;

            automata.Visit(l =>
            {
                var tr = GetTransitions(l);

                if (tr == null)
                {
                    return;
                }

                tr
                .ForEach(
                    f =>
                {
                    var primitiveApplication =
                        new Assignment(Formater.FormatParameter(f.Key, i), new BoolConstant(f.Value.Value));

                    if (goal1 == null)
                    {
                        goal1 = primitiveApplication;
                    }
                    else
                    {
                        goal1 = new Sequence(
                            goal1,
                            primitiveApplication);
                    }
                });
                i++;
            });


            logger.Info("Goal: " + goal1);
            return(goal1);
        }
Beispiel #5
0
        private static Expression SetGoalsBasedOnAutomata(GeneNode automata)
        {
            Expression goal1 = null;

            if (automata == null || automata.Transitions == null || !automata.Transitions.Any())
            {
                return(null);
            }

            int i = 0;

            automata.Visit(l =>
            {
                var tr = GetTransitions(l);

                if (tr == null)
                {
                    return;
                }

                tr
                .ForEach(
                    f =>
                {
                    var primitiveApplication =
                        BddHelper.SetBooleanValue(i, f.Value.Value, f.Key);

                    if (goal1 == null)
                    {
                        goal1 = primitiveApplication;
                    }
                    else
                    {
                        goal1 = new PrimitiveApplication(PrimitiveApplication.AND,
                                                         goal1,
                                                         primitiveApplication);
                    }
                });
                i++;
            });



            return(goal1);
        }