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(); } }
//[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); }
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)); }
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); }