Esempio n. 1
0
        public void ResetGanttPlanDB()
        {
            //Reset GanttPLan DB?
            var ganttPlanContext = GanttPlanDBContext.GetContext(GanttPlanCtxString);

            ganttPlanContext.Database.ExecuteSqlRaw("EXEC sp_MSforeachtable 'DELETE FROM ? '");
        }
Esempio n. 2
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();
 }
Esempio n. 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());
        }
Esempio n. 4
0
 public static IBehaviour Central(GanttPlanDBContext ganttContext
                                  , ProductionDomainContext productionDomainContext
                                  , IMessageHub messageHub
                                  , Configuration configuration
                                  , List <FSetEstimatedThroughputTime> estimatedThroughputTimes)
 {
     return(new Central(ganttContext, productionDomainContext, messageHub, configuration, estimatedThroughputTimes));
 }
Esempio n. 5
0
        public void TransferStockPostings()
        {
            using (var localGanttPlanDbContext = GanttPlanDBContext.GetContext(_dbConnectionStringGanttPlan))
            {
                localGanttPlanDbContext.GptblStockquantityposting.AddRange(_stockPostings);
                localGanttPlanDbContext.SaveChanges();
            }

            ResetStockPostings();
        }
        public void TransferConfirmations()
        {
            using (var localGanttPlanDbContext = GanttPlanDBContext.GetContext(_dbConnectionStringGanttPlan))
            {
                localGanttPlanDbContext.GptblConfirmation.AddRange(_confirmations);
                localGanttPlanDbContext.GptblConfirmationResource.AddRange(_confirmationsResources);
                localGanttPlanDbContext.SaveChanges();
            }

            ResetConfirmations();
        }
Esempio n. 7
0
        public Central(string dbConnectionStringGanttPlan, string dbConnectionStringMaster, WorkTimeGenerator workTimeGenerator, SimulationType simulationType = SimulationType.Default) : base(childMaker: null, simulationType: simulationType)
        {
            _workTimeGenerator           = workTimeGenerator;
            _dbConnectionStringGanttPlan = dbConnectionStringGanttPlan;
            _dbConnectionStringMaster    = dbConnectionStringMaster;
            _confirmationManager         = new ConfirmationManager(dbConnectionStringGanttPlan);
            _stockPostingManager         = new StockPostingManager(dbConnectionStringGanttPlan);

            using (var localganttplanDB = GanttPlanDBContext.GetContext(_dbConnectionStringGanttPlan))
            {
                _products = localganttplanDB.GptblMaterial.Where(x => x.Info1.Equals("Product")).ToList();
            }
        }
Esempio n. 8
0
 public Central(GanttPlanDBContext ganttContext
                , ProductionDomainContext productionDomainContext
                , IMessageHub messageHub
                , Configuration configuration
                , List <FSetEstimatedThroughputTimes.FSetEstimatedThroughputTime> estimatedThroughputTimes)
 {
     _ganttContext       = ganttContext;
     _productionContext  = productionDomainContext;
     _dataBaseConnection = _ganttContext.Database.GetDbConnection();
     _messageHub         = messageHub;
     _orderGenerator     = new OrderGenerator(simConfig: configuration,
                                              productionDomainContext,
                                              productIds: estimatedThroughputTimes.Select(x => x.ArticleId).ToList());
     _orderCounter     = new OrderCounter(maxQuantity: configuration.GetOption <OrderQuantity>().Value);
     _configID         = configuration.GetOption <SimulationId>().Value;
     _simulationEnds   = configuration.GetOption <SimulationEnd>().Value;
     _simulationType   = configuration.GetOption <SimulationKind>().Value;
     _transitionFactor = configuration.GetOption <TransitionFactor>().Value;
     estimatedThroughputTimes.ForEach(SetEstimatedThroughputTime);
 }
Esempio n. 9
0
        public void TestDateUpdate()
        {
            GanttPlanOptRunner.RunOptAndExport("Init");

            var ganttPlanContext = GanttPlanDBContext.GetContext(GanttPlanCtxString);

            var modelparameter = ganttPlanContext.GptblModelparameter.FirstOrDefault();

            if (modelparameter != null)
            {
                modelparameter.ActualTime = new DateTime(year: 2020, day: 2, month: 1);
                ganttPlanContext.Entry(modelparameter).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                ganttPlanContext.SaveChanges();
            }


            GanttPlanOptRunner.RunOptAndExport("Continuous");

            var modelparameter1 = ganttPlanContext.GptblModelparameter.FirstOrDefault();

            if (modelparameter != null)
            {
                modelparameter1.ActualTime = new DateTime(year: 2020, day: 3, month: 1);
                ganttPlanContext.Entry(modelparameter1).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                ganttPlanContext.SaveChanges();
            }

            GanttPlanOptRunner.RunOptAndExport("Continuous");

            var modelparameter2 = ganttPlanContext.GptblModelparameter.FirstOrDefault();

            if (modelparameter != null)
            {
                modelparameter2.ActualTime = new DateTime(year: 2020, day: 3, month: 1);
                ganttPlanContext.Entry(modelparameter2).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                ganttPlanContext.SaveChanges();
            }
        }
Esempio n. 10
0
        public async void RunGanttSimulation(Configuration simConfig)
        {
            GanttPlanDBContext.ClearDatabase(GanttPlanCtxString);

            //Synchronisation GanttPlan
            GanttPlanOptRunner.Inizialize();

            var simContext = new GanttSimulation(GanttPlanCtxString, _context.Database.GetDbConnection().ConnectionString, messageHub: _messageHub);

            simConfig.ReplaceOption(new SimulationKind(value: SimulationType.Central));
            simConfig.ReplaceOption(new DebugSystem(value: false));

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

            //emtpyResultDBbySimulationNumber(simNr: simConfig.GetOption<SimulationNumber>());
            if (simulation.IsReady())
            {
                // Start simulation
                var sim = simulation.RunAsync();
                simContext.StateManager.ContinueExecution(simulation);
                await sim;
            }
        }
Esempio n. 11
0
        public void TestMaterialRelations()
        {
            using (var localGanttPlanDbContext = GanttPlanDBContext.GetContext(GanttPlanCtxString))
            {
                var materialId = "10115";

                var activities = new Queue <GptblProductionorderOperationActivityResourceInterval>(
                    localGanttPlanDbContext.GptblProductionorderOperationActivityResourceInterval
                    .Include(x => x.ProductionorderOperationActivityResource)
                    .ThenInclude(x => x.ProductionorderOperationActivity)
                    .ThenInclude(x => x.ProductionorderOperationActivityMaterialrelation)
                    .Include(x => x.ProductionorderOperationActivityResource)
                    .ThenInclude(x => x.ProductionorderOperationActivity)
                    .ThenInclude(x => x.Productionorder)
                    .Include(x => x.ProductionorderOperationActivityResource)
                    .ThenInclude(x => x.ProductionorderOperationActivity)
                    .ThenInclude(x => x.ProductionorderOperationActivityResources)
                    .Where(x => x.ProductionorderOperationActivityResource.ProductionorderOperationActivity
                           .Productionorder.MaterialId.Equals(materialId) &&
                           x.IntervalAllocationType.Equals(1))
                    .OrderBy(x => x.DateFrom)
                    .ToList());
            } // filter Done and in Progress?
        }
Esempio n. 12
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);
        }
Esempio n. 13
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));
        }
Esempio n. 14
0
        private void LoadProductionOrders(IActorRef inboxActorRef)
        {
            var  timeStamps = new Dictionary <string, long>();
            long lastStep   = 0;
            var  stopwatch  = Stopwatch.StartNew();

            stopwatch.Start();

            _stockPostingManager.TransferStockPostings();
            _confirmationManager.TransferConfirmations();

            /*using (var localGanttPlanDbContext = GanttPlanDBContext.GetContext(_dbConnectionStringGanttPlan))
             * {
             *  foreach (var updatedSalesorder in _salesOrder.Where(x => x.Status.Equals(8)))
             *  {
             *      var salesorder = localGanttPlanDbContext.GptblSalesorder.Single(x => x.SalesorderId.Equals(updatedSalesorder.SalesorderId));
             *
             *      if(salesorder.Status.NotEqual(8)){
             *          salesorder.Status = updatedSalesorder.Status;
             *          salesorder.QuantityDelivered = updatedSalesorder.QuantityDelivered;
             *      }
             *
             *  }
             *
             *  localGanttPlanDbContext.SaveChanges();
             * }*/

            //update model planning time


            using (var localGanttPlanDbContext = GanttPlanDBContext.GetContext(_dbConnectionStringGanttPlan))
            {
                var modelparameter = localGanttPlanDbContext.GptblModelparameter.FirstOrDefault();
                if (modelparameter != null)
                {
                    modelparameter.ActualTime = Agent.CurrentTime.ToDateTime();
                    localGanttPlanDbContext.SaveChanges();
                }
            }

            lastStep = stopwatch.ElapsedMilliseconds;
            timeStamps.Add("Write Confirmations", lastStep);

            System.Diagnostics.Debug.WriteLine("Start GanttPlan");
            GanttPlanOptRunner.RunOptAndExport("Continuous"); //changed to Init - merged configs
            System.Diagnostics.Debug.WriteLine("Finish GanttPlan");

            lastStep = stopwatch.ElapsedMilliseconds - lastStep;
            timeStamps.Add("Gantt Plan Execution", lastStep);

            using (var localGanttPlanDbContext = GanttPlanDBContext.GetContext(_dbConnectionStringGanttPlan))
            {
                foreach (var resourceState in _resourceManager.resourceStateList)
                {
                    // put to an sorted Queue on each Resource
                    resourceState.ActivityQueue = new Queue <GptblProductionorderOperationActivityResourceInterval>(
                        localGanttPlanDbContext.GptblProductionorderOperationActivityResourceInterval
                        .Include(x => x.ProductionorderOperationActivityResource)
                        .ThenInclude(x => x.ProductionorderOperationActivity)
                        .ThenInclude(x => x.ProductionorderOperationActivityMaterialrelation)
                        .Include(x => x.ProductionorderOperationActivityResource)
                        .ThenInclude(x => x.ProductionorderOperationActivity)
                        .ThenInclude(x => x.Productionorder)
                        .Include(x => x.ProductionorderOperationActivityResource)
                        .ThenInclude(x => x.ProductionorderOperationActivity)
                        .ThenInclude(x => x.ProductionorderOperationActivityResources)
                        .Where(x => x.ResourceId.Equals(resourceState.ResourceDefinition.Id.ToString()) &&
                               x.IntervalAllocationType.Equals(1) &&
                               (x.ProductionorderOperationActivityResource.ProductionorderOperationActivity.Status != (int)GanttActivityState.Finished &&
                                x.ProductionorderOperationActivityResource.ProductionorderOperationActivity.Status != (int)GanttActivityState.Started))
                        .OrderBy(x => x.DateFrom)
                        .ToList());
                } // filter Done and in Progress?

                var tempsalesorder = _SalesorderMaterialrelations;
                _SalesorderMaterialrelations = localGanttPlanDbContext.GptblSalesorderMaterialrelation.ToList();
                foreach (var salesorder in tempsalesorder)
                {
                    var newProductionOrderId = _SalesorderMaterialrelations.Single(x => x.SalesorderId.Equals(salesorder.SalesorderId)).ChildId;
                    if (newProductionOrderId != salesorder.ChildId)
                    {
                        Agent.DebugMessage($"Productionorder for SalesOrderId {salesorder.SalesorderId} changed from {salesorder.ChildId} to {newProductionOrderId}");
                    }
                }

                _salesOrder = localGanttPlanDbContext.GptblSalesorder.ToList();

                if (_prtResources.Count < 1)
                {
                    localGanttPlanDbContext.GptblPrt.Where(x => x.CapacityType.Equals(1)).Select(x => new { x.Id, x.Name }).ForEach(x => _prtResources.Add(x.Id, x.Name));
                }
            }

            //delete orders to avoid sync
            using (var masterDBContext = MasterDBContext.GetContext(_dbConnectionStringMaster))
            {
                masterDBContext.CustomerOrders.RemoveRange(masterDBContext.CustomerOrders);
                masterDBContext.CustomerOrderParts.RemoveRange(masterDBContext.CustomerOrderParts);
                masterDBContext.SaveChanges();
            }

            Agent.DebugMessage($"GanttPlanning number {_planManager.PlanVersion} incremented {_planManager.IncrementPlaningNumber()}");
            _scheduledActivities.Clear();

            StartActivities();

            lastStep = stopwatch.ElapsedMilliseconds - lastStep;
            timeStamps.Add("Load Gantt Results", lastStep);
            timeStamps.Add("TimeStep", Agent.CurrentTime);
            stopwatch.Stop();

            inboxActorRef.Tell(new FCentralGanttPlanInformation(JsonConvert.SerializeObject(timeStamps), "Plan"), this.Agent.Context.Self);
        }