Example #1
0
        public void GenerateData() //Generierung für Simulation direkt im Testfall, wo Simulation durchgeführt wird
        {
            for (var i = 5; i < 6; i++)
            {
                var approachId     = i;
                var generatorDbCtx = DataGeneratorContext.GetContext(testGeneratorCtxString);
                var approach       = ApproachRepository.GetApproachById(generatorDbCtx, approachId);

                /*var parameterSet = ParameterSet.Create(new object[] { Dbms.GetNewMasterDataBase(false, "Master40") });
                 * var dataBase = parameterSet.GetOption<DataBase<ProductionDomainContext>>();*/

                var dbContext     = MasterDBContext.GetContext(testCtxString);
                var resultContext = ResultContext.GetContext(testResultCtxString);

                var generator = new MainGenerator();
                generator.StartGeneration(approach, dbContext, resultContext, true);
            }
            Assert.True(true);
        }
Example #2
0
        public void VerifySimulatedData(MasterDBContext dbContext, DataGeneratorContext dbGeneratorCtx,
                                        ResultContext dbResultCtx, int simNumber)
        {
            var simulation = SimulationRepository.GetSimulationById(simNumber, dbGeneratorCtx);

            if (simulation != null)
            {
                var approach = ApproachRepository.GetApproachById(dbGeneratorCtx, simulation.ApproachId);
                if (approach.TransitionMatrixInput.ExtendedTransitionMatrix)
                {
                    var generator = new MainGenerator();
                    generator.StartGeneration(approach, dbContext, dbResultCtx);

                    var articleCount =
                        ArticleRepository.GetArticleNamesAndCountForEachUsedArticleInSimulation(dbResultCtx, simNumber);

                    var articlesByNames =
                        ArticleRepository.GetArticlesByNames(articleCount.Keys.ToHashSet(), dbContext);
                    var capabilities = ResourceCapabilityRepository.GetParentResourceCapabilities(dbContext);

                    var actualTransitionMatrix = new TransitionMatrix
                    {
                        Pi = new double[capabilities.Count + 1, capabilities.Count + 1]
                    };

                    var capPosByCapId = new Dictionary <int, int>();
                    foreach (var cap in capabilities)
                    {
                        var number = cap.Name.Substring(0, cap.Name.IndexOf(" "));
                        var pos    = AlphabeticNumbering.GetNumericRepresentation(number);
                        capPosByCapId.Add(cap.Id, pos);
                    }

                    foreach (var a in articlesByNames)
                    {
                        var operations = a.Value.Operations.ToList();
                        operations.Sort((o1, o2) => o1.HierarchyNumber.CompareTo(o2.HierarchyNumber));

                        var operationCount = 0;
                        var lastCapPos     = 0;
                        do
                        {
                            var capPos =
                                capPosByCapId[
                                    operations[operationCount].ResourceCapability.ParentResourceCapability.Id];
                            actualTransitionMatrix.Pi[lastCapPos, capPos] += articleCount[a.Key];
                            lastCapPos = capPos + 1;
                            operationCount++;
                        } while (operationCount < operations.Count);

                        actualTransitionMatrix.Pi[lastCapPos, capabilities.Count] += articleCount[a.Key];
                    }

                    for (var i = 0; i <= capabilities.Count; i++)
                    {
                        var sum = 0.0;
                        for (var j = 0; j <= capabilities.Count; j++)
                        {
                            sum += actualTransitionMatrix.Pi[i, j];
                        }

                        for (var j = 0; j <= capabilities.Count; j++)
                        {
                            actualTransitionMatrix.Pi[i, j] /= sum;
                        }
                    }

                    var transitionMatrixGenerator = new TransitionMatrixGenerator();
                    ActualOrganizationDegree = transitionMatrixGenerator.CalcOrganizationDegree(
                        actualTransitionMatrix.Pi,
                        capabilities.Count + 1);
                    GeneratedOrganizationDegree = transitionMatrixGenerator.CalcOrganizationDegree(
                        generator.TransitionMatrix.Pi,
                        capabilities.Count + 1);

                    System.Diagnostics.Debug.WriteLine("################################# Executed work plans have an organization degree of " + ActualOrganizationDegree + " (transition matrix has " + GeneratedOrganizationDegree + "; input was " + approach.TransitionMatrixInput.DegreeOfOrganization + ")");
                }
            }
        }
        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);
            }
        }