Beispiel #1
0
            public static void Run()
            {
                IModel m = new Highpoint.Sage.SimCore.Model("Demo Model");

                Highpoint.Sage.SimCore.StateMachine sm = m.StateMachine;
                sm.TransitionCompletedSuccessfully +=
                    (model, data) =>
                    Console.WriteLine("Model transitioned successfully to the {0} state.", m.StateMachine.State);

                string[] stateNames = Enum.GetNames(sm.State.GetType());
                Console.WriteLine("State machine's default states are {0}",
                                  StringOperations.ToCommasAndAndedList(stateNames));

                DateTime startDateTime = DateTime.Parse("Fri, 15 Jul 2016 00:00:00");

                Console.WriteLine("Registering an event to run in the model at {0}",
                                  StringOperations.ToCommasAndAndedList(stateNames));
                m.Executive.RequestEvent(
                    (exec, data) =>
                    Console.WriteLine("{0} : While running, Model state is {1}.", exec.Now, m.StateMachine.State),
                    startDateTime);

                Console.WriteLine("Before starting, model state is {0}.", m.StateMachine.State);
                m.Start();
                Console.WriteLine("After completion, model state is {0}.", m.StateMachine.State);
            }
Beispiel #2
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);

                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));
                }
            }
Beispiel #3
0
            public static void Run()
            {
                // Create the model.
                Highpoint.Sage.SimCore.Model m = new Highpoint.Sage.SimCore.Model("Model");

                // Add the model objects to it.
                List <StateAwareDemoObject> tools = new List <StateAwareDemoObject>();

                foreach (string name in new[] { "Drill", "Welder", "Rinse" })
                {
                    StateAwareDemoObject tool = new StateAwareDemoObject(m, name, 10 /* run ten jobs. */);
                    tools.Add(tool);
                    m.AddModelObject(tool);
                }

                m.Start();

                tools.ForEach(o => Console.WriteLine(o.StateReport));
            }
Beispiel #4
0
            public static void Run()
            {
                Highpoint.Sage.SimCore.Model model = new Highpoint.Sage.SimCore.Model();
                MotorPool mp = new MotorPool(model);

                foreach (int passengerCapacity in new[] { 1, 3, 4, 7, 9 })
                {
                    mp.Add(new Vehicle(model, passengerCapacity));
                }
                Console.WriteLine("Stocked a motor pool with {0} seat vehicles.\r\n",
                                  StringOperations.ToCommasAndAndedList(mp.Resources.Cast <Vehicle>(),
                                                                        vehicle => vehicle.PassengerCapacity.ToString()));

                foreach (int[] requisitions in new[] { new[] { 1, 3, 4 }, new[] { 2, 5, 7 }, new[] { 1, 5, 8 }, new[] { 8, 1, 6 }, new[] { 8, 7, 6 }, new[] { 1, 3, 4, 7, 8, 9 } })
                {
                    Console.WriteLine("\r\nTest:");
                    List <VehicleRequest> requests = requisitions.Select(requisition => new VehicleRequest(requisition)).ToList();

                    foreach (VehicleRequest vehicleRequest in requests)
                    {
                        Console.Write("Requested a {0} seat vehicle. ", vehicleRequest.SeatsNeeded);
                        if (vehicleRequest.Acquire(mp, false))
                        {
                            Console.WriteLine(" Got a vehicle with {0} seats.", ((Vehicle)vehicleRequest.ResourceObtained).PassengerCapacity);
                        }
                        else
                        {
                            Console.WriteLine(" Motor pool had nothing satisfactory.");
                        }
                    }

                    foreach (VehicleRequest vehicleRequest in requests.Where(n => n.ResourceObtained != null))
                    {
                        vehicleRequest.Release();
                    }
                }
            }