示例#1
0
            public static void Run()
            {
                Highpoint.Sage.SimCore.Model model = new Highpoint.Sage.SimCore.Model("TaskGraph 1", Guid.NewGuid());
                DateTime  startTime     = new DateTime(2001, 3, 5, 7, 9, 11);
                Hashtable graphContext1 = new Hashtable();
                TestTask  makeBrownies  = new TestTask(model, "Make Brownies", 0);

                TestTask prepareOven = new TestTask(model, "Prepare Oven", 7);

                TestTask preparePan = new TestTask(model, "Prepare Pan", 0);
                TestTask acquirePan = new TestTask(model, "Acquire Pan", 2);
                TestTask greasePan  = new TestTask(model, "Grease Pan", 2);

                TestTask assembleBrownies   = new TestTask(model, "Assemble Brownies", 0);
                TestTask acquireIngredients = new TestTask(model, "Acquire Ingredients", 45);
                TestTask mixIngredients     = new TestTask(model, "Mix Ingredients", 45);
                TestTask pourBatter         = new TestTask(model, "Pour Batter", 45);

                TestTask bakeBrownies      = new TestTask(model, "Bake Brownies", 0);
                TestTask putPanInOven      = new TestTask(model, "Put Pan In Oven", .5);
                TestTask waitForCookTime   = new TestTask(model, "Wait for Cook Time", 45);
                TestTask removePanFromOven = new TestTask(model, "Remove Pan From Oven", 2);

                makeBrownies.AddChildEdges(new [] { prepareOven, preparePan, assembleBrownies, bakeBrownies }); // We'll allow them to proceed in parallel.
                preparePan.AddChainOfChildren(new[] { acquirePan, greasePan });                                 // These happen in series.
                assembleBrownies.AddChainOfChildren(new[] { acquireIngredients, mixIngredients, pourBatter });  // These happen in series.
                bakeBrownies.AddChainOfChildren(new[] { putPanInOven, waitForCookTime, removePanFromOven });    // These happen in series.

                bakeBrownies.AddPredecessor(preparePan);
                bakeBrownies.AddPredecessor(assembleBrownies);

//                CpmAnalyst cpa = new CpmAnalyst(bakeBrownies);
//                cpa.Analyze();

                model.Starting += delegate(IModel theModel)
                {
                    theModel.Executive.RequestEvent((exec, data) => makeBrownies.Start(graphContext1), startTime);
                };

                model.Start();

                Console.WriteLine("\r\nPost-run analysis:\r\n");

                foreach (TestTask testTask in new[] { prepareOven, mixIngredients, putPanInOven, waitForCookTime })
                {
                    Console.WriteLine("It was recorded that {0} started at {1} and took {2}.", testTask.Name,
                                      testTask.GetStartTime(graphContext1), testTask.GetRecordedDuration(graphContext1));
                }

                Console.WriteLine("\n\n\n\n\n");
                //And if you want to alter the task graph, and run the model again...
                TestTask hollerComeAndGetItTask = new TestTask(model, "<Top of Lungs>Holler \"COME AND GET IT!!!\"", 1);

                removePanFromOven.RemoveSuccessor(bakeBrownies);
                removePanFromOven.AddSuccessor(hollerComeAndGetItTask);
                bakeBrownies.AddCofinish(hollerComeAndGetItTask);

                graphContext1.Clear();
                model.Reset();

                model.Start();
            }