Exemplo n.º 1
0
        public static void DbInitialize(MasterDBContext context, ModelSize resourceModelSize, ModelSize setupModelSize, ModelSize operatorsModelSize, int numberOfWorkersForProcessing, bool secondResource, bool distributeSetupsExponentially = false)
        {
            context.Database.EnsureCreated();

            // Look for any Entrys.
            if (context.Articles.Any())
            {
                return;   // DB has been seeded
            }
            var resourceCapabilities = MasterTableResourceCapability(context, resourceModelSize, setupModelSize, operatorsModelSize, numberOfWorkersForProcessing, secondResource);

            // Article Definitions
            var units = new MasterTableUnit();

            units.Init(context);
            var articleTypes = new MasterTableArticleType();

            articleTypes.Init(context);

            // requires Units and Article Types
            var articleTable = new MasterTableArticle(articleTypes, units);
            var articles     = articleTable.Init(context);

            MasterTableStock.Init(context, articles);

            var operations = new MasterTableOperation(articleTable, resourceCapabilities, distributeSetupsExponentially);

            operations.Init(context);

            var boms = new MasterTableBom();

            boms.Init(context, articleTable, operations);

            var businessPartner = new MasterTableBusinessPartner();

            businessPartner.Init(context);

            context.SaveChanges();

            var articleToBusinessPartner = new MasterTableArticleToBusinessPartner();

            articleToBusinessPartner.Init(context, businessPartner, articleTable);

            var updateArticleLotSize = context.Articles
                                       .Include(x => x.ArticleType)
                                       .Include(x => x.ArticleToBusinessPartners)
                                       .ToList();

            // TODO noch gemogelt LotSize != PackSize
            foreach (var article in updateArticleLotSize)
            {
                if (article.ToPurchase)
                {
                    article.LotSize = article.ArticleToBusinessPartners.First().PackSize;
                }
            }
            DbUtils.InsertOrUpdateRange(updateArticleLotSize, context.Articles, context);
            context.SaveChanges();
        }
Exemplo n.º 2
0
        public void Init(MasterDBContext dbContext, M_Article[] articleTable, MasterTableBusinessPartner businessPartner)
        {
            List <M_ArticleToBusinessPartner> articleToBusinessPartners = new List <M_ArticleToBusinessPartner>();

            foreach (var article in articleTable)
            {
                articleToBusinessPartners.Add(new M_ArticleToBusinessPartner()
                {
                    BusinessPartnerId = businessPartner.KREDITOR_MATERIAL_WHOLSALE.Id,
                    ArticleId         = article.Id,
                    PackSize          = 10,
                    Price             = 20.00,
                    TimeToDelivery    = 480
                });
            }

            dbContext.ArticleToBusinessPartners.AddRange(articleToBusinessPartners);
            dbContext.SaveChanges();
        }
Exemplo n.º 3
0
        public void StartGeneration(Approach approach, MasterDBContext dbContext, ResultContext resultContext, bool doVerify = false)
        {
            dbContext.Database.EnsureDeleted();
            dbContext.Database.EnsureCreated();

            var rng = new XRandom(approach.Seed);

            var units        = new MasterTableUnit();
            var unitCol      = units.Init(dbContext);
            var articleTypes = new MasterTableArticleType();

            articleTypes.Init(dbContext);

            var productStructureGenerator = new ProductStructureGenerator();
            var productStructure          = productStructureGenerator.GenerateProductStructure(approach.ProductStructureInput,
                                                                                               articleTypes, units, unitCol, rng);

            ArticleInitializer.Init(productStructure.NodesPerLevel, dbContext);

            var articleTable = dbContext.Articles.ToArray();

            MasterTableStock.Init(dbContext, articleTable);

            var transitionMatrixGenerator = new TransitionMatrixGenerator();

            TransitionMatrix = transitionMatrixGenerator.GenerateTransitionMatrix(approach.TransitionMatrixInput,
                                                                                  approach.ProductStructureInput, rng);

            List <ResourceProperty> resourceProperties = approach.TransitionMatrixInput.WorkingStations
                                                         .Select(x => (ResourceProperty)x).ToList();

            var resourceCapabilities = ResourceInitializer.Initialize(dbContext, resourceProperties);

            var operationGenerator = new OperationGenerator();

            operationGenerator.GenerateOperations(productStructure.NodesPerLevel, TransitionMatrix,
                                                  approach.TransitionMatrixInput, resourceCapabilities, rng);
            OperationInitializer.Init(productStructure.NodesPerLevel, dbContext);

            var billOfMaterialGenerator = new BillOfMaterialGenerator();

            billOfMaterialGenerator.GenerateBillOfMaterial(approach.BomInput, productStructure.NodesPerLevel,
                                                           TransitionMatrix, units, rng);
            BillOfMaterialInitializer.Init(productStructure.NodesPerLevel, dbContext);

            var businessPartner = new MasterTableBusinessPartner();

            businessPartner.Init(dbContext);

            var articleToBusinessPartner = new ArticleToBusinessPartnerInitializer();

            articleToBusinessPartner.Init(dbContext, articleTable, businessPartner);


            if (doVerify)
            {
                var productStructureVerifier = new ProductStructureVerifier();
                productStructureVerifier.VerifyComplexityAndReutilizationRation(approach.ProductStructureInput,
                                                                                productStructure);

                if (approach.TransitionMatrixInput.ExtendedTransitionMatrix)
                {
                    var transitionMatrixGeneratorVerifier = new TransitionMatrixGeneratorVerifier();
                    transitionMatrixGeneratorVerifier.VerifyGeneratedData(TransitionMatrix,
                                                                          productStructure.NodesPerLevel, resourceCapabilities);
                }
            }

            //##### TEMP
            var incomingEdgeCount = 0;

            foreach (var level in productStructure.NodesPerLevel)
            {
                foreach (var node in level)
                {
                    incomingEdgeCount += node.Value.IncomingEdges.Count;
                }
            }

            var actualCR = incomingEdgeCount / (1.0 * (productStructure.NodesCounter - productStructure.NodesPerLevel[^ 1].Count));
        public static void DbInitialize(MasterDBContext context)
        {
            context.Database.EnsureCreated();

            // Look for any Entrys.
            if (context.Articles.Any())
            {
                return;   // DB has been seeded
            }
            // Resource Definitions
            var resourceTools = new MasterTableResourceTool();

            resourceTools.Init(context);
            // requires Tools
            var resource = new MasterTableResource();

            resource.Init(context);
            // requires Tools and Resources
            var resourceSkills = new MasterTableResourceSkill();

            resourceSkills.Init(context);
            // requires Tools, Resources, and Skills
            var resourceSetups = new MasterTableResourceSetup(resource, resourceTools, resourceSkills);

            resourceSetups.Init(context);

            // Article Definitions
            var units = new MasterTableUnit();

            units.Init(context);
            var articleTypes = new MasterTableArticleType();

            articleTypes.Init(context);

            // requires Units and Article Types
            var articleTable = new MasterTableArticle(articleTypes, units);
            var articles     = articleTable.Init(context);

            MasterTableStock.Init(context, articles);

            var operations = new MasterTableOperation(articleTable, resourceSkills, resourceTools);

            operations.Init(context);

            var boms = new MasterTableBom();

            boms.Init(context, articleTable, operations);

            var businessPartner = new MasterTableBusinessPartner();

            businessPartner.Init(context);

            var articleToBusinessPartner = new MasterTableArticleToBusinessPartner();

            articleToBusinessPartner.Init(context, businessPartner, articleTable);

            var updateArticleLotSize = context.Articles
                                       .Include(x => x.ArticleType)
                                       .Include(x => x.ArticleToBusinessPartners)
                                       .ToList();

            // TODO noch gemogelt LotSize != PackSize
            foreach (var article in updateArticleLotSize)
            {
                if (article.ToPurchase)
                {
                    article.LotSize = article.ArticleToBusinessPartners.First().PackSize;
                }
            }
            DbUtils.InsertOrUpdateRange(updateArticleLotSize, context.Articles, context);
            context.SaveChanges();
        }