Exemplo n.º 1
0
        public override Process ClearConstant(Dictionary<string, Expression> constMapping)
        {
            Expression[] newArgs = new Expression[Args.Length];
            for (int i = 0; i < Args.Length; i++)
            {
                Expression arg = Args[i].ClearConstant(constMapping);

                if (!arg.HasVar)
                    newArgs[i] = EvaluatorDenotational.Evaluate(arg, null);
                else
                    newArgs[i] = arg;
            }

            DefinitionRef newRef = new DefinitionRef(Name, newArgs);

            //this is a special cases happened in the middle of parsing, where the current Def is not initialized in the parser.
            //so need to put the newRef into the def list to initialize the Def once the parsing is done.
            if (Def == null)
            {
                //TreeWalker.dlist.Add(newRef);
                //TreeWalker.dtokens.Add(null);
            }
            else
            {
                newRef.Def = Def;
            }

            return newRef;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Check whethere the goal can be reachable from the initial state of automataBDD
        /// [ REFS: traces, DEREFS: ]
        /// </summary>
        /// <param name="automataBDD"></param>
        /// <param name="goal"></param>
        /// <param name="model"></param>
        public void MC(AutomataBDD automataBDD, Expression goal, Model model)
        {
            //Clear the old data
            this.traces.Clear();

            ExpressionBDDEncoding goalBddEncoding = goal.TranslateBoolExpToBDD(model);

            ExpressionBDDEncoding initEncoding = automataBDD.initExpression.TranslateBoolExpToBDD(model);
            if (initEncoding.GuardDDs.Count == 0)
            {
                VerificationOutput.VerificationResult = VerificationResultType.INVALID;
            }
            else
            {
                CUDDNode initDD = CUDD.Function.Or(initEncoding.GuardDDs);
                CUDDNode goalDD = CUDD.Function.Or(goalBddEncoding.GuardDDs);

                CUDD.Ref(automataBDD.transitionBDD);
                List<CUDDNode> noEventTrans = CUDD.Abstract.ThereExists(automataBDD.transitionBDD, model.GetAllEventVars());

                bool reachable = model.Path(initDD, goalDD, noEventTrans, traces, SelectedEngineName, VerificationOutput.GenerateCounterExample);
                CUDD.Deref(noEventTrans);

                //
                CUDD.Deref(initDD, goalDD);

                VerificationOutput.VerificationResult = (reachable) ? VerificationResultType.VALID : VerificationResultType.INVALID;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tick transition if done is false, don't need to add unchanged condition of other local variables.
        /// They will be updated after the event becomes true
        /// use the tick transition of P1 if done is true
        /// </summary>
        /// <param name="P1"></param>
        /// <param name="model"></param>
        /// <param name="result"></param>
        private static void EventPrefixEncodeTick(Expression guardOfTick, AutomataBDD P1, Model model, AutomataBDD result)
        {
            Expression guard;
            List<CUDDNode> guardDD;

            //1. !done and guardOfTick and event = tick and !done'
            if (!(guardOfTick is BoolConstant && !(guardOfTick as BoolConstant).Value))
            {
                guard = Expression.AND(
                                                            Expression.EQ(
                                                                                     new Variable(result.newLocalVarName),
                                                                                     new IntConstant(0)),
                                                            Expression.AND(
                                                                                     guardOfTick,
                                                                                     new PrimitiveApplication(
                                                                                         PrimitiveApplication.AND,
                                                                                         AutomataBDD.
                                                                                             GetTerminateTransExpression
                                                                                             (),
                                                                                         new Assignment(
                                                                                             result.newLocalVarName,
                                                                                             new IntConstant(0)))));

                guardDD = guard.TranslateBoolExpToBDD(model).GuardDDs;
                guardDD = model.AddVarUnchangedConstraint(guardDD, model.GlobalVarIndex);
                result.Ticks.AddRange(guardDD);
            }

            //2. done and p1.Tick and done'
            guard = Expression.AND(Expression.EQ(new Variable(result.newLocalVarName), new IntConstant(1)),
                        new Assignment(result.newLocalVarName, new IntConstant(0)));
            guardDD = guard.TranslateBoolExpToBDD(model).GuardDDs;
            guardDD = CUDD.Function.And(guardDD, P1.Ticks);
            result.Ticks.AddRange(guardDD);
        }
Exemplo n.º 4
0
        public IndexInterleaveAbstract(Process processBase, Expression range)
        {
            Processes = new List<Process>();
            Processes.Add(processBase);

            RangeExpression = range;
        }
Exemplo n.º 5
0
        private static List <CUDDNode> IsExistPath(Expression goal1, BDDEncoder encoder,
                                                   List <CUDDNode> path,
                                                   CUDDNode initDD,
                                                   AutomataBDD systemBDD,
                                                   List <string> letters,
                                                   ref bool reach1)
        {
            CUDDNode goal1DD;

            goal1DD = CUDD.Function.Or(goal1.TranslateBoolExpToBDD(encoder.model).GuardDDs);

            path = new List <CUDDNode>();

            reach1 = encoder.model.PathForward(initDD, goal1DD, new List <List <CUDDNode> >()
            {
                systemBDD.transitionBDD
            }, path, false);


            logger.Info("Finish run. Result is " + reach1);

#if DEBUG
            StringBuilder builder = new StringBuilder();
            PrintResult(builder, path, encoder, letters);
            logger.Info(builder.ToString());
#endif

            return(path);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Return AutomataBDD of the guard process
 /// </summary>
 /// <param name="guard">The guard expression of the process P1</param>
 /// <param name="P1">AutomataBDD of the process P1</param>
 /// <param name="model"></param>
 /// <returns></returns>
 public static AutomataBDD Guard(Expression guard, AutomataBDD P1, Model model)
 {
     AutomataBDD result = AutomataBDD.Guard(guard, P1, model);
     GuardEncodeTick(guard, P1, model, result);
     //
     return result;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Return the AutomataBDD of the Channel Output
        /// </summary>
        /// <param name="channelName">Channel's name</param>
        /// <param name="channelEventIndex"></param>
        /// <param name="exps">List of output expressions of the channel</param>
        /// <param name="guardOfTick"></param>
        /// <param name="P1"><AutomataBDD of process P1 after the channel input/param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static AutomataBDD SyncChannelOutputPrefixing(int channelEventIndex, List<Expression> exps, Expression guardOfTick, AutomataBDD P1, Model model)
        {
            AutomataBDD result = AutomataBDD.SyncChannelOutputPrefixing(channelEventIndex, exps, P1, model);
            EventPrefixEncodeTick(guardOfTick, P1, model, result);

            //
            return result;
        }
Exemplo n.º 8
0
 public PrimitiveApplication(String op, Expression a1)
 {
     ExpressionType = ExpressionType.PrimitiveApplication;
     Operator = op;
     Argument1 = a1;
     this.HasVar = a1.HasVar;
     expressionID = Operator + Argument1.ExpressionID;
 }
Exemplo n.º 9
0
 public ClassPropertyAssignment(ClassProperty property, Expression rhs)
 {
     ClassProperty = property;
     RightHandExpression = rhs;
     ExpressionType = ExpressionType.ClassPropertyAssignment;
     HasVar =  ClassProperty.HasVar || rhs.HasVar;
     expressionID = ClassProperty.ExpressionID + "=" + RightHandExpression.ExpressionID;
 }
Exemplo n.º 10
0
 public Sequence(Expression f, Expression s)
 {
     FirstPart = f;
     SecondPart = s;
     HasVar = f.HasVar || s.HasVar;
     ExpressionType = ExpressionType.Sequence;
     expressionID = FirstPart.ExpressionID + ";" + SecondPart.ExpressionID;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Return AutomataBDD of the not tau event prefix process with guard [b] e -> P1
        /// </summary>
        /// <param name="guard"></param>
        /// <param name="updateOfEvent">Update command happening with the event</param>
        /// <param name="guardOfTick">Guard of the tick before engaging the event</param>
        /// <param name="P1">AutomataBDD of the process P1 engaging after the event</param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static AutomataBDD EventPrefix(Expression guard, Expression updateOfEvent, Expression guardOfTick, AutomataBDD P1, Model model)
        {
            AutomataBDD result = AutomataBDD.EventPrefix(guard, updateOfEvent, P1, model);
            EventPrefixEncodeTick(guardOfTick, P1, model, result);

            //
            return result;
        }
Exemplo n.º 12
0
        public DataOperationPrefix(Event e, Expression assignment, Process process, string[] localvar)
        {
            Event = e;
            AssignmentExpr = assignment;
            Process = process;
            LocalVariables = localvar;

            ProcessID = DataStore.DataManager.InitializeProcessID(Event.GetID() + "{" + AssignmentExpr.ExpressionID + "}" + Constants.EVENTPREFIX + Process.ProcessID);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Return the AutomataBDD of the Channel Output
        /// </summary>
        /// <param name="channelName">Channel's name</param>
        /// <param name="channelEventIndex"></param>
        /// <param name="exps">List of output expressions of the channel</param>
        /// <param name="assignmentExp"></param>
        /// <param name="guardOfTick"></param>
        /// <param name="P1"><AutomataBDD of process P1 after the channel input/param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static AutomataBDD ChannelOutputPrefixing(string channelName, int channelEventIndex, List<Expression> exps, Expression assignmentExp, Expression guardOfTick, AutomataBDD P1, Model model)
        {
            AutomataBDD result = AutomataBDD.ChannelOutputPrefixing(channelName, channelEventIndex, exps, assignmentExp,
                                                                    P1, model);
            EventPrefixEncodeTick(guardOfTick, P1, model, result);

            //
            return result;
        }
Exemplo n.º 14
0
        public Assignment(string l, Expression r)
        {
            LeftHandSide = l;
            RightHandSide = r;
            ExpressionType = ExpressionType.Assignment;
            HasVar = true;

            expressionID = LeftHandSide + "=" + RightHandSide.ExpressionID;
        }
Exemplo n.º 15
0
 //string[] localvar,
 public PNTransition(Event e, ParallelDefinition[] selects, Expression guard, Expression assignment, PNPlace from, PNPlace to)
 {
     Event = e;
     Selects = selects;
     ProgramBlock = assignment;
     GuardCondition = guard;
     FromPNPlace = from;
     ToPNPlace = to;
 }
Exemplo n.º 16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="channelName">The channel Name</param>
        /// <param name="channelEventIndex"></param>
        /// <param name="guard">If no guard, give BoolConstant(true)</param>
        /// <param name="exps">List of expressions of channel out</param>
        /// <param name="assignmentExp">If no guard, give BoolConstant(true)</param>
        /// <param name="P1">Process after channel in</param>
        /// <param name="model"></param>
        /// <param name="result"></param>
        private static void ChannelInputEncodeTransition(string channelName, int channelEventIndex, Expression guard, List<Expression> exps, Expression assignmentExp, AutomataBDD P1, Model model, AutomataBDD result)
        {
            List<Expression> guardUpdateChannel = GetGuardUpdateOfChannelInput(channelName, guard, exps, assignmentExp, model);

            //set update Model.Event_Name
            guardUpdateChannel[1] = new Sequence(guardUpdateChannel[1], new Assignment(Model.EVENT_NAME, new IntConstant(channelEventIndex)));

            EventPrefixEncodeTransition(guardUpdateChannel[0], guardUpdateChannel[1], P1, model, result);
        }
Exemplo n.º 17
0
        public While(Expression t, Expression b)
        {
            Test = t;
            Body = b;
            this.HasVar = t.HasVar || b.HasVar;
            ExpressionType = ExpressionType.While;

            expressionID = "W@" + Test.ExpressionID + "{" + Body.ExpressionID + "}";
        }
Exemplo n.º 18
0
        public LetDefinition(String v, Expression rhe)
        {
            Variable = v;
            RightHandExpression = rhe;
            HasVar = true;
            ExpressionType = ExpressionType.Let;

            expressionID = Variable + "=" + RightHandExpression.ExpressionID;
        }
Exemplo n.º 19
0
        public PropertyAssignment(Expression rec, Expression p, Expression rhs)
        {
            RecordExpression = rec;
            PropertyExpression = p;
            RightHandExpression = rhs;
            ExpressionType = ExpressionType.PropertyAssignment;
            this.HasVar = RecordExpression.HasVar || PropertyExpression.HasVar || rhs.HasVar;

            expressionID = RecordExpression.ExpressionID + "[" + PropertyExpression.ExpressionID + "]=" + RightHandExpression.ExpressionID;
        }
Exemplo n.º 20
0
        public override Process ClearConstant(Dictionary<string, Expression> constMapping)
        {
            Expression[] newExpression = new Expression[ExpressionList.Length];
            for (int i = 0; i < ExpressionList.Length; i++)
            {
                newExpression[i] = ExpressionList[i].ClearConstant(constMapping);
            }

            return new ChannelOutput(ChannelName, newExpression, Process.ClearConstant(constMapping));
        }
Exemplo n.º 21
0
 public ParallelDefinition(string para, IToken token)
 {
     Parameter = para;
     Domain = new List<Expression>();
     DomainValues = new List<int>();
     //HasVaraible = false;
     LowerBound = null;
     UpperBound = null;
     Token = token;
 }
Exemplo n.º 22
0
        public ConditionalChoice(Process firstProcess, Process secondProcess, Expression conditionExpression)
        {
            FirstProcess = firstProcess;
            SecondProcess = secondProcess;
            ConditionalExpression = conditionExpression;

            ProcessID = DataStore.DataManager.InitializeProcessID(FirstProcess.ProcessID + Constants.CONDITIONAL_CHOICE +
                                                                      conditionExpression.ExpressionID + Constants.CONDITIONAL_CHOICE +
                                                                      SecondProcess.ProcessID);
        }
Exemplo n.º 23
0
 //string[] localvar,
 public Transition(Event e, ParallelDefinition[] selects, Expression Guard, Expression assignment, State from, State to)
 {
     Event = e;
     Selects = selects;
     ProgramBlock = assignment;
     //LocalVariables = localvar;
     GuardCondition = Guard;
     FromState = from;
     ToState = to;
 }
Exemplo n.º 24
0
        private static Expression CreateFunctionApplication(
            Dictionary <string, List <int> > availableFunctions,
            IEnumerable <IGrouping <string, GeneLink> > toDictionary,
            int i,
            Mode mode,
            Dictionary <string, bool> values)
        {
            Expression res = null;


            toDictionary.ToList().ForEach(ff =>
            {
                Expression ass = null;
                var to         = ff.Key;
                var froms      = ff.Where(a => !a.IsOptional).ToList();

                // can be null!!

                if (availableFunctions == null || !availableFunctions.ContainsKey(to))
                {
                    res = AddIfExist(res, CreateAssignment(ff.FirstOrDefault(), i, GetFunction(mode)), mode);
                }
                else
                {
                    var availableFunc        = availableFunctions[to];
                    var funcAssignmentHelper = new FuncAssignmentHelper();
                    var toFormatted          = Formater.FormatParameter(to, i + 1);

                    availableFunc.ForEach(f =>
                    {
                        ass =
                            funcAssignmentHelper.CreateFuncAssignment(to, froms, i, f);

                        //if (values != null && values.ContainsKey(toFormatted))
                        //{
                        //    ass = new PrimitiveApplication(PrimitiveApplication.AND, ass, new BoolConstant(values[toFormatted]));
                        //    values.Remove(toFormatted);
                        //}
                    });


                    if (mode == Mode.Equal)
                    {
                        res = new PrimitiveApplication(PrimitiveApplication.EQUAL, new Variable(toFormatted),
                                                       ass);
                    }
                    else
                    {
                        res = GetFunction(mode).Invoke(toFormatted, ass);
                    }
                }
            });

            return(res);
        }
Exemplo n.º 25
0
        public override Expression ClearConstant(Dictionary<string, Expression> constMapping)
        {
            Expression[] newArgs = new Expression[Arguments.Length];

            for (int i = 0; i < Arguments.Length; i++)
            {
                newArgs[i] = Arguments[i].ClearConstant(constMapping);
            }

            return new NewObjectCreation(ClassName, newArgs);
        }
Exemplo n.º 26
0
        public override Expression ClearConstant(Dictionary<string, Expression> constMapping)
        {
            Expression[] newArgs = new Expression[Arguments.Length];

            for (int i = 0; i < Arguments.Length; i++)
            {
                newArgs[i] = Arguments[i].ClearConstant(constMapping);
            }

            return new ClassMethodCallInstance(Variable.ClearConstant(constMapping), MethodName, newArgs);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Return the AutomataBDD of the Channel Input
        /// Currently Channel Input is translated as assginment, not guard. We don't support using channel input to expect a certain value
        /// </summary>
        /// <param name="channelName">Channel's name</param>
        /// <param name="channelEventIndex"></param>
        /// <param name="guard">Guard expression of the channel input</param>
        /// <param name="exps">List of input expression to the channel</param>
        /// <param name="assignmetExp"></param>
        /// <param name="P1">AutomataBDD of process P1 after the channel input</param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static AutomataBDD ChannelInputPrefixing(string channelName, int channelEventIndex, Expression guard, List<Expression> exps, Expression assignmetExp, AutomataBDD P1, Model model)
        {
            AutomataBDD result = new AutomataBDD();

            ChannelInputSetVariable(exps, P1, model, result);
            EventPrefixSetInit(result);
            ChannelInputEncodeTransition(channelName, channelEventIndex, guard, exps, assignmetExp, P1, model, result);

            //
            return result;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Return AutomataBDD of the guard process
        /// </summary>
        /// <param name="guard">The guard expression of the process P1</param>
        /// <param name="P1">AutomataBDD of the process P1</param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static AutomataBDD Guard(Expression guard, AutomataBDD P1, Model model)
        {
            AutomataBDD result = new AutomataBDD();

            GuardSetVariable(P1, model, result);
            GuardSetInit(P1, result);
            GuardEncodeTransition(guard, P1, model, result);

            //
            return result;
        }
Exemplo n.º 29
0
        public override Expression ClearConstant(Dictionary<string, Expression> constMapping)
        {
            Expression[] newAssociations = new Expression[Associations.Length];

            for (int i = 0; i < Associations.Length; i++)
            {
                newAssociations[i] = Associations[i].ClearConstant(constMapping);
            }

            return new Record(newAssociations);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Return AutomataBDD of the not tau event prefix process with guard [b] e -> P1
        /// </summary>
        /// <param name="guard">Guard of this event to happen</param>
        /// <param name="updateOfEvent">Update command happening with the event</param>
        /// <param name="P1">AutomataBDD of the process P1 engaging after the event</param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static AutomataBDD EventPrefix(Expression guard, Expression updateOfEvent, AutomataBDD P1, Model model)
        {
            AutomataBDD result = new AutomataBDD();

            EventPrefixSetVariable(P1, model, result);
            EventPrefixSetInit(result);
            EventPrefixEncodeTransition(guard, updateOfEvent, P1, model, result);

            //
            return result;
        }
Exemplo n.º 31
0
 public int HVal(Expression exp)
 {
     PrimitiveApplication pa = exp as PrimitiveApplication;
     foreach (StringDictionaryEntryWithKey<ExpressionValue> expVal in Variables._entries)
     {
         if ("P3".Equals(expVal.Key))
         {
             return (expVal.Value as IntConstant).Value;
         }
     }
     return -1;
 }
Exemplo n.º 32
0
 public ChannelOutputEvent(string name, Expression ex)
     : base(name)
 {
     if (ex == null)
     {
         ExpressionList = new Expression[0];
     }
     else
     {
         ExpressionList = new Expression[] { ex };
     }
 }
Exemplo n.º 33
0
        private static Expression SetGoalBasedOnFunction(List <GeneLink> booleanNetwok,
                                                         Dictionary <string, List <int> > availableFunctions, int depth)
        {
            Expression seq = null;

            var toDictionary = booleanNetwok.GroupBy(a => a.To);

            for (int i = 0; i < depth - 1; i++)
            {
                Expression ass = null;


                toDictionary.ToList().ForEach(ff =>
                {
                    var b    = ff.FirstOrDefault();
                    var from = Formater.FormatParameter(b.From, i);
                    var to   = Formater.FormatParameter(b.To, i + 1);

                    if (b.IsPositive)
                    {
                        //ass = new Assignment(b.To,
                        //    new Variable(b.From));

                        ass = new PrimitiveApplication(PrimitiveApplication.EQUAL,
                                                       new Variable(to), new Variable(from));
                    }
                    else
                    {
                        ass = new PrimitiveApplication(PrimitiveApplication.EQUAL,
                                                       new Variable(to),
                                                       new PrimitiveApplication(
                                                           PrimitiveApplication.AND, new PrimitiveApplication(nOT, new Variable(from))));
                    }

                    if (seq == null)
                    {
                        seq = ass;
                    }
                    else
                    {
                        seq =
                            new PrimitiveApplication(PrimitiveApplication.AND,
                                                     seq,
                                                     ass);
                    }
                });
            }

            return(seq);
        }
Exemplo n.º 34
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);
        }
Exemplo n.º 35
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);
        }
Exemplo n.º 36
0
        private static Expression AddIfExist(Expression res, Expression createAssignment, Mode mode)
        {
            if (res == null)
            {
                return(createAssignment);
            }

            if (mode == Mode.Equal)
            {
                res = new PrimitiveApplication(PrimitiveApplication.AND, res, createAssignment);
            }
            else
            {
                res = new Sequence(res, createAssignment);
            }

            return(res);
        }
Exemplo n.º 37
0
        private static Expression CreateExpressionsFromBooleanNetwork(List <GeneLink> booleanNetwok,
                                                                      Dictionary <string, List <int> > availableFunctions,
                                                                      int depth,
                                                                      Mode mode,
                                                                      Dictionary <string, bool> values = null)
        {
            Expression seq = null;

            var toDictionary = booleanNetwok.GroupBy(a => a.To);

            for (int i = 0; i < depth - 1; i++)
            {
                var ass = CreateFunctionApplication(availableFunctions, toDictionary, i, mode, values);

                seq = AddIfExist(seq, ass, mode);
            }

            return(seq);
        }
Exemplo n.º 38
0
 private static Assignment CreateAssignment(string toFormatted, Expression ass)
 {
     return(new Assignment(toFormatted, ass));
 }
Exemplo n.º 39
0
 private static Expression CreateEquality(string toFormatted, Expression ass)
 {
     return(new PrimitiveApplication(PrimitiveApplication.EQUAL, new Variable(toFormatted), ass));
 }
Exemplo n.º 40
0
        public bool IsValidPath(GeneNode automata, List <GeneLink> booleanNetwok, Dictionary <string, List <int> > availableFunctions = null)
        {
            lock (locker)
            {
                var tempAutomata = automata;
                //    new GeneNode()
                //{
                //    NodeName = "Start",
                //    CurrentCondition = new Condition(),
                //    Transitions = new List<GeneTransition>()
                //    {
                //        new GeneTransition()
                //        {
                //            Node = automata
                //        }
                //    }
                //};

                var letters = new List <string>();

                int z     = 0;
                var depth = tempAutomata.NodeLength;

                tempAutomata.GetAllConditionLetters(letters);

                letters = letters.SelectMany(l => Enumerable.Range(0, depth).ToList().Select(n => Formater.FormatParameter(l, n))).ToList();

                logger.Info(tempAutomata.NodeLength + 1);

                Model.NUMBER_OF_EVENT             = tempAutomata.NodeLength + 2;
                Model.MAX_NUMBER_EVENT_PARAMETERS = 0;

                BDDEncoder encoder = new BDDEncoder();

                letters.Distinct().ToList().ForEach(l => encoder.model.AddLocalVar(l, 0, 1));
                logger.Info(string.Join(",", letters));

                SymbolicLTS lts = new SymbolicLTS();

                List <State> states = new List <State>();
                var          state0 = lts.AddState();
                states.Add(state0);


                lts.InitialState = states[0];

                var state1 = lts.AddState();
                states.Add(state1);
                //var goal2 = CreateExpressionBasedOnAutomata(tempAutomata);

                var        dictValues = BDDLogicHelper.CreateDictBasedOnAutomata(tempAutomata);
                Expression seq        = null;

                /*CreateExpressionsFromBooleanNetwork(booleanNetwok,
                 *      availableFunctions, depth, Mode.Assignment, dictValues);*/

                if (dictValues.Any())
                {
                    dictValues.ToList().ForEach(f =>
                    {
                        Expression curr = new Assignment(f.Key, new BoolConstant(f.Value));
                        seq             = seq == null ? curr : new Sequence(seq, curr);
                    });
                }



                //seq =  new Sequence(seq, goal2);
                //  //
                logger.Info("Assignments: " + seq);

                var trans1 =
                    new Transition(new Event("a0"), null, seq,
                                   states[0], states[1]);

                lts.Transitions.Add(trans1);
                logger.Info(lts);
                AutomataBDD systemBDD = lts.Encode(encoder);

                systemBDD.PrintTransition();
                CUDDNode initDD = CUDD.Function.Or(
                    systemBDD.initExpression.TranslateBoolExpToBDD(encoder.model).GuardDDs);

                bool reach1         = true;
                var  path           = new List <CUDDNode>();
                var  geneTransition = tempAutomata;
                InitInitialState(geneTransition, systemBDD, letters);
                var goal  = SetGoalsBasedOnAutomata(geneTransition);
                var goal3 = CreateExpressionsFromBooleanNetwork(booleanNetwok,
                                                                availableFunctions, depth, Mode.Equal);

                goal = new PrimitiveApplication(PrimitiveApplication.AND, goal, goal3);
                logger.Info("Goal: " + goal);
                path = IsExistPath(goal, encoder, path, initDD, systemBDD, letters, ref reach1);
                path.Clear();
                encoder.model.Close();
                return(reach1);
            }
        }