Exemple #1
0
        private static void RunSimulation()
        {
            LogConfiguration.LogTo(TargetTypes.File, TargetNames.LOG_AGENTS, LogLevel.Info, LogLevel.Warn);
            LogConfiguration.LogTo(TargetTypes.Console, TargetNames.LOG_AGENTS, LogLevel.Info);
            LogConfiguration.LogTo(TargetTypes.Console, TargetNames.LOG_AKKA, LogLevel.Warn);
            LogConfiguration.LogTo(TargetTypes.File, TargetNames.LOG_AKKA, LogLevel.Trace);
            //InternalLogger.LogToConsole = true;
            //InternalLogger.LogLevel = LogLevel.Trace;

            SimulationConfig simConfig = new SimulationConfig(debugAkka: false
                                                              , debugAkkaSim: true
                                                              , interruptInterval: 120
                                                              , timeToAdvance: TimeSpan.FromSeconds(0));
            var sim = new Simulation(simConfig);
            var r   = new Random();

            Console.ReadKey();

            var jobDistributor =
                sim.ActorSystem.ActorOf(MachineJobDistributor.Props(sim.ActorSystem.EventStream, sim.SimulationContext, 0),
                                        "JobDistributor");

            // Tell all Machines
            for (int i = 0; i < 3; i++)
            {
                // Create a message
                var createMachines = new MachineJobDistributor.AddMachine(null, jobDistributor);
                sim.SimulationContext.Tell(createMachines, null);
            }

            for (int i = 0; i < 300; i++)
            {
                var materialRequest = new MaterialRequest(CreateBOM(), new Dictionary <int, bool>(), 0, r.Next(50, 500), true);
                var request         = new MachineJobDistributor.ProductionOrder(materialRequest, jobDistributor);
                sim.SimulationContext.Tell(request, null);
            }

            // example to monitor for FinishWork Messages.

            var monitor = sim.ActorSystem.ActorOf(props: Monitoring.WorkTimeMonitor
                                                  .Props(time: 0),
                                                  name: "SimulationMonitor");

            if (sim.IsReady())
            {
                var terminated = sim.RunAsync();
                new StateManager().Continuation(simConfig.Inbox, sim);
                terminated.Wait();
            }

            Console.WriteLine("Systen is shutdown!");
            Console.WriteLine("System Runtime " + sim.ActorSystem.Uptime);
        }
Exemple #2
0
        private static void Run()
        {
            Console.WriteLine("Simulation world of Akka!");

            SimulationConfig simConfig = new SimulationConfig(false, 480);
            var sim = new Simulation(simConfig);
            var r   = new Random();

            Console.ReadKey();

            var jobDistributor = sim.ActorSystem.ActorOf(MachineJobDistributor.Props(sim.ActorSystem.EventStream, sim.SimulationContext, 0), "JobDistributor");
            // Create a message
            var createMachines = new MachineJobDistributor.AddMachine(null, jobDistributor);

            // Tell all Machines
            for (int i = 0; i < 10; i++)
            {
                sim.SimulationContext.Tell(createMachines, null);
            }

            for (int i = 0; i < 3000; i++)
            {
                var materialRequest = new MaterialRequest(CreateBOM(), new Dictionary <int, bool>(), 0, r.Next(50, 500), true);
                var request         = new MachineJobDistributor.ProductionOrder(materialRequest, jobDistributor);
                sim.SimulationContext.Tell(request, null);
            }

            // example to monitor for FinishWork Messages.

            var monitor = sim.ActorSystem.ActorOf(props: Monitoring.WorkTimeMonitor
                                                  .Props(time: 0),
                                                  name: "SimulationMonitor");
            var stw = new Stopwatch();

            stw.Start();

            if (sim.IsReady())
            {
                sim.RunAsync();
                //Continuation(simConfig.Inbox, sim);
            }



            Console.WriteLine("Systen shutdown. . . ");
            Console.WriteLine("System Runtime " + sim.ActorSystem.Uptime);

            Console.ReadLine();
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Simulation world of Akka!");

            var sim = new Simulation(false);
            var r   = new Random();

            Console.ReadKey();

            var jobDistributor = sim.ActorSystem.ActorOf(MachineJobDistributor.Props(sim.ActorSystem.EventStream, sim.SimulationContext, 0), "JobDistributor");
            // Create a message
            var createMachines = new MachineJobDistributor.AddMachine(null, jobDistributor);

            // Tell all Machines
            for (int i = 0; i < 10; i++)
            {
                sim.SimulationContext.Tell(createMachines, null);
            }

            for (int i = 0; i < 200; i++)
            {
                var materialRequest = new MaterialRequest(CreateBOM(), new Dictionary <int, bool>(), 0, r.Next(50, 500), true);
                var request         = new MachineJobDistributor.ProductionOrder(materialRequest, jobDistributor);
                sim.SimulationContext.Tell(request, null);
            }

            // example to monitor for FinishWork Messages.

            var monitor = sim.ActorSystem.ActorOf(props: Monitoring.WorkTimeMonitor
                                                  .Props(time: 0),
                                                  name: "SimulationMonitor");
            var stw = new Stopwatch();

            stw.Start();


            sim.RunAsync().Wait();

            Console.WriteLine("System Runtime " + sim.ActorSystem.Uptime);
            Console.WriteLine("Final Call Finisch Done Forever Together And So On");
            Console.ReadLine();
        }