private void SomeFunction()
        {
            var a = new ModelProgram();

            statusBoolValue = a.FuncionRead(statusBoolValue);
            TextBoxValue    = Convert.ToString(statusBoolValue);
        }
Esempio n. 2
0
 /// <summary>
 /// Construct a model stepper that records coverage points.
 /// Defines the coverage point for a given action a and state s
 /// as the bag containig the pair (s.GetHashCode(),a.GetHashCode())
 /// </summary>
 /// <param name="modelProgram">model program</param>
 /// <param name="policy">reward policy</param>
 public StrategyWithCoverage(ModelProgram modelProgram, RewardPolicy policy)
     :
     base(modelProgram)
 {
     this.policy = policy;
     this.coveragePointProvider = DefaultCoveragePointProvider;
 }
Esempio n. 3
0
        /// <summary>
        /// Create a strategy with random action selection from the given model program.
        /// </summary>
        /// <param name="modelProgram">model program</param>
        /// <param name="coverage">coverage point names (this argument is ignored)</param>
        public static IStrategy Create(ModelProgram modelProgram, string[] coverage)
        {
            Strategy s = new Strategy(modelProgram);

            s.CoverageNames = new Set <string>(coverage);
            return(s);
        }
        public IActionResult AddUpdateProgram(ModelProgram MP)
        {
            if (!ModelState.IsValid)
            {
                TempData["Action"] = Constants.FAILED;
                return(View(MP));
            }

            try
            {
                if (MP.ProgramId > 0)
                {
                    MP.DateUpdated = DateTime.Now;
                    OurdbContext.Program.Update(CopyMPToP(MP));
                    OurdbContext.SaveChanges();
                }
                else
                {
                    OurdbContext.Program.Add(CopyMPToP(MP));
                    OurdbContext.SaveChanges();
                }
            }
            catch (Exception)
            {
                TempData["Action"] = Constants.FAILED;
            }

            return(RedirectToAction(nameof(AdministratorController.ProgramList)));
        }
Esempio n. 5
0
 /// <summary>
 /// Construct a model stepper that records coverage points.
 /// Coverage points of interest are provided by <paramref name="transitionPropertyNames"/>
 /// </summary>
 /// <param name="modelProgram">model program</param>
 /// <param name="policy">reward policy</param>
 /// <param name="transitionPropertyNames">(optional) coverage points of interest</param>
 public StrategyWithCoverage(ModelProgram modelProgram, RewardPolicy policy, Set <string> transitionPropertyNames)
     :
     base(modelProgram)
 {
     this.policy = policy;
     this.coveragePointProvider = new CoveragePointProvider(modelProgram, transitionPropertyNames).GetCoveragePoints;
 }
Esempio n. 6
0
        internal ExploredTransitions(ModelProgram modelProgram, int initTransitions, int maxTransitions)
        {
            this.modelProgram        = modelProgram;
            this.transitions         = Set <Transition> .EmptySet;
            this.groupingTransitions = Set <Transition> .EmptySet;
            Node initNode = new Literal(0);

            this.initialNode    = initNode;
            this.nodes          = new Set <Node>(initNode);
            this.acceptingNodes = (modelProgram.IsAccepting(modelProgram.InitialState) ?
                                   new Set <Node>(initNode) :
                                   Set <Node> .EmptySet);
            //this.errorNodes = (!modelProgram.SatisfiesStateInvariant(modelProgram.InitialState) ?
            //    new Set<Node>(initNode) :
            //    Set<Node>.EmptySet);
            Dictionary <Node, IState> initialStateMap =
                new Dictionary <Node, IState>();

            initialStateMap[initNode] = modelProgram.InitialState;
            this.stateMap             = initialStateMap;
            actionsExploredFromNode   = new Dictionary <Node, Dictionary <CompoundTerm, Node> >();
            Dictionary <IState, Node> initialNodeMap =
                new Dictionary <IState, Node>();

            initialNodeMap[modelProgram.InitialState] = initNode;
            this.nodeMap           = initialNodeMap;
            this.hiddenTransitions = Set <Transition> .EmptySet;
            this.maxTransitions    = maxTransitions;
            this.initTransitions   = initTransitions;
        }
Esempio n. 7
0
        internal Set <CompoundTerm> processGoal(ModelProgram mp, Set <CompoundTerm> goals)
        {
            Set <CompoundTerm> processedGoals = Set <CompoundTerm> .EmptySet;

            if (typeof(LibraryModelProgram) == mp.GetType())
            {
                //we ignore it for the moment
                Console.Error.WriteLine("Goals involving LibraryModelPrograms currently not supported. ");
                Console.Error.WriteLine("Currently searching for a match for '" + goals.ToString() + "'. ");
            }
            else if (typeof(FsmModelProgram) == mp.GetType())
            {
                FsmModelProgram fsm = (FsmModelProgram)mp;
                foreach (CompoundTerm ct in goals)
                {
                    Console.WriteLine("Checking FSM: " + ct.ToString() + "; " + fsm.Name);
                    if (ct.FunctionSymbol.ToString() == fsm.Name)
                    {
                        processedGoals = processedGoals.Add(CompoundTerm.Parse("FsmState(Set(" + ct.Arguments[0].ToString() + "))"));
                        goals          = goals.Remove(ct);
                    }
                    Console.WriteLine("Current processedGoals: " + processedGoals.ToString());
                }
            }
            else if (typeof(ProductModelProgram) == mp.GetType())
            {
                ProductModelProgram pmp = (ProductModelProgram)mp;
                processedGoals = processedGoals.Union(processGoal(pmp.M1, goals));
                processedGoals = processedGoals.Union(processGoal(pmp.M2, goals));
            }
            return(processedGoals);
        }
Esempio n. 8
0
        /// <summary>
        /// Process the goal in the format "ModelProgramName1(stateName1(value1)),ModelProgramName2(stateName2(value2)" to a compound term of the corresponding model program.
        /// In the case of FSMs the format is "ModelProgramName(stateNumber)".
        /// </summary>
        /// <param name="mp">model program</param>
        /// <param name="goalString">goal as string</param>
        /// <returns>A set of compound terms corresponding to the goal string.</returns>
        internal Set <CompoundTerm> processGoal(ModelProgram mp, string goalString)
        {
            Set <CompoundTerm> processedGoals = Set <CompoundTerm> .EmptySet;

            if (goalString == "")
            {
                return(processedGoals);
            }
            string[]           subgoals = goalString.Split(',');
            Set <CompoundTerm> goals    = Set <CompoundTerm> .EmptySet;

            try
            {
                foreach (string g in subgoals)
                {
                    CompoundTerm ct = CompoundTerm.Parse(g);
                    goals = goals.Add(ct);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("The goal '" + goalString + "' seems not to be a term. " +
                                        "Goal should be in the form ModelProgramName(state) " +
                                        "(or several such terms separated by commas).");
                Console.Error.WriteLine("The error message: ", e.Message);
                return(processedGoals);
            }
            return(processGoal(mp, goals));
        }
Esempio n. 9
0
 /// <summary>
 /// Construct a model stepper that records coverage points.
 /// </summary>
 /// <param name="modelProgram">model program</param>
 /// <param name="policy">reward policy</param>
 /// <param name="coveragePointProvider">(optional) coverage point provider</param>
 public StrategyWithCoverage(ModelProgram modelProgram, RewardPolicy policy, CoveragePointDelegate coveragePointProvider)
     :
     base(modelProgram)
 {
     this.policy = policy;
     this.coveragePointProvider = coveragePointProvider;
 }
Esempio n. 10
0
 public MDPStrategy(ModelProgram modelProgram)
     :
     base(modelProgram)
 {
     cov = new Dictionary <IState, double>();
     v   = new Dictionary <IState, double>();
     cps = new Dictionary <int, Set <int> >();
 }
Esempio n. 11
0
        /// <summary>
        /// Check if the term represented by goal is reachable in the given model program.
        /// Empty string as goal results in traversing the whole state space.
        /// </summary>
        /// <param name="mp">The model program to be checked.</param>
        /// <param name="goal">The goal term involving the model program name as outer function symbol.</param>
        /// <param name="excludeIsomorphicStates">Whether to use the symmetry reduction. Default is false.</param>
        public static ReachabilityResult Check(ModelProgram mp, string goal, bool excludeIsomorphicStates = false)
        {
            Reachability reach = new Reachability();

            reach.ModelProgram            = mp;
            reach.excludeIsomorphicStates = excludeIsomorphicStates;
            return(reach.CheckReachability(goal));
        }
Esempio n. 12
0
 /// <summary>
 /// Sets the initial state of the view
 /// </summary>
 /// <param name="modelProgram">given model program to be viewed</param>
 public void SetModelProgram(ModelProgram modelProgram1)
 {
     this.modelProgram        = modelProgram1;
     this.exploredTransitions = new ExploredTransitions(modelProgram1, this.initialTransitions, this.maxTransitions);
     this.exploredTransitions.excludeIsomorphicStates          = this.ExcludeIsomorphicStates;
     this.exploredTransitions.collapseExcludedIsomorphicStates = this.collapseExcludedIsomorphicStates;
     this.exploredTransitions.ShowReachable(this.exploredTransitions.initialNode);
     this.InitializeViewer();
 }
Esempio n. 13
0
 public MDPNewAbstractStrategy(ModelProgram modelProgram) :
     base(modelProgram)
 {
     requirementProperties  = Sequence <string> .EmptySequence;
     requireEnabledStateMap = Map <string, Set <int> > .EmptyMap;
     activeEdges            = new Dictionary <int, Set <int> >();
     passiveEdges           = new Dictionary <int, Bag <int> >();
     bdt = new BinaryDecisionTree("root", null, null, 1, 1, new Set <int>(currState.GetHashCode()));
 }
Esempio n. 14
0
 /// <summary>
 /// Construct a strategy with random action selection from the given model program.
 /// </summary>
 /// <param name="modelProgram">model program</param>
 public Strategy(ModelProgram modelProgram)
 {
     if (modelProgram == null)
     {
         throw new ArgumentNullException("modelProgram");
     }
     this.modelProgram = modelProgram;
     this.currState    = modelProgram.InitialState;
     this.initialState = modelProgram.InitialState;
 }
        public IActionResult AddUpdateProgram()
        {
            ModelProgram MP = new ModelProgram();

            MP.DateCreated = DateTime.Now;
            IList <Shift> ILS = OurdbContext.Shift.ToList();

            ViewBag.vb = ILS;
            return(View(MP));
        }
Esempio n. 16
0
 /// <summary>
 /// Creates a model stepper that uses coverage points (when != null) to direct the selection of actions.
 /// If coverage == null, uses default coverage points that are (state.GetHashCode(), action.GetHashCode()) pairs.
 /// Uses RewardPolicy.ProbableReward for action selection.
 /// </summary>
 /// <param name="modelProgram">given model program</param>
 /// <param name="coverage">given coverage point names (may be null)</param>
 public static StrategyWithCoverage CreateWithProbableReward(ModelProgram modelProgram, string[] /*?*/ coverage)
 {
     if (coverage == null)
     {
         return(new StrategyWithCoverage(modelProgram, RewardPolicy.ProbableReward));
     }
     else
     {
         return(new StrategyWithCoverage(modelProgram, RewardPolicy.ProbableReward, new Set <string>(coverage)));
     }
 }
 private Program CopyMPToP(ModelProgram MP)
 {
     Entities.Program P = new Entities.Program
     {
         ProgramId    = MP.ProgramId,
         FkShiftId    = MP.FkShiftId,
         ProgramTitle = MP.ProgramTitle,
         DateCreated  = MP.DateCreated,
         DateUpdated  = MP.DateUpdated,
     };
     return(P);
 }
Esempio n. 18
0
 public MDPNewStrategy(ModelProgram modelProgram)
     :
     base(modelProgram)
 {
     cov          = new Dictionary <int, double>();
     v            = new Dictionary <int, double>();
     cps          = new Dictionary <int, Set <int> >();
     activeEdges  = new Dictionary <int, Set <int> >();
     passiveEdges = new Dictionary <int, Bag <int> >();
     v[this.currState.GetHashCode()]   = 1.0;
     cov[this.currState.GetHashCode()] = 0.0;
 }
        private ModelProgram CopyPToMP(Program P)
        {
            ModelProgram MP = new ModelProgram
            {
                ProgramId    = P.ProgramId,
                FkShiftId    = P.FkShiftId,
                ProgramTitle = P.ProgramTitle,
                DateCreated  = P.DateCreated,
                DateUpdated  = P.DateUpdated,
            };

            return(MP);
        }
Esempio n. 20
0
        private static IStrategy CreateModelStepper(List <Assembly> libs, ModelProgram mp,
                                                    string /*?*/ msName, string[] /*?*/ coverage, Set <Symbol> obs)
        {
            //if no model stepper name is provided, use the default one and ignore coverage
            if (msName == null)
            {
                return(new Strategy(mp));
            }

            //check if one of the supported model steppers is used
            if (msName.Equals(typeof(StrategyWithCoverage).FullName + ".CreateWithMaximumReward"))
            {
                return(StrategyWithCoverage.CreateWithMaximumReward(mp, coverage));
            }
            //check if one of the supported model steppers is used
            if (msName.Equals(typeof(StrategyWithCoverage).FullName + ".CreateWithProbableReward"))
            {
                return(StrategyWithCoverage.CreateWithProbableReward(mp, coverage));
            }

            string msMethodName;
            string msClassName;

            ReflectionHelper.SplitFullMethodName(msName, out msClassName, out msMethodName);
            Type       msType   = ReflectionHelper.FindType(libs, msClassName);
            MethodInfo msMethod = ReflectionHelper.FindMethod(msType, msMethodName, new Type[] { typeof(ModelProgram), typeof(string[]) }, typeof(IStrategy));
            IStrategy  ms       = null;

            try
            {
                ms = (IStrategy)msMethod.Invoke(null, new object[] { mp, coverage });
                ms.ObservableActionSymbols = obs;
            }
            catch (Exception e)
            {
                throw new ModelProgramUserException("Invocation of '" + msName + "' failed: " + e.ToString());
            }
            return(ms);
        }
Esempio n. 21
0
        /// <summary>
        /// Provides programmatic access to the ModelProgramViewer commandline utility 'mpv.exe'.
        /// </summary>
        /// <param name="args">command line arguments: model program(s), optional settings for the viewer</param>
        /// <remarks>The settings are displayed when 'mpv.exe /?' is executed from the command line without arguments.</remarks>
        public static void Run(ModelProgram mp)
        {
            ProgramSettings settings = new ProgramSettings();

            //ModelProgram mp = (ModelProgram)lmp;

            ModelProgramGraphViewForm form = new ModelProgramGraphViewForm("Model Program Viewer");

            //configure the settings of the viewer
            form.View.AcceptingStatesMarked   = settings.acceptingStatesMarked;
            form.View.TransitionLabels        = settings.transitionLabels;
            form.View.CombineActions          = settings.combineActions;
            form.View.Direction               = settings.direction;
            form.View.UnsafeStateColor        = Color.FromName(settings.unsafeStateColor);
            form.View.HoverColor              = Color.FromName(settings.hoverColor);
            form.View.InitialStateColor       = Color.FromName(settings.initialStateColor);
            form.View.LoopsVisible            = settings.loopsVisible;
            form.View.MaxTransitions          = settings.maxTransitions;
            form.View.NodeLabelsVisible       = settings.nodeLabelsVisible;
            form.View.SelectionColor          = Color.FromName(settings.selectionColor);
            form.View.MergeLabels             = settings.mergeLabels;
            form.View.StateShape              = settings.stateShape;
            form.View.DeadStateColor          = Color.FromName(settings.deadStateColor);
            form.View.InitialTransitions      = settings.initialTransitions;
            form.View.LivenessCheckIsOn       = settings.livenessCheckIsOn;
            form.View.ExcludeIsomorphicStates = settings.excludeIsomorphicStates;
            form.View.SafetyCheckIsOn         = settings.safetyCheckIsOn;
            form.View.DeadstatesVisible       = settings.deadStatesVisible;
            form.View.StateViewVisible        = settings.stateViewVisible;

            //show the view of the product of all the model programs
            form.View.SetModelProgram(mp);

            form.OnSaveSettings += new EventHandler(settings.SaveSettings);
            form.ShowDialog();
        }
Esempio n. 22
0
 /// <summary>
 /// Create a coverage point provider for a model program and a given set of property names
 /// </summary>
 /// <param name="mp">given model program</param>
 /// <param name="transitionPropertyNames">property names of interest</param>
 public CoveragePointProvider(ModelProgram mp, Set <string> transitionPropertyNames)
 {
     this.mp = mp;
     this.transitionPropertyNames = transitionPropertyNames;
 }
Esempio n. 23
0
        public static void RunWithCommandLineArguments(string[] args)
        {
            //System.Diagnostics.Debugger.Break();
            ConformanceTester confTester = null;

            try
            {
                ConfTesterCommandLineSettings settings = new ConfTesterCommandLineSettings();
                if (!Parser.ParseArgumentsWithUsage(args, settings))
                {
                    //Console.ReadLine();
                    return;
                }

                #region load the libraries
                List <Assembly> libs = new List <Assembly>();
                try
                {
                    if (settings.reference != null)
                    {
                        foreach (string l in settings.reference)
                        {
                            libs.Add(System.Reflection.Assembly.LoadFrom(l));
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException(e.Message);
                }
                #endregion

                #region create the implementation stepper using the factory method
                string implStepperMethodName;
                string implStepperClassName;
                ReflectionHelper.SplitFullMethodName(settings.iut, out implStepperClassName, out implStepperMethodName);
                Type       implStepperType   = ReflectionHelper.FindType(libs, implStepperClassName);
                MethodInfo implStepperMethod = ReflectionHelper.FindMethod(implStepperType, implStepperMethodName, Type.EmptyTypes, typeof(IStepper));
                IStepper   implStepper       = null;
                try
                {
                    implStepper = (IStepper)implStepperMethod.Invoke(null, null);
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException("Invocation of '" + settings.iut + "' failed: " + e.ToString());
                }
                #endregion

                #region create a model program for each model using the factory method and compose into product
                string       mpMethodName;
                string       mpClassName;
                ModelProgram mp = null;
                if (settings.model != null && settings.model.Length > 0)
                {
                    ReflectionHelper.SplitFullMethodName(settings.model[0], out mpClassName, out mpMethodName);
                    Type       mpType   = ReflectionHelper.FindType(libs, mpClassName);
                    MethodInfo mpMethod = ReflectionHelper.FindMethod(mpType, mpMethodName, Type.EmptyTypes, typeof(ModelProgram));
                    try
                    {
                        mp = (ModelProgram)mpMethod.Invoke(null, null);
                    }
                    catch (Exception e)
                    {
                        throw new ModelProgramUserException("Invocation of '" + settings.model[0] + "' failed: " + e.ToString());
                    }
                    for (int i = 1; i < settings.model.Length; i++)
                    {
                        ReflectionHelper.SplitFullMethodName(settings.model[i], out mpClassName, out mpMethodName);
                        mpType   = ReflectionHelper.FindType(libs, mpClassName);
                        mpMethod = ReflectionHelper.FindMethod(mpType, mpMethodName, Type.EmptyTypes, typeof(ModelProgram));
                        ModelProgram mp2 = null;
                        try
                        {
                            mp2 = (ModelProgram)mpMethod.Invoke(null, null);
                        }
                        catch (Exception e)
                        {
                            throw new ModelProgramUserException("Invocation of '" + settings.model[i] + "' failed: " + e.ToString());
                        }
                        mp = new ProductModelProgram(mp, mp2);
                    }
                }
                #endregion

                #region load the test cases if any
                Sequence <Sequence <CompoundTerm> > testcases = Sequence <Sequence <CompoundTerm> > .EmptySequence;
                if (!String.IsNullOrEmpty(settings.testSuite))
                {
                    try
                    {
                        System.IO.StreamReader testSuiteReader =
                            new System.IO.StreamReader(settings.testSuite);
                        string testSuiteAsString = testSuiteReader.ReadToEnd();
                        testSuiteReader.Close();
                        CompoundTerm testSuite = (CompoundTerm)Term.Parse(testSuiteAsString);
                        foreach (CompoundTerm testCaseTerm in testSuite.Arguments)
                        {
                            Sequence <CompoundTerm> testCase =
                                testCaseTerm.Arguments.Convert <CompoundTerm>(delegate(Term t) { return((CompoundTerm)t); });
                            testcases = testcases.AddLast(testCase);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new ModelProgramUserException("Cannot create test suite: " + e.Message);
                    }
                }
                #endregion

                #region load the fsms if any
                Dictionary <string, FSM> fsms = new Dictionary <string, FSM>();
                if (settings.fsm != null && settings.fsm.Length > 0)
                {
                    try
                    {
                        foreach (string fsmFile in settings.fsm)
                        {
                            System.IO.StreamReader fsmReader = new System.IO.StreamReader(fsmFile);
                            string fsmAsString = fsmReader.ReadToEnd();
                            fsmReader.Close();
                            fsms[fsmFile] = FSM.FromTerm(CompoundTerm.Parse(fsmAsString));
                        }
                    }
                    catch (Exception e)
                    {
                        throw new ModelProgramUserException("Cannot create fsm: " + e.Message);
                    }
                }
                #endregion

                if (mp == null && testcases.IsEmpty && fsms.Count == 0)
                {
                    throw new ModelProgramUserException("No model, fsm, or test suite was given.");
                }

                if (fsms.Count > 0)
                {
                    foreach (string fsmName in fsms.Keys)
                    {
                        ModelProgram fsmmp = new FsmModelProgram(fsms[fsmName], fsmName);
                        if (mp == null)
                        {
                            mp = fsmmp;
                        }
                        else
                        {
                            mp = new ProductModelProgram(mp, fsmmp);
                        }
                    }
                }

                #region create the model stepper
                IStrategy ms;

                if (!testcases.IsEmpty)
                {
                    ms = new TestSuiteStepper(settings.startTestAction, testcases, mp);
                }
                else
                {
                    ms = CreateModelStepper(libs, mp, settings.modelStepper, settings.coverage);
                }

                #endregion

                confTester = new ConformanceTester(ms, implStepper);

                #region configure conformance tester settings

                confTester.ContinueOnFailure = settings.continueOnFailure;
                confTester.StepsCnt          = (testcases.IsEmpty ? settings.steps : 0);
                confTester.MaxStepsCnt       = (testcases.IsEmpty ? settings.maxSteps : 0);
                confTester.RunsCnt           = (testcases.IsEmpty ? settings.runs : testcases.Count);
                confTester.WaitAction        = settings.waitAction;
                confTester.TimeoutAction     = settings.timeoutAction;

                Symbol waitActionSymbol    = confTester.waitActionSet.Choose();
                Symbol timeoutActionSymbol = confTester.timeoutAction.FunctionSymbol1;

                Set <Symbol> obs = new Set <string>(settings.observableAction).Convert <Symbol>(delegate(string s) { return(Symbol.Parse(s)); });
                confTester.ObservableActionSymbols = obs;

                Set <Symbol> cleanup = new Set <string>(settings.cleanupAction).Convert <Symbol>(delegate(string s) { return(Symbol.Parse(s)); });
                confTester.CleanupActionSymbols = cleanup;

                if (confTester.IsAsync)
                {
                    //remove the wait and timeout action symbol from tester action symbols
                    if (confTester.testerActionSymbols.Contains(waitActionSymbol) ||
                        confTester.testerActionSymbols.Contains(timeoutActionSymbol))
                    {
                        confTester.testerActionSymbols =
                            confTester.testerActionSymbols.Remove(waitActionSymbol).Remove(timeoutActionSymbol);
                    }
                }

                Set <Symbol> internals = new Set <string>(settings.internalAction).Convert <Symbol>(delegate(string s) { return(Symbol.Parse(s)); });

                confTester.InternalActionSymbols =
                    (testcases.IsEmpty || settings.startTestAction != "Test" ?
                     internals :
                     internals.Add(Symbol.Parse("Test")));

                TimeSpan timeout = new TimeSpan(0, 0, 0, 0, settings.timeout);
                confTester.TesterActionTimeout = delegate(IState s, CompoundTerm a) { return(timeout); };
                confTester.Logfile             = settings.logfile;
                confTester.OverwriteLog        = settings.overwriteLog;
                if (settings.randomSeed != 0)
                {
                    confTester.RandomSeed = settings.randomSeed;
                }
                #endregion

                //finally, run the application
                confTester.Run();
            }
            catch (ModelProgramUserException)
            {
                throw;
            }
            catch (ConformanceTesterException e)
            {
                throw new ModelProgramUserException(e.Message);
            }
            finally
            {
                if (confTester != null)
                {
                    confTester.Dispose();
                }
            }
        }
Esempio n. 24
0
        public static void RunWithCommandLineArguments(string[] args)
        {
            MCCmdLineParams settings = new MCCmdLineParams();

            if (!Parser.ParseArgumentsWithUsage(args, settings))
            {
                return;
            }



            #region load the libraries
            List <Assembly> libs = new List <Assembly>();
            try
            {
                if (settings.reference != null)
                {
                    foreach (string l in settings.reference)
                    {
                        libs.Add(System.Reflection.Assembly.LoadFrom(l));
                    }
                }
            }
            catch (Exception e)
            {
                throw new ModelProgramUserException(e.Message);
            }
            #endregion

            #region load the test cases if any
            CompoundTerm goal = null;
            if (!String.IsNullOrEmpty(settings.goal))
            {
                try
                {
                    System.IO.StreamReader goalReader =
                        new System.IO.StreamReader(settings.goal);
                    string goalAsString = goalReader.ReadToEnd();
                    goalReader.Close();
                    goal = CompoundTerm.Parse(goalAsString);
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException("Cannot create goal: " + e.Message);
                }
            }
            else
            {
                Console.WriteLine("No goal was specified, counting distinct states and transitions.");
                Console.WriteLine("Invalid end states check currently not enabled.");
            }
            #endregion

            #region create a model program for each model using the factory method and compose into product
            string       mpMethodName;
            string       mpClassName;
            ModelProgram mp = null;
            if (settings.model != null && settings.model.Length > 0)
            {
                if (libs.Count == 0)
                {
                    throw new ModelProgramUserException("No reference was provided to load models from.");
                }
                ReflectionHelper.SplitFullMethodName(settings.model[0], out mpClassName, out mpMethodName);
                Type       mpType   = ReflectionHelper.FindType(libs, mpClassName);
                MethodInfo mpMethod = ReflectionHelper.FindMethod(mpType, mpMethodName, Type.EmptyTypes, typeof(ModelProgram));
                try
                {
                    mp = (ModelProgram)mpMethod.Invoke(null, null);
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException("Invocation of '" + settings.model[0] + "' failed: " + e.ToString());
                }
                for (int i = 1; i < settings.model.Length; i++)
                {
                    ReflectionHelper.SplitFullMethodName(settings.model[i], out mpClassName, out mpMethodName);
                    mpType   = ReflectionHelper.FindType(libs, mpClassName);
                    mpMethod = ReflectionHelper.FindMethod(mpType, mpMethodName, Type.EmptyTypes, typeof(ModelProgram));
                    ModelProgram mp2 = null;
                    try
                    {
                        mp2 = (ModelProgram)mpMethod.Invoke(null, null);
                    }
                    catch (Exception e)
                    {
                        throw new ModelProgramUserException("Invocation of '" + settings.model[i] + "' failed: " + e.ToString());
                    }
                    mp = new ProductModelProgram(mp, mp2);
                }
            }
            #endregion

            if (mp == null)
            {
                Console.WriteLine("ModelProgram was null");
                Console.WriteLine("Tried to instantiate:");
                if (settings.model != null)
                {
                    foreach (string s in settings.model)
                    {
                        Console.WriteLine(s);
                    }
                }
                return;
            }
            Reachability mc = new Reachability();
            mc.excludeIsomorphicStates = settings.excludeIsomorphic;
            mc.modelProgram            = mp;
            DateTime           before = DateTime.Now;
            ReachabilityResult result = mc.CheckReachability();
            DateTime           after  = DateTime.Now;
            Console.WriteLine("Results of reachability checking:");
            Console.WriteLine();
            Console.WriteLine(" States reached: " + result.StateCount);
            Console.WriteLine(" Transitions covered: " + result.TransitionCount);
        }
Esempio n. 25
0
 /// <summary>
 /// Creates a model stepper that uses coverage points (when != null) to direct the selection of actions.
 /// If coverage == null, uses default coverage points that are (state.GetHashCode(), action.GetHashCode()) pairs.
 /// Uses RewardPolicy.MaximumReward for action selection.
 /// </summary>
 /// <param name="modelProgram">given model program</param>
 /// <param name="coverage">given coverage point names (may be null)</param>
 public static MDPStrategy CreateMDPStrategy(ModelProgram modelProgram, string[] /*?*/ coverage)
 {
     //return new MDPStrategy(modelProgram,new Set<string>(coverage));
     return(new MDPStrategy(modelProgram));
 }
Esempio n. 26
0
 /// <summary>
 /// Constructs a model stepper for a given test suite and a given model program,
 /// using the product of the test suite and the model program.
 /// </summary>
 /// <param name="startTest">name of start action of a test case</param>
 /// <param name="testsuite">given test suite as a nonempty sequence of test cases</param>
 /// <param name="mp">given model program</param>
 public TestSuiteStepper(string startTest, Sequence <Sequence <CompoundTerm> > testsuite, ModelProgram mp)
     :
     base(CreateModelProgram(startTest, testsuite, mp))
 {
     if (testsuite == null ||
         testsuite.IsEmpty ||
         testsuite.Exists(delegate(Sequence <CompoundTerm> testcase)
     {
         return(testcase == null || testcase.IsEmpty);
     }))
     {
         throw new ConformanceTesterException("Invalid test suite, the test suite must be a nonempty sequence of nonempty action sequences.");
     }
     this.currentTest           = testsuite.Head.AddFirst((CompoundTerm)Term.Parse(startTest + "(" + 0 + ")"));
     this.testsuite             = testsuite.Tail;
     this.currentTestInProgress = false;
     this.testnr    = 1;
     this.startTest = startTest;
 }
Esempio n. 27
0
        static ModelProgram CreateModelProgram(string startTest, Sequence <Sequence <CompoundTerm> > testsuite, ModelProgram mp)
        {
            Set <Symbol> symbs = Set <Symbol> .EmptySet;

            foreach (Sequence <CompoundTerm> testcase in testsuite)
            {
                foreach (CompoundTerm action in testcase)
                {
                    symbs = symbs.Add(action.Symbol);
                }
            }
            FSM             fa    = FsmTraversals.GenerateTestSequenceAutomaton(startTest, testsuite, symbs);
            FsmModelProgram fsmmp = new FsmModelProgram(fa, "TestSuite");

            if (mp == null)
            {
                return(fsmmp);
            }
            else
            {
                return(new ProductModelProgram(fsmmp, mp));
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Provides programmatic access to the ModelProgramViewer commandline utility 'mpv.exe'.
        /// </summary>
        /// <param name="args">command line arguments: model program(s), optional settings for the viewer</param>
        /// <remarks>The settings are displayed when 'mpv.exe /?' is executed from the command line without arguments.</remarks>
        public static void RunWithCommandLineArguments(params string[] args)
        {
            ProgramSettings settings = new ProgramSettings();

            if (!Parser.ParseArgumentsWithUsage(args, settings))
            {
                return;
            }

            #region load the libraries
            List <Assembly> libs = new List <Assembly>();
            try
            {
                if (settings.reference != null)
                {
                    foreach (string l in settings.reference)
                    {
                        libs.Add(System.Reflection.Assembly.LoadFrom(l));
                    }
                }
            }
            catch (Exception e)
            {
                throw new ModelProgramUserException(e.Message);
            }
            #endregion

            #region create a model program for each model using the factory method and compose into product
            string       mpMethodName;
            string       mpClassName;
            ModelProgram mp = null;
            if (settings.model != null && settings.model.Length > 0)
            {
                if (libs.Count == 0)
                {
                    throw new ModelProgramUserException("No reference was provided to load models from.");
                }
                ReflectionHelper.SplitFullMethodName(settings.model[0], out mpClassName, out mpMethodName);
                Type       mpType   = ReflectionHelper.FindType(libs, mpClassName);
                MethodInfo mpMethod = ReflectionHelper.FindMethod(mpType, mpMethodName, Type.EmptyTypes, typeof(ModelProgram));
                try
                {
                    mp = (ModelProgram)mpMethod.Invoke(null, null);
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException("Invocation of '" + settings.model[0] + "' failed: " + e.ToString());
                }
                for (int i = 1; i < settings.model.Length; i++)
                {
                    ReflectionHelper.SplitFullMethodName(settings.model[i], out mpClassName, out mpMethodName);
                    mpType   = ReflectionHelper.FindType(libs, mpClassName);
                    mpMethod = ReflectionHelper.FindMethod(mpType, mpMethodName, Type.EmptyTypes, typeof(ModelProgram));
                    ModelProgram mp2 = null;
                    try
                    {
                        mp2 = (ModelProgram)mpMethod.Invoke(null, null);
                    }
                    catch (Exception e)
                    {
                        throw new ModelProgramUserException("Invocation of '" + settings.model[i] + "' failed: " + e.ToString());
                    }
                    mp = new ProductModelProgram(mp, mp2);
                }
            }
            #endregion

            #region create a model program from given namespace and feature names
            if (settings.mp != null && settings.mp.Length > 0)
            {
                if (libs.Count == 0)
                {
                    throw new ModelProgramUserException("No reference was provided to load models from.");
                }
                //parse the model program name and the feature names for each entry
                foreach (string mps in settings.mp)
                {
                    //the first element is the model program, the remaining ones are
                    //feature names
                    string[] mpsSplit = mps.Split(new string[] { "[", "]", "," },
                                                  StringSplitOptions.RemoveEmptyEntries);
                    if (mpsSplit.Length == 0)
                    {
                        throw new ModelProgramUserException("Invalid model program specifier '" + mps + "'.");
                    }
                    string       mpName     = mpsSplit[0];
                    Assembly     mpAssembly = ReflectionHelper.FindAssembly(libs, mpName);
                    Set <string> mpFeatures = new Set <string>(mpsSplit).Remove(mpName);
                    ModelProgram mp1        = new LibraryModelProgram(mpAssembly, mpName, mpFeatures);
                    mp = (mp == null ? mp1 : new ProductModelProgram(mp, mp1));
                }
            }

            #endregion

            #region load the test cases if any
            Sequence <Sequence <CompoundTerm> > testcases = Sequence <Sequence <CompoundTerm> > .EmptySequence;
            if (!String.IsNullOrEmpty(settings.testSuite))
            {
                try
                {
                    System.IO.StreamReader testSuiteReader =
                        new System.IO.StreamReader(settings.testSuite);
                    string testSuiteAsString = testSuiteReader.ReadToEnd();
                    testSuiteReader.Close();
                    CompoundTerm testSuite = CompoundTerm.Parse(testSuiteAsString);
                    foreach (CompoundTerm testCaseTerm in testSuite.Arguments)
                    {
                        Sequence <CompoundTerm> testCase =
                            testCaseTerm.Arguments.Convert <CompoundTerm>(delegate(Term t) { return((CompoundTerm)t); });
                        testcases = testcases.AddLast(testCase);
                    }
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException("Cannot create test suite: " + e.Message);
                }
            }
            #endregion

            #region load the fsms if any
            Dictionary <string, FSM> fsms = new Dictionary <string, FSM>();
            if (settings.fsm != null && settings.fsm.Length > 0)
            {
                try
                {
                    foreach (string fsmFile in settings.fsm)
                    {
                        System.IO.StreamReader fsmReader = new System.IO.StreamReader(fsmFile);
                        string fsmAsString = fsmReader.ReadToEnd();
                        fsmReader.Close();
                        fsms[fsmFile] = FSM.FromTerm(CompoundTerm.Parse(fsmAsString));
                    }
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException("Cannot create fsm: " + e.Message);
                }
            }
            #endregion

            if (mp == null && testcases.IsEmpty && fsms.Count == 0)
            {
                throw new ModelProgramUserException("No model, fsm, or test suite was given.");
            }

            if (!testcases.IsEmpty)
            {
                FSM fa = FsmTraversals.GenerateTestSequenceAutomaton(
                    settings.startTestAction, testcases, GetActionSymbols(testcases));
                ModelProgram famp = new FsmModelProgram(fa, settings.testSuite);
                if (mp == null)
                {
                    mp = famp;
                }
                else
                {
                    mp = new ProductModelProgram(mp, famp);
                }
            }

            if (fsms.Count > 0)
            {
                foreach (string fsmName in fsms.Keys)
                {
                    ModelProgram fsmmp = new FsmModelProgram(fsms[fsmName], fsmName);
                    if (mp == null)
                    {
                        mp = fsmmp;
                    }
                    else
                    {
                        mp = new ProductModelProgram(mp, fsmmp);
                    }
                }
            }

            ModelProgramGraphViewForm form = new ModelProgramGraphViewForm("Model Program Viewer");
            //configure the settings of the viewer
            form.View.AcceptingStatesMarked   = settings.acceptingStatesMarked;
            form.View.TransitionLabels        = settings.transitionLabels;
            form.View.CombineActions          = settings.combineActions;
            form.View.Direction               = settings.direction;
            form.View.UnsafeStateColor        = Color.FromName(settings.unsafeStateColor);
            form.View.HoverColor              = Color.FromName(settings.hoverColor);
            form.View.InitialStateColor       = Color.FromName(settings.initialStateColor);
            form.View.LoopsVisible            = settings.loopsVisible;
            form.View.MaxTransitions          = settings.maxTransitions;
            form.View.NodeLabelsVisible       = settings.nodeLabelsVisible;
            form.View.SelectionColor          = Color.FromName(settings.selectionColor);
            form.View.MergeLabels             = settings.mergeLabels;
            form.View.StateShape              = settings.stateShape;
            form.View.DeadStateColor          = Color.FromName(settings.deadStateColor);
            form.View.InitialTransitions      = settings.initialTransitions;
            form.View.LivenessCheckIsOn       = settings.livenessCheckIsOn;
            form.View.ExcludeIsomorphicStates = settings.excludeIsomorphicStates;
            form.View.SafetyCheckIsOn         = settings.safetyCheckIsOn;
            form.View.DeadstatesVisible       = settings.deadStatesVisible;
            form.View.StateViewVisible        = settings.stateViewVisible;

            //show the view of the product of all the model programs
            form.View.SetModelProgram(mp);

            form.OnSaveSettings += new EventHandler(settings.SaveSettings);
            form.ShowDialog();
        }
Esempio n. 29
0
 public frmLogin()
 {
     db = new ModelProgram();
     InitializeComponent();
 }
Esempio n. 30
0
 public frmSaida()
 {
     db = new ModelProgram();
     InitializeComponent();
 }