Exemple #1
0
 /// <summary>
 /// Prepare Simulation Environment
 /// </summary>
 /// <param name="debug">Enables AKKA-Global message Debugging</param>
 public GanttSimulation(string ganttContextDbString, string productionContextDbString, IMessageHub messageHub)
 {
     _ganttContext       = GanttPlanDBContext.GetContext(ganttContextDbString);
     _productionContext  = ProductionDomainContext.GetContext(productionContextDbString);
     _messageHub         = messageHub;
     _resourceDictionary = new ResourceDictionary();
 }
        static void Main(string[] args)
        {
            Console.WriteLine(value: "Welcome to AkkaSim Cli");


            var masterDb      = ProductionDomainContext.GetContext(defaultCon: ConfigurationManager.AppSettings[index: 0]);
            var validCommands = new Commands();
            var command       = validCommands.Single(predicate: x => x.ArgLong == "Help");
            var lastArg       = 0;
            var config        = new SimulationCore.Environment.Configuration();

            for (; lastArg < args.Length; lastArg++)
            {
                if (args[lastArg] == "-?" || args[lastArg] == "/?")
                {
                    command.Action(arg1: null, arg2: null);
                    return;
                }

                if (IsArg(validCommands: validCommands, argument: args[lastArg], command: ref command))
                {
                    if (command.HasProperty)
                    {
                        lastArg++;
                        command.Action(arg1: config, arg2: args[lastArg]);
                    }
                    else
                    {
                        command.Action(arg1: config, arg2: null);
                    }
                }
            }

            RunSimulationTask(masterDb: masterDb, config: config).Wait();
        }
Exemple #3
0
        public void TestGanttPlanApi()
        {
            ProductionDomainContext master40Context = ProductionDomainContext.GetContext(masterCtxString);

            GanttPlanDBContext ganttPlanContext = GanttPlanDBContext.GetContext(GanttPlanCtxString);
            var prod = ganttPlanContext.GptblProductionorder
                       .Include(x => x.ProductionorderOperationActivities)
                       .ThenInclude(x => x.ProductionorderOperationActivityMaterialrelation)
                       .Include(x => x.ProductionorderOperationActivities)
                       .ThenInclude(x => x.ProductionorderOperationActivityResources)
                       .Include(x => x.ProductionorderOperationActivities)
                       .ThenInclude(x => x.ProductionorderOperationActivityResources)
                       .ThenInclude(x => x.ProductionorderOperationActivityResourceInterval)
                       .Single(x => x.ProductionorderId == "000030");

            // System.Diagnostics.Debug.WriteLine("First ID: " + prod.ProductionorderId);
            // var activity = prod.ProductionorderOperationActivities.ToArray()[1];
            // System.Diagnostics.Debug.WriteLine("First Activity ID: " + activity.ActivityId);
            // var materialRelation = activity.ProductionorderOperationActivityMaterialrelation.ToArray()[0];
            // System.Diagnostics.Debug.WriteLine("First Activity Material Relation ID: " + materialRelation.ChildId);
            // var ress = activity.ProductionorderOperationActivityResources.ToArray()[0];
            // System.Diagnostics.Debug.WriteLine("First Resource: " + ress.Worker.Name);
            // System.Diagnostics.Debug.WriteLine("First Resource Intervall: " + ress.ProductionorderOperationActivityResourceInterval.DateFrom);
            var activities = ganttPlanContext.GptblProductionorderOperationActivity
                             .Include(x => x.ProductionorderOperationActivityResources)
                             .Where(x => x.ProductionorderId == "000029").ToList();

            activities.ForEach(act =>
            {
                System.Diagnostics.Debug.WriteLine("Activity:" + act.Name);
                act.ProductionorderOperationActivityResources.ForEach(res =>
                {
                    System.Diagnostics.Debug.WriteLine("Activity Resource:" + res.ResourceId);
                    switch (res.ResourceType)
                    {
                    case 1:
                        res.Resource =
                            ganttPlanContext.GptblWorkcenter.Single(x => x.WorkcenterId == res.ResourceId);
                        break;

                    case 3:
                        res.Resource =
                            ganttPlanContext.GptblWorker.Single(x => x.WorkerId == res.ResourceId);
                        break;

                    case 5:
                        res.Resource =
                            ganttPlanContext.GptblPrt.Single(x => x.PrtId == res.ResourceId);

                        break;
                    }
                    System.Diagnostics.Debug.WriteLine("Activity Resource Name:" + res.Resource.Name);
                });
            }
                               );


            Assert.True(ganttPlanContext.GptblMaterial.Any());
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Console.WriteLine(value: "Welcome to AkkaSim Cli");

            // has to be Installed here other wise it would attach a new log listener every time a simulation is called.
            LogConfiguration.LogTo(TargetTypes.Console, TargetNames.LOG_AGENTS, LogLevel.Info, LogLevel.Info);
            //LogConfiguration.LogTo(TargetTypes.File, TargetNames.LOG_AGENTS, LogLevel.Debug, LogLevel.Debug);
            //LogConfiguration.LogTo(TargetTypes.File, TargetNames.LOG_AKKA, LogLevel.Trace);
            //LogConfiguration.LogTo(TargetTypes.Console, TargetNames.LOG_AKKA, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AKKA, LogLevel.Warn);

            var masterDb      = ProductionDomainContext.GetContext(ConfigurationManager.AppSettings[AgentCore.DEFAULT_CONNECTION]);
            var validCommands = Commands.GetAllValidCommands;
            var command       = validCommands.Single(predicate: x => x.ArgLong == "Help");
            var lastArg       = 0;
            var config        = new SimulationCore.Environment.Configuration();

            for (; lastArg < args.Length; lastArg++)
            {
                if (args[lastArg] == "-?" || args[lastArg] == "/?")
                {
                    command.Action(arg1: null, arg2: null);
                    return;
                }

                if (ArgumentConverter.IsArg(validCommands: validCommands, argument: args[lastArg], command: ref command))
                {
                    if (command.HasProperty)
                    {
                        lastArg++;
                        command.Action(arg1: config, arg2: args[lastArg]);
                    }
                    else
                    {
                        command.Action(arg1: config, arg2: null);
                    }
                }
            }

            if (config.TryGetValue(typeof(StartHangfire), out object startHangfire))
            {
                StartHangfire(((StartHangfire)startHangfire).Silent).Wait();
            }
            else
            {
                RunSimulationTask(masterDb: masterDb, config: config).Wait();
                Console.WriteLine(value: "Simulation Run Finished.");
            }
        }
        public void SomethingToPlayWith()
        {
            var masterCtx = ProductionDomainContext.GetContext(testCtxString);
            var resources = masterCtx.Resources
                                       //.Where(x => x.Count == 1)
                                       // .Include(x => x.RequiresResourceSetups)
                                       //     .ThenInclude(x => x.ChildResource)
                                       // .Include(x => x.UsedInResourceSetups)
                                       //     .ThenInclude(x => x.ResourceCapability)
                            .ToList(); // all Resources

            foreach (var resource in resources)
            {
                GetSetups(resource, masterCtx);
            }
        }
        public async Task SystemTestAsync(int approachId
                                          , int orderQuantity
                                          , int maxBucketSize
                                          , long throughput
                                          , int seed
                                          , double arrivalRate
                                          , long simulationEnd)
        {
            ResultContext           ctxResult  = ResultContext.GetContext(resultCon: testResultCtxString);
            ProductionDomainContext masterCtx  = ProductionDomainContext.GetContext(testCtxString);
            DataGeneratorContext    dataGenCtx = DataGeneratorContext.GetContext(testGeneratorCtxString);

            var approach  = ApproachRepository.GetApproachById(dataGenCtx, approachId);
            var generator = new MainGenerator();
            await Task.Run(() =>
                           generator.StartGeneration(approach, masterCtx, ctxResult));

            var simContext = new AgentSimulation(DBContext: masterCtx, messageHub: new ConsoleHub());
            var simConfig  = ArgumentConverter.ConfigurationConverter(ctxResult, 1);

            //LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AGENTS, LogLevel.Trace, LogLevel.Trace);
            LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AGENTS, LogLevel.Info, LogLevel.Info);
            //LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AGENTS, LogLevel.Debug, LogLevel.Debug);
            //LogConfiguration.LogTo(TargetTypes.Debugger, CustomLogger.PRIORITY, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.File, CustomLogger.SCHEDULING, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.File, CustomLogger.DISPOPRODRELATION, LogLevel.Debug, LogLevel.Debug);
            //LogConfiguration.LogTo(TargetTypes.Debugger, CustomLogger.PROPOSAL, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.Debugger, CustomLogger.INITIALIZE, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.Debugger, CustomLogger.JOB, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.File, CustomLogger.ENQUEUE, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.Debugger, CustomLogger.JOBSTATE, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.File, TargetNames.LOG_AKKA, LogLevel.Trace, LogLevel.Trace);
            //LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AKKA, LogLevel.Warn);

            var dataGenSim = new DB.GeneratorModel.Simulation();

            dataGenSim.ApproachId = approachId;
            dataGenSim.StartTime  = DateTime.Now;
            await Task.Run(() =>
            {
                dataGenCtx.Simulations.AddRange(dataGenSim);
                dataGenCtx.SaveChanges();
            });

            // update customized Configuration
            simConfig.AddOption(new DBConnectionString(testResultCtxString));
            simConfig.ReplaceOption(new TimeConstraintQueueLength(480));
            simConfig.ReplaceOption(new OrderArrivalRate(value: arrivalRate));
            simConfig.ReplaceOption(new OrderQuantity(value: orderQuantity));
            simConfig.ReplaceOption(new EstimatedThroughPut(value: throughput));
            simConfig.ReplaceOption(new TimePeriodForThroughputCalculation(value: 2880));
            simConfig.ReplaceOption(new Seed(value: seed));
            simConfig.ReplaceOption(new SettlingStart(value: 0));
            simConfig.ReplaceOption(new SimulationEnd(value: simulationEnd));
            simConfig.ReplaceOption(new SaveToDB(value: true));
            simConfig.ReplaceOption(new MaxBucketSize(value: maxBucketSize));
            simConfig.ReplaceOption(new SimulationNumber(value: dataGenSim.Id));
            simConfig.ReplaceOption(new DebugSystem(value: true));
            simConfig.ReplaceOption(new WorkTimeDeviation(0.0));
            // anpassen der Lieferzeiten anhand der Erwarteten Durchlaufzeit.
            simConfig.ReplaceOption(new MinDeliveryTime(80));
            simConfig.ReplaceOption(new MaxDeliveryTime(150));

            await Task.Run(() =>
                           ArgumentConverter.ConvertBackAndSave(ctxResult, simConfig, dataGenSim.Id));

            var simulation = await simContext.InitializeSimulation(configuration : simConfig);


            if (simulation.IsReady())
            {
                // Start simulation
                var sim = simulation.RunAsync();
                simContext.StateManager.ContinueExecution(simulation);
                await sim;
                dataGenSim.FinishTime           = DateTime.Now;
                dataGenSim.FinishedSuccessfully = sim.IsCompletedSuccessfully;
                await Task.Run(() =>
                               dataGenCtx.SaveChanges());

                System.Diagnostics.Debug.WriteLine("################################# Simulation has finished with number " + dataGenSim.Id);
                Assert.True(condition: sim.IsCompleted);
            }
        }
Exemple #7
0
 public AgentCore()
 {
     _context       = ProductionDomainContext.GetContext(ConfigurationManager.AppSettings[DEFAULT_CONNECTION]);
     _resultContext = ResultContext.GetContext(ConfigurationManager.AppSettings[RESULT_CONNECTION]);
 }
Exemple #8
0
        //[InlineData(SimulationType.DefaultSetup, 1, Int32.MaxValue, 1920, 169, ModelSize.Small, ModelSize.Small)]
        public async Task CentralSystemTest()
        {
            //LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AGENTS, LogLevel.Trace, LogLevel.Trace);
            LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AGENTS, LogLevel.Info, LogLevel.Info);
            //LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AGENTS, LogLevel.Debug, LogLevel.Debug);
            LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AGENTS, LogLevel.Warn, LogLevel.Warn);

            var simtulationType = SimulationType.Central;
            var seed            = 169;
            var throughput      = 1920;
            var arrivalRate     = 0.015;

            //Create Master40Data
            var masterPlanContext = ProductionDomainContext.GetContext(masterCtxString);

            masterPlanContext.Database.EnsureDeleted();
            masterPlanContext.Database.EnsureCreated();
            MasterDBInitializerTruck.DbInitialize(masterPlanContext, ModelSize.Medium, ModelSize.Medium, ModelSize.Small, 3, false);

            //CreateMaster40Result
            var masterPlanResultContext = ResultContext.GetContext(masterResultCtxString);

            masterPlanResultContext.Database.EnsureDeleted();
            masterPlanResultContext.Database.EnsureCreated();
            ResultDBInitializerBasic.DbInitialize(masterPlanResultContext);

            //Reset GanttPLan DB?
            var ganttPlanContext = GanttPlanDBContext.GetContext(GanttPlanCtxString);

            ganttPlanContext.Database.ExecuteSqlRaw("EXEC sp_MSforeachtable 'DELETE FROM ? '");

            //Synchronisation GanttPlan
            GanttPlanOptRunner.RunOptAndExport("Init");

            var simContext = new GanttSimulation(GanttPlanCtxString, masterCtxString, messageHub: new ConsoleHub());
            var simConfig  = ArgumentConverter.ConfigurationConverter(masterPlanResultContext, 1);

            // update customized Items
            simConfig.AddOption(new DBConnectionString(masterResultCtxString));
            simConfig.ReplaceOption(new KpiTimeSpan(240));
            simConfig.ReplaceOption(new TimeConstraintQueueLength(480));
            simConfig.ReplaceOption(new SimulationKind(value: simtulationType));
            simConfig.ReplaceOption(new OrderArrivalRate(value: arrivalRate));
            simConfig.ReplaceOption(new OrderQuantity(value: 141));
            simConfig.ReplaceOption(new EstimatedThroughPut(value: throughput));
            simConfig.ReplaceOption(new TimePeriodForThroughputCalculation(value: 4000));
            simConfig.ReplaceOption(new Seed(value: seed));
            simConfig.ReplaceOption(new SettlingStart(value: 2880));
            simConfig.ReplaceOption(new SimulationEnd(value: 10080));
            simConfig.ReplaceOption(new SaveToDB(value: true));
            simConfig.ReplaceOption(new DebugSystem(value: false));
            simConfig.ReplaceOption(new WorkTimeDeviation(0.2));

            var simulation = await simContext.InitializeSimulation(configuration : simConfig);

            //emtpyResultDBbySimulationNumber(simNr: simConfig.GetOption<SimulationNumber>());

            var simWasReady = false;

            if (simulation.IsReady())
            {
                // set for Assert
                simWasReady = true;
                // Start simulation
                var sim = simulation.RunAsync();
                simContext.StateManager.ContinueExecution(simulation);
                await sim;
            }

            Assert.True(condition: simWasReady);
        }
Exemple #9
0
        public void GanttPlanInsertConfirmationAndReplan()
        {
            ProductionDomainContext master40Context = ProductionDomainContext.GetContext(masterCtxString);

            master40Context.CustomerOrders.RemoveRange(master40Context.CustomerOrders);
            master40Context.CustomerOrderParts.RemoveRange(master40Context.CustomerOrderParts);
            master40Context.SaveChanges();

            master40Context.CreateNewOrder(10115, 1, 0, 250);
            master40Context.SaveChanges();

            GanttPlanDBContext ganttPlanContext = GanttPlanDBContext.GetContext(GanttPlanCtxString);

            ganttPlanContext.Database.ExecuteSqlRaw("EXEC sp_MSforeachtable 'DELETE FROM ? '");
            GanttPlanOptRunner.RunOptAndExport("Init");

            Assert.True(ganttPlanContext.GptblProductionorder.Any());

            ganttPlanContext.GptblConfirmation.RemoveRange(ganttPlanContext.GptblConfirmation);
            var productionorder = ganttPlanContext.GptblProductionorder.Single(x => x.ProductionorderId.Equals("000004"));

            ganttPlanContext.GptblConfirmation.RemoveRange(ganttPlanContext.GptblConfirmation);

            var activities = ganttPlanContext.GptblProductionorderOperationActivity.Where(x =>
                                                                                          x.ProductionorderId.Equals(productionorder.ProductionorderId));

            var activity     = activities.Single(x => x.OperationId.Equals("10") && x.ActivityId.Equals(2));
            var confirmation = CreateConfirmation(activity, productionorder, 1);

            ganttPlanContext.GptblConfirmation.Add(confirmation);

            ganttPlanContext.SaveChanges();

            GanttPlanOptRunner.RunOptAndExport("Continuous");

            Assert.True(ganttPlanContext.GptblConfirmation.Any());

            confirmation = ganttPlanContext.GptblConfirmation.SingleOrDefault(x =>
                                                                              x.ConfirmationId.Equals(confirmation.ConfirmationId));
            //ganttPlanContext.GptblConfirmation.Remove(confirmation);
            var finishConfirmation = CreateConfirmation(activity, productionorder, 16);

            ganttPlanContext.SaveChanges();

            ganttPlanContext.GptblConfirmation.Add(finishConfirmation);

            activity = activities.Single(x => x.OperationId.Equals("10") && x.ActivityId.Equals(3));

            confirmation = CreateConfirmation(activity, productionorder, 16);

            ganttPlanContext.GptblConfirmation.Add(confirmation);

            activity = activities.Single(x => x.OperationId.Equals("20") && x.ActivityId.Equals(2));

            confirmation = CreateConfirmation(activity, productionorder, 16);
            ganttPlanContext.GptblConfirmation.Add(confirmation);

            ganttPlanContext.SaveChanges();

            GanttPlanOptRunner.RunOptAndExport("Continuous");

            Assert.True(ganttPlanContext.GptblProductionorder.Count().Equals(10));
        }
        public async Task SystemTestAsync(SimulationType simulationType, int simNr, int maxBucketSize, long throughput,
                                          int seed
                                          , ModelSize resourceModelSize, ModelSize setupModelSize
                                          , double arrivalRate, bool distributeSetupsExponentially)
        {
            LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AGENTS, LogLevel.Trace, LogLevel.Trace);
            LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AGENTS, LogLevel.Info, LogLevel.Info);
            LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AGENTS, LogLevel.Debug, LogLevel.Debug);
            //LogConfiguration.LogTo(TargetTypes.Debugger, CustomLogger.PRIORITY, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.File, CustomLogger.SCHEDULING, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.File, CustomLogger.DISPOPRODRELATION, LogLevel.Debug, LogLevel.Debug);
            //LogConfiguration.LogTo(TargetTypes.Debugger, CustomLogger.PROPOSAL, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.Debugger, CustomLogger.INITIALIZE, LogLevel.Warn, LogLevel.Warn);
            LogConfiguration.LogTo(TargetTypes.Debugger, CustomLogger.JOB, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.File, CustomLogger.ENQUEUE, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.Debugger, CustomLogger.JOBSTATE, LogLevel.Warn, LogLevel.Warn);
            //LogConfiguration.LogTo(TargetTypes.File, TargetNames.LOG_AKKA, LogLevel.Trace, LogLevel.Trace);
            //LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AKKA, LogLevel.Warn);

            var masterCtx = ProductionDomainContext.GetContext(testCtxString);

            masterCtx.Database.EnsureDeleted();
            masterCtx.Database.EnsureCreated();
            MasterDBInitializerTruck.DbInitialize(masterCtx, resourceModelSize, setupModelSize, ModelSize.Small, 3, distributeSetupsExponentially);
            //InMemoryContext.LoadData(source: _masterDBContext, target: _ctx);
            var simContext = new AgentSimulation(DBContext: masterCtx, messageHub: new ConsoleHub());
            var simConfig  = Simulation.CLI.ArgumentConverter.ConfigurationConverter(_ctxResult, 1);

            // update customized Items
            simConfig.AddOption(new DBConnectionString(testResultCtxString));
            simConfig.ReplaceOption(new TimeConstraintQueueLength(480));
            simConfig.ReplaceOption(new SimulationKind(value: simulationType));
            simConfig.ReplaceOption(new OrderArrivalRate(value: arrivalRate));
            simConfig.ReplaceOption(new OrderQuantity(value: 5));
            simConfig.ReplaceOption(new EstimatedThroughPut(value: throughput));
            simConfig.ReplaceOption(new TimePeriodForThroughputCalculation(value: 2880));
            simConfig.ReplaceOption(new Seed(value: seed));
            simConfig.ReplaceOption(new SettlingStart(value: 0));
            simConfig.ReplaceOption(new SimulationEnd(value: 2880));
            simConfig.ReplaceOption(new SaveToDB(value: true));
            simConfig.ReplaceOption(new MaxBucketSize(value: maxBucketSize));
            simConfig.ReplaceOption(new SimulationNumber(value: simNr));
            simConfig.ReplaceOption(new DebugSystem(value: true));
            simConfig.ReplaceOption(new WorkTimeDeviation(0.0));

            var simulation = await simContext.InitializeSimulation(configuration : simConfig);

            emtpyResultDBbySimulationNumber(simNr: simConfig.GetOption <SimulationNumber>());


            var simWasReady = false;

            if (simulation.IsReady())
            {
                // set for Assert
                simWasReady = true;
                // Start simulation
                var sim = simulation.RunAsync();
                simContext.StateManager.ContinueExecution(simulation);
                await sim;
            }

            Assert.True(condition: simWasReady);
        }