Example #1
0
 public override string ToString()
 {
     if (Success)
     {
         return(string.Join(Environment.NewLine,
                            $"Scenario {Name}: going from {Path.First()} to {Path.Last()}.",
                            $"The result length of path is:   {PathLength}.",
                            $"The expected length of path is: {CorrectPathLength}",
                            $"The % increase of the result length: {PathLength.PercentageDifference(CorrectPathLength)}%",
                            Path.ToCollectionString()));
     }
     return(ErrorMessage);
 }
        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(PathLength.ToString() + newLine);

            for (int i = Path.Count - 1; i >= 0; --i)
            {
                stringBuilder.Append(Path[i].ToString() + ' ');
            }

            return(stringBuilder.ToString());
        }
Example #3
0
        [TestMethod] public void TestBaseFunctionality()
        {
            long oneDay  = TimeSpan.FromDays(1.0).Ticks;
            long oneHour = TimeSpan.FromHours(1.0).Ticks;

            Model model = new Model();

            model.AddService <ITaskManagementService>(new TaskManagementService());

            Task[] tasks = new Task[] { new MyTask(model, 0), new DelayTask(model, 1, oneDay), new MyTask(model, 2), new DelayTask(model, 3, oneHour) };

            int[] from = new int[] { 0, 0, 1, 2 }; //,4,5,6,7,8};
            int[] to   = new int[] { 1, 3, 2, 3 }; //,4,6,5,9,1};

            ArrayList childTasks = new ArrayList();

            foreach (Task task in tasks)
            {
                childTasks.Add(task);
            }

            for (int ndx = 0; ndx < to.Length; ndx++)
            {
                Task taskA = (Task)((Edge)childTasks[from[ndx]]);
                Task taskB = (Task)((Edge)childTasks[to[ndx]]);

                Debug.WriteLine(String.Format("Considering a connection between {0} and {1}.", taskA.Name, taskB.Name));

                int forward  = PathLength.ShortestPathLength(taskA, taskB);
                int backward = PathLength.ShortestPathLength(taskB, taskA);

                Debug.WriteLine(String.Format("Forward path length is {0}, and reverse path length is {1}.", forward, backward));

                if ((forward == int.MaxValue) && (backward == int.MaxValue))
                {
                    taskA.AddSuccessor(taskB);
                    Debug.WriteLine(String.Format("{0} will follow {1}.", taskB.Name, taskA.Name));
                }
                else if ((forward != int.MaxValue) && (backward == int.MaxValue))
                {
                    taskA.AddSuccessor(taskB);
                    Debug.WriteLine(String.Format("{0} will follow {1}.", taskB.Name, taskA.Name));
                }
                else if ((forward == int.MaxValue) && (backward != int.MaxValue))
                {
                    taskB.AddSuccessor(taskA);
                    Debug.WriteLine(String.Format("{1} will follow {0}.", taskB.Name, taskA.Name));
                }
                else
                {
                    throw new ApplicationException("Cycle exists between " + taskA.Name + " and " + taskB.Name + ".");
                }
            }

            Task topTask = new Task(model, "Parent", Guid.NewGuid());

            topTask.AddChildEdges(childTasks);
            TaskProcessor tp = new TaskProcessor(model, "Task Processor", topTask);

            tp.SetStartTime(DateTime.Now);
            model.GetService <ITaskManagementService>().AddTaskProcessor(tp);

            model.StateMachine.InboundTransitionHandler(model.GetStartEnum()).Commit += new CommitTransitionEvent(OnModelStarting);

            model.Start();
            if (model.StateMachine.State.Equals(StateMachine.GenericStates.Running))
            {
                Debug.WriteLine("Error attempting to transition to Started state.");
            }
        }