/// <summary> /// Create the StartConditionMessage which is send to Hub and ResourceAgent /// </summary> /// <param name="operation"></param> /// <returns></returns> public static FUpdateStartCondition GetStartCondition(this FOperation operation, long customerDue) { return(new FUpdateStartCondition(operationKey: operation.Key , customerDue: customerDue , preCondition: operation.StartConditions.PreCondition , articlesProvided: operation.StartConditions.ArticlesProvided)); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="durationSelector"></param> /// <typeparam name="TPayload"></typeparam> /// <returns></returns> public static FOperation <TPayload> AlterEventDuration <TPayload>( this FOperation <TPayload> input, Expression <Func <long, long, long> > durationSelector ) { return(new AlterDurationFOperation <TPayload>(input, durationSelector)); }
private void EnqueueJob(FOperation fOperation) { var localItem = _operationList.FirstOrDefault(x => x.Key == fOperation.Key); // If item is not Already in Queue Add item to Queue // // happens i.e. Machine calls to Requeue item. if (localItem == null) { localItem = fOperation; localItem.UpdateHubAgent(hub: Agent.Context.Self); _operationList.Add(item: localItem); Agent.DebugMessage(msg: $"Got New Item to Enqueue: {fOperation.Operation.Name} | with start condition: {fOperation.StartConditions.Satisfied} with Id: {fOperation.Key}"); } else { // reset Item. Agent.DebugMessage(msg: $"Got Item to Requeue: {fOperation.Operation.Name} | with start condition: {fOperation.StartConditions.Satisfied} with Id: {fOperation.Key}"); fOperation.Proposals.Clear(); localItem = fOperation; //localItem = fOperation.UpdateHubAgent(hub: Agent.Context.Self); _operationList.Replace(val: localItem); } var resourceToRequest = _resourceManager.GetResourceByTool(fOperation.Operation.ResourceTool); foreach (var actorRef in resourceToRequest) { Agent.DebugMessage(msg: $"Ask for proposal at resource {actorRef.Path.Name}"); Agent.Send(instruction: Resource.Instruction.RequestProposal.Create(message: localItem, target: actorRef)); } }
private void EnqueueJob(FOperation fOperation) { var localItem = _operationList.FirstOrDefault(x => x.Key == fOperation.Key); // If item is not Already in Queue Add item to Queue // // happens i.e. Machine calls to Requeue item. if (localItem == null) { localItem = fOperation; localItem.UpdateHubAgent(hub: Agent.Context.Self); _operationList.Add(item: localItem); Agent.DebugMessage(msg: "Got New Item to Enqueue: " + fOperation.Operation.Name + " | with start condition:" + fOperation.StartConditions.Satisfied + " with Id: " + fOperation.Key); } else { // reset Item. Agent.DebugMessage(msg: "Got Item to Requeue: " + fOperation.Operation.Name + " | with start condition:" + fOperation.StartConditions.Satisfied + " with Id: " + fOperation.Key); fOperation.Proposals.Clear(); localItem = fOperation; //localItem = fOperation.UpdateHubAgent(hub: Agent.Context.Self); _operationList.Replace(val: localItem); } foreach (var actorRef in _resourceAgents) { Agent.Send(instruction: Resource.Instruction.RequestProposal.Create(message: localItem, target: actorRef.Key)); } }
public FEndStreamable(FOperation <TResult> fop) : base(new StreamProperties <Empty, TResult>( false, false, null, false, null, null, false, false, false, false, EqualityComparerExpression <Empty> .Default, EqualityComparerExpression <TResult> .Default, null, null, new Dictionary <Expression, object>(), new Dictionary <Expression, Guid?>(), null) ) { Contract.Requires(fop != null); this.pool = MemoryManager.GetMemoryPool <Empty, TResult>(false); this.pool.Get(out this.output); this.output.Allocate(); var fwindow = fop.Compile(0, fop.Size * Config.FuseFactor); //Config.DataGranularity = fwindow.Size; owindow = new OutputFWindow <TResult>(fwindow); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="joiner"></param> /// <typeparam name="TPayload"></typeparam> /// <typeparam name="TResult"></typeparam> /// <returns></returns> public static FOperation <TResult> ConsecutivePairs <TPayload, TResult>( this FOperation <TPayload> input, PairFWindow <TPayload, TResult> .Joiner joiner ) { return(new PairFOperation <TPayload, TResult>(input, joiner)); }
public static FBucket ToBucketItem(this FOperation operation, long time) { // TO BE TESTET var prioRule = Extension.CreateFunc( // Lamda zur Func. func: (bucket, currentTime) => bucket.Operations.Min(selector: y => ((IJob)y).Priority(time)) // ENDE ); var operations = new List <FOperation>(); operations.Add(item: operation); return(new FBucket(key: Guid.NewGuid() //, prioRule: prioRule.ToFSharpFunc() , priority: prioRule.ToFSharpFunc() , name: $"{operation.Operation.ResourceSkill.Name}({BucketNumber++})" , creationTime: time , forwardStart: 0 , forwardEnd: 0 , backwardStart: 0 , backwardEnd: 0 , end: 0 , start: 0 , startConditions: new FStartCondition(preCondition: false, articlesProvided: false) , maxBucketSize: 1 , minBucketSize: 1 , resourceAgent: ActorRefs.NoSender , hubAgent: ActorRefs.NoSender , operations: new FSharpSet <FOperation>(elements: operations) , tool: operation.Tool , proposals: new List <FProposal>())); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="window"></param> /// <param name="transform"></param> /// <typeparam name="TPayload"></typeparam> /// <typeparam name="TResult"></typeparam> /// <returns></returns> public static FOperation <TResult> Transform <TPayload, TResult>( this FOperation <TPayload> input, long window, Action <int, TPayload[], int, TResult[], int> transform ) { return(new W2WFOperation <TPayload, TResult>(input, window, transform)); }
public FBucket Add(FBucket bucket, FOperation fOperation) { if (bucket == null) { throw new Exception($"Bucket {bucket.Name} does not exits"); } bucket = bucket.AddOperation(fOperation); return(bucket); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="predicate"></param> /// <typeparam name="TPayload"></typeparam> /// <returns></returns> public static FOperation <TPayload> Where <TPayload>( this FOperation <TPayload> source, Expression <Func <TPayload, bool> > predicate ) { Invariant.IsNotNull(source, nameof(source)); Invariant.IsNotNull(predicate, nameof(predicate)); return(new WhereFOperation <TPayload>(source, predicate)); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="selector"></param> /// <typeparam name="TPayload"></typeparam> /// <typeparam name="TResult"></typeparam> /// <returns></returns> public static FOperation <TResult> Multicast <TPayload, TResult>( this FOperation <TPayload> source, Func <FOperation <TPayload>, FOperation <TResult> > selector ) { Invariant.IsNotNull(source, nameof(source)); Invariant.IsNotNull(selector, nameof(selector)); return(selector(new MulticastFOperation <TPayload>(source))); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="selector"></param> /// <typeparam name="TPayload"></typeparam> /// <typeparam name="TResult"></typeparam> /// <returns></returns> public static FOperation <TResult> Select <TPayload, TResult>( this FOperation <TPayload> source, SelectFWindow <TPayload, TResult> .Selector selector ) { Invariant.IsNotNull(source, nameof(source)); Invariant.IsNotNull(selector, nameof(selector)); return(new SelectFOperation <TPayload, TResult>(source, selector)); }
public JobConfirmation CreateBucket(FOperation fOperation, Agent agent) { var bucketSize = GetBucketSize(fOperation.RequiredCapability.Id); var bucket = fOperation.ToBucketScopeItem(agent.Context.Self, agent.CurrentTime, bucketSize); var jobConfirmation = new JobConfirmation(bucket); jobConfirmation.SetJobAgent(agent.Context.ActorOf(Job.Props(agent.ActorPaths, jobConfirmation.ToImmutable(), agent.CurrentTime, agent.DebugThis, agent.Context.Self) , $"JobAgent({bucket.Name.ToActorName()})")); _jobConfirmations.Add(jobConfirmation); return(jobConfirmation); }
/// <summary> /// Starts the next Job /// </summary> internal void DoWork(FOperation operation) { Agent.DebugMessage($"Call start Work for {_jobInProgress.JobName} {operation.Operation.Name} {operation.Key} to process for {operation.Operation.RandomizedDuration}", CustomLogger.JOB, LogLevel.Warn); _jobInProgress.SetupIsOngoing = false; _jobInProgress.StartProcessing(Agent.CurrentTime, _jobInProgress.JobDuration); _jobInProgress.CurrentOperation.Set(operation, Agent.CurrentTime); CreateProcessingTask(operation); Agent.Send(Resource.Instruction.Default.FinishTask.Create("PROCESSING", Agent.Context.Self), waitFor: operation.Operation.RandomizedDuration); }
/// <summary> /// /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <param name="joiner"></param> /// <typeparam name="TLeft"></typeparam> /// <typeparam name="TRight"></typeparam> /// <typeparam name="TResult"></typeparam> /// <returns></returns> public static FOperation <TResult> Join <TLeft, TRight, TResult>( this FOperation <TLeft> left, FOperation <TRight> right, JoinFWindow <TLeft, TRight, TResult> .Joiner joiner ) { Invariant.IsNotNull(left, nameof(left)); Invariant.IsNotNull(right, nameof(right)); return(new JoinFOperation <TLeft, TRight, TResult>(left, right, joiner)); }
/// <summary> /// /// </summary> public AggregateFOperation( FOperation <TPayload> input, IAggregate <TPayload, TAggState, TResult> aggregate, long window, long period, long offset ) : base(input) { Invariant.IsTrue(window % period == 0, "Window must be a multiple of period"); Invariant.IsTrue(period % Input.Period == 0, "Period must be a multiple of input period"); _aggregate = aggregate; _window = window; _period = period; _offset = offset; }
void CreateProcessingTask(FOperation item) { var pub = new FCreateTaskItem( type: JobType.OPERATION , resource: Agent.Name.Replace("Resource(", "").Replace(")", "") , start: Agent.CurrentTime , end: Agent.CurrentTime + item.Operation.RandomizedDuration , capability: _jobInProgress.RequiredCapabilityName , operation: item.Operation.Name , groupId: _jobInProgress.JobName); //TODO NO tracking Agent.Context.System.EventStream.Publish(@event: pub); }
public static FOperation <Signal> Resample( this FOperation <Signal> source, long iperiod, long operiod, long gap_tol ) { return(source .ConsecutivePairs <Signal, SigPair>(ResampleJoiner) .AlterEventDuration((s, e) => (e - s > gap_tol) ? iperiod : e - s) .Chop(1) .Select <SigPair, Signal>(ResampleSelector) .AlterPeriod(operiod) ); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="aggregate"></param> /// <param name="window"></param> /// <param name="period"></param> /// <param name="offset"></param> /// <typeparam name="TPayload"></typeparam> /// <typeparam name="TAggState"></typeparam> /// <typeparam name="TResult"></typeparam> /// <returns></returns> public static FOperation <TResult> Aggregate <TPayload, TAggState, TResult>( this FOperation <TPayload> source, Func <Window <Empty, TPayload>, IAggregate <TPayload, TAggState, TResult> > aggregate, long window, long period, long offset = 0 ) { Invariant.IsNotNull(source, nameof(source)); Invariant.IsNotNull(aggregate, nameof(aggregate)); var p = new StreamProperties <Empty, TPayload>( false, true, source.Period, true, period, offset, false, true, true, true, EqualityComparerExpression <Empty> .Default, EqualityComparerExpression <TPayload> .Default, ComparerExpression <Empty> .Default, ComparerExpression <TPayload> .Default, null, null, null ); return(new AggregateFOperation <TPayload, TAggState, TResult>( source, aggregate(new Window <Empty, TPayload>(p)), window, period, offset )); }
internal void EnqueueOperation(FOperation fOperation) { Agent.DebugMessage(msg: $"Original FOperation before add to Bucket : {fOperation.Operation.Name} {fOperation.Key}" + $"| with start condition: {fOperation.StartConditions.Satisfied} with Id: {fOperation.Key}" + $"| ArticleProvided: {fOperation.StartConditions.ArticlesProvided} " + $"| PreCondition: {fOperation.StartConditions.PreCondition}", CustomLogger.JOB, LogLevel.Warn); var operationInBucket = _bucketManager.GetBucketByOperationKey(fOperation.Key); if (operationInBucket != null) { Agent.DebugMessage($"{fOperation.Operation.Name} {fOperation.Key} is already in bucket", CustomLogger.ENQUEUE, LogLevel.Warn); return; } var jobConfirmation = _bucketManager.AddToBucket(fOperation, Agent.CurrentTime); if (jobConfirmation != null) { var bucket = ((FBucket)jobConfirmation.Job); var operationInsideBucket = bucket.Operations.Single(x => x.Key.Equals(fOperation.Key)); Agent.DebugMessage(msg: $"FOperation {operationInsideBucket.Operation.Name} inside Bucket {bucket.Name} {bucket.Key}" + $"| with start condition: {operationInsideBucket.StartConditions.Satisfied} with Id: {operationInsideBucket.Key}" + $"| ArticleProvided: {operationInsideBucket.StartConditions.ArticlesProvided} " + $"| PreCondition: {operationInsideBucket.StartConditions.PreCondition}", CustomLogger.JOB, LogLevel.Warn); Agent.DebugMessage($"Operation {fOperation.Operation.Name} {fOperation.Key} was added to {bucket.Name} {bucket.Key} Send to {jobConfirmation.JobAgentRef.Path.Name}", CustomLogger.ENQUEUE, LogLevel.Warn); Agent.Send(instruction: BasicInstruction.UpdateJob.Create(message: bucket, target: jobConfirmation.JobAgentRef)); return;//if no bucket to add exists create a new one } jobConfirmation = _bucketManager.CreateBucket(fOperation: fOperation, Agent); EnqueueBucket(jobConfirmation.Job.Key); Agent.DebugMessage($"New {jobConfirmation.Job.Name} has been created for Operation {fOperation.Operation.Name} {fOperation.Key}", CustomLogger.ENQUEUE, LogLevel.Warn); //after creating new bucket, modify subsequent buckets RequestDissolveBucket(fOperation); }
internal void RequestDissolveBucket(FOperation operation) { var bucketsToDissolve = _bucketManager.FindAllBucketsLaterForwardStart(operation); if (bucketsToDissolve.Count > 0) { foreach (var bucket in bucketsToDissolve) { if (bucket.IsRequestedToDissolve) { continue; } bucket.IsRequestedToDissolve = true; Agent.DebugMessage(msg: $"Asking Job Agent to start dissolve {bucket.Job.Key}"); Agent.Send(Job.Instruction.RequestDissolve.Create(bucket.JobAgentRef)); } } }
public static FBucket ToBucketScopeItem(this FOperation operation, IActorRef hubAgent, long time, long maxBucketSize) { //Todo Abs of BackwardStart and ForwardStart, avoid negative values //var scope = Math.Abs(operation.BackwardStart - operation.ForwardStart); var scope = (operation.BackwardStart - operation.ForwardStart); // TO BE TESTET var prioRule = Extension.CreateFunc( // Lamda zur Func. func: (bucket, currentTime) => bucket.Operations.Min(selector: y => ((IJob)y).Priority(currentTime)) // ENDE ); var operations = new List <FOperation> { operation }; return(new FBucket(key: Guid.NewGuid() //, prioRule: prioRule.ToFSharpFunc() , priority: prioRule.ToFSharpFunc() , name: $"(Bucket({BucketNumber++})){operation.RequiredCapability.Name}" , isFixPlanned: false , creationTime: time , forwardStart: operation.ForwardStart , forwardEnd: operation.ForwardEnd , backwardStart: operation.BackwardStart , backwardEnd: operation.BackwardEnd , scope: scope , end: 0 , start: 0 , startConditions: new FStartCondition(preCondition: false, articlesProvided: false) , maxBucketSize: maxBucketSize , minBucketSize: 1000 , setupKey: -1 //unset , hubAgent: hubAgent , operations: new FSharpSet <FOperation>(elements: operations) , requiredCapability: operation.RequiredCapability , bucket: String.Empty)); }
public static FCreateSimulationJob ToSimulationJob(this FOperation fOperation, string jobType, FArticle fArticle, string productionAgent) { var simulationJob = new FCreateSimulationJob( key: fOperation.Key.ToString() , dueTime: fOperation.DueTime , articleName: fOperation.Operation.Article.Name , operationName: fOperation.Operation.Name , operationHierarchyNumber: fOperation.Operation.HierarchyNumber , operationDuration: fOperation.Operation.Duration , requiredCapabilityName: fOperation.Operation.ResourceCapability.Name , jobType: jobType.ToString() , customerOrderId: fArticle.CustomerOrderId.ToString() , isHeadDemand: fArticle.IsHeadDemand , fArticleKey: fArticle.Key , fArticleName: fArticle.Article.Name , productionAgent: productionAgent , articleType: fArticle.Article.ArticleType.Name , start: fOperation.Start , end: fOperation.End ); return(simulationJob); }
/// <summary> /// Add the operation to an existing matching bucket or otherwise creates a new one /// </summary> /// <param name="fOperation"></param> /// <param name="hubAgent"></param> /// <param name="currentTime"></param> /// <returns></returns> public JobConfirmation AddToBucket(FOperation fOperation, long time) { var matchingBuckets = FindAllWithEqualCapability(fOperation).Select(x => x.Job).Cast <FBucket>().ToList(); if (matchingBuckets != null) { //Add var bucket = FindEarliestAndLatestScopeMatching(matchingBuckets, fOperation, time); if (bucket != null) { bucket = Add(bucket: bucket, fOperation: fOperation); var jobConfirmation = GetConfirmationByBucketKey(bucket.Key); if (jobConfirmation == null) { throw new Exception("Tried to add bucket to unknown jobConfirmation"); } jobConfirmation.Job = bucket; return(jobConfirmation); } } //need to create a new one return(null); }
/// <summary> /// Return null if no matching bucket exits /// </summary> /// <param name="buckets">gets a List of all bi</param> /// <param name="operation"></param> /// <returns></returns> public FBucket FindEarliestAndLatestScopeMatching(List <FBucket> buckets, FOperation operation, long time) { List <FBucket> matchingBuckets = new List <FBucket>(); foreach (var bucket in buckets) { var maxbucket = ExceedMaxBucketSize(bucket, operation); if (!maxbucket) { //System.Diagnostics.Debug.WriteLine($"Max bucket size exceed"); } if (HasCapacityLeft(bucket, operation) && HasLaterForwardStart(bucket, operation) && maxbucket) { matchingBuckets.Add(bucket); } } //var matchingBucket = GetBucketWithMostLeftCapacity(matchingBuckets); var matchingBucket = matchingBuckets.OrderBy(x => x.Priority.Invoke(x).Invoke(time)).FirstOr(null); return(matchingBucket); }
private DoWork(FOperation message, IActorRef target) : base(message: message, target: target) { }
public static DoWork Create(FOperation message, IActorRef target) { return(new DoWork(message: message, target: target)); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="filter"></param> public WhereFOperation(FOperation <TPayload> input, Expression <Func <TPayload, bool> > filter) : base(input) { _filter = filter; }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="period"></param> /// <typeparam name="TPayload"></typeparam> /// <returns></returns> public static FOperation <TPayload> AlterPeriod <TPayload>(this FOperation <TPayload> input, long period) { return(new AlterPeriodFOperation <TPayload>(input, period)); }
/// <summary> /// /// </summary> /// <param name="fop"></param> /// <typeparam name="TResult"></typeparam> /// <returns></returns> public static IStreamable <Empty, TResult> FuseEnd <TResult>(this FOperation <TResult> fop) { return(new FEndStreamable <TResult>(fop)); }