Exemple #1
0
        /// <summary>
        /// Check if Feature is still active.
        ///
        /// </summary>
        /// <param name="featureActivity"></param>
        private void ScheduleActivity(FCentralActivity featureActivity)
        {
            if (featureActivity.GanttPlanningInterval < _planManager.PlanVersion)
            {
                Agent.DebugMessage($"{featureActivity.Key} has new schedule from more recent planning interval {featureActivity.GanttPlanningInterval}");
                return;
            }

            if (_activityManager.Activities.Any(x => x.Activity.GetKey.Equals(featureActivity.Key)))
            {
                Agent.DebugMessage($"Actvity {featureActivity.Key} already in progress");
                return;
            }

            //Agent.DebugMessage($"TryStart scheduled activity {featureActivity.Key}");
            if (_scheduledActivities.ContainsKey(featureActivity.Key))
            {
                var resource = _resourceManager.resourceStateList.Single(x => x.ResourceDefinition.Id == featureActivity.ResourceId);
                if (NextActivityIsEqual(resource, featureActivity.Key))
                {
                    //Agent.DebugMessage($"Activity {featureActivity.Key} is equal start now after been scheduled by {featureActivity.ResourceId}");
                    _scheduledActivities.Remove(featureActivity.Key);
                    TryStartActivity(resource.ActivityQueue.Peek(), featureActivity);
                }
            }
        }
Exemple #2
0
        public void StartWork(FCentralActivity activity)
        {
            Agent.DebugMessage($"Start {activity.ProductionOrderId}|{activity.OperationId}|{activity.ActivityId} with Duration: {activity.Duration}");
            _currentActivity = activity;

            CreateTask(activity);

            Agent.Send(Resource.Instruction.Central.ActivityFinish.Create(Agent.Context.Self), activity.Duration);
        }
Exemple #3
0
        private void StartActivity(List <ResourceState> requiredResources
                                   , GptblProductionorderOperationActivityResourceInterval interval
                                   , FCentralActivity featureActivity
                                   , string requiredCapability)
        {
            if (_scheduledActivities.ContainsKey(featureActivity.Key))
            {
                Agent.DebugMessage($"Activity {featureActivity.Key} removed from _scheduledActivities");
                _scheduledActivities.Remove(featureActivity.Key);
            }

            Agent.DebugMessage($"Start activity {featureActivity.ProductionOrderId}|{featureActivity.OperationId}|{featureActivity.ActivityId}!");

            var activity = interval.ProductionorderOperationActivityResource.ProductionorderOperationActivity;

            WithdrawalMaterial(activity);

            _confirmationManager.AddConfirmations(activity, GanttConfirmationState.Started, Agent.CurrentTime, Agent.CurrentTime);

            //Capability


            var randomizedDuration = _workTimeGenerator.GetRandomWorkTime(featureActivity.Duration);

            CreateSimulationJob(activity, Agent.CurrentTime, randomizedDuration, requiredCapability);

            foreach (var resourceState in requiredResources)
            {
                var fCentralActivity = new FCentralActivity(resourceId: resourceState.ResourceDefinition.Id
                                                            , productionOrderId: featureActivity.ProductionOrderId
                                                            , operationId: featureActivity.OperationId
                                                            , activityId: featureActivity.ActivityId
                                                            , activityType: featureActivity.ActivityType
                                                            , start: Agent.CurrentTime
                                                            , duration: randomizedDuration
                                                            , name: featureActivity.Name
                                                            , ganttPlanningInterval: featureActivity.GanttPlanningInterval
                                                            , hub: featureActivity.Hub
                                                            , capability: requiredCapability);

                var startActivityInstruction = Resource.Instruction.Central
                                               .ActivityStart.Create(activity: fCentralActivity
                                                                     , target: resourceState.ResourceDefinition.AgentRef);
                if (resourceState.ActivityQueue.Peek().GetKey == featureActivity.Key)
                {
                    resourceState.ActivityQueue.Dequeue();
                    _activityManager.AddOrUpdateActivity(activity, resourceState.ResourceDefinition);
                    resourceState.StartActivityAtResource(activity);
                    Agent.Send(startActivityInstruction);
                }
                else
                {
                    Agent.DebugMessage($"{resourceState.ResourceDefinition.Name} has another activity");
                }
            }
        }
Exemple #4
0
        private void StartActivities()
        {
            foreach (var resourceState in _resourceManager.resourceStateList)
            {
                //Skip if resource is working
                if (resourceState.IsWorking)
                {
                    continue;
                }

                if (resourceState.ActivityQueue.IsNull() || resourceState.ActivityQueue.Count < 1)
                {
                    continue;
                }

                var interval = resourceState.ActivityQueue.Peek();

                //CheckMaterial

                var featureActivity = new FCentralActivity(resourceState.ResourceDefinition.Id
                                                           , interval.ProductionorderId
                                                           , interval.OperationId
                                                           , interval.ActivityId
                                                           , Agent.CurrentTime
                                                           , interval.ConvertedDateTo - interval.ConvertedDateFrom
                                                           , interval.ProductionorderOperationActivityResource.ProductionorderOperationActivity.Name
                                                           , _planManager.PlanVersion
                                                           , Agent.Context.Self
                                                           , string.Empty
                                                           , interval.ActivityId.Equals(2) ? JobType.SETUP : JobType.OPERATION); // may not required.

                // Feature Activity
                if (interval.ConvertedDateFrom > Agent.CurrentTime)
                {
                    // only schedule activities that have not been scheduled
                    if (_scheduledActivities.TryAdd(featureActivity.Key, featureActivity))
                    {
                        var waitFor = interval.ConvertedDateFrom - Agent.CurrentTime;
                        Agent.DebugMessage($"{featureActivity.Key} has been scheduled to {Agent.CurrentTime + waitFor} as planning interval {_planManager.PlanVersion}");
                        Agent.Send(instruction: Hub.Instruction.Central.ScheduleActivity.Create(featureActivity, Agent.Context.Self)
                                   , waitFor);
                    }
                }
                else
                {
                    if (interval.ConvertedDateFrom < Agent.CurrentTime)
                    {
                        Agent.DebugMessage($"Activity {featureActivity.Key} at {resourceState.ResourceDefinition.Name} is delayed {interval.ConvertedDateFrom}");
                    }

                    // Activity is scheduled for now
                    TryStartActivity(interval, featureActivity);
                }
            }
        }
Exemple #5
0
        void CreateTask(FCentralActivity activity)
        {
            var pub = new FCreateTaskItem(
                type: activity.ActivityType
                , resource: _resourceDefinition.ResourceName
                , resourceId: _resourceDefinition.ResourceId
                , start: Agent.CurrentTime
                , end: Agent.CurrentTime + activity.Duration
                , capability: activity.Capability
                , operation: activity.ActivityType == JobType.SETUP ? "Setup for " + activity.Name : activity.Name
                , groupId: activity.ProductionOrderId + activity.OperationId + activity.ActivityId + activity.GanttPlanningInterval);

            //TODO NO tracking
            Agent.Context.System.EventStream.Publish(@event: pub);
        }
Exemple #6
0
        public void FinishActivity(FCentralActivity fActivity)
        {
            // Get Resource
            System.Diagnostics.Debug.WriteLine($"Finish {fActivity.ProductionOrderId}|{fActivity.OperationId}|{fActivity.ActivityId} with Duration: {fActivity.Duration} from {Agent.Sender.ToString()}");

            var activity = _resourceManager.GetCurrentActivity(fActivity.ResourceId);

            // Add Confirmation
            _activityManager.FinishActivityForResource(activity, fActivity.ResourceId);

            if (_activityManager.ActivityIsFinished(activity.GetKey))
            {
                //Check if productionorder finished
                _confirmationManager.AddConfirmations(activity, GanttConfirmationState.Finished, Agent.CurrentTime, fActivity.Start);

                ProductionOrderFinishCheck(activity);
            }

            // Finish ResourceState
            _resourceManager.FinishActivityAtResource(fActivity.ResourceId);

            //Check If new activities are available
            StartActivities();
        }
Exemple #7
0
 public static ActivityStart Create(FCentralActivity activity, IActorRef target)
 {
     return(new ActivityStart(message: activity, target: target));
 }
Exemple #8
0
 public void FinishWork()
 {
     Agent.DebugMessage($"Finish {_currentActivity.ProductionOrderId}|{_currentActivity.OperationId}|{_currentActivity.ActivityId} with Duration: {_currentActivity.Duration}");
     Agent.Send(HubAgent.Hub.Instruction.Central.ActivityFinish.Create(_currentActivity, _currentActivity.Hub));
     _currentActivity = null;
 }
Exemple #9
0
        private void TryStartActivity(GptblProductionorderOperationActivityResourceInterval interval, FCentralActivity fActivity)
        {
            // not sure if this works or if we just loop through resources and check even activities
            var resourcesForActivity = interval.ProductionorderOperationActivityResource
                                       .ProductionorderOperationActivity
                                       .ProductionorderOperationActivityResources;

            var resourceId = resourcesForActivity.SingleOrDefault(x => x.ResourceType.Equals(5))?.ResourceId;

            var requiredCapability = _prtResources[resourceId];

            var resource = _resourceManager.resourceStateList.Single(x => x.ResourceDefinition.Id.Equals(fActivity.ResourceId));

            //Agent.DebugMessage($"{resource.ResourceDefinition.Name} try start activity {fActivity.Key}!");

            var requiredResources = new List <ResourceState>();
            var resourceCount     = 0;

            //activity can be ignored as long any resource is working -> after finish work of the resource it will trigger anyways
            foreach (var resourceForActivity in resourcesForActivity)
            {
                if (_prtResources.ContainsKey(resourceForActivity.ResourceId))
                {
                    //do not request, because tool is infinity
                    continue;
                }
                var resourceState = _resourceManager.resourceStateList.Single(x => x.ResourceDefinition.Id == int.Parse(resourceForActivity.ResourceId));

                //Agent.DebugMessage($"Try to start activity {fActivity.Key} at {resourceState.ResourceDefinition.Name}");
                if (_resourceManager.ResourceIsWorking(int.Parse(resourceForActivity.ResourceId)))
                {
                    //Agent.DebugMessage($"{resourceState.ResourceDefinition.Name} has current work{resourceState.GetCurrentProductionOperationActivity}. Stop TryStartActivity!");
                    return;
                }

                if (!NextActivityIsEqual(resourceState, fActivity.Key))
                {
                    var nextActivity = resourceState.ActivityQueue.Peek();
                    //Agent.DebugMessage($"{resourceState.ResourceDefinition.Name} has different work next {nextActivity.ProductionorderId}|{nextActivity.OperationId}|{nextActivity.ActivityId}. Stop TryStartActivity!");
                    return;
                }

                resourceCount++;
                Agent.DebugMessage($"{resourceCount} of {resourcesForActivity.Count} Resource for Activity {fActivity.Key} are ready");
                requiredResources.Add(resourceState);
            }

            //Check if all preconditions are fullfilled
            var activity = interval.ProductionorderOperationActivityResource.ProductionorderOperationActivity;

            if (!_activityManager.HasPreconditionsFullfilled(activity, requiredResources))
            {
                Agent.DebugMessage($"Preconditions for {fActivity.Key} are not fulfilled!");
                return;
            }

            StartActivity(requiredResources: requiredResources
                          , interval: interval
                          , featureActivity: fActivity
                          , requiredCapability: requiredCapability);
        }
Exemple #10
0
 public static ScheduleActivity Create(FCentralActivity message, IActorRef target, bool logThis = false)
 {
     return(new ScheduleActivity(message: message, target: target, logThis: logThis));
 }