コード例 #1
0
        public override object Clone()
        {
            var result = new UrgentPlan();

            result.EstimatedExecutionTime = EstimatedExecutionTime;
            result.NodesTimings           = NodesTimings == null ? null : NodesTimings.Select(nt => nt.Clone() as TaskScheduler.NodeAvailabilityTime).ToList();
            result.Plan        = Plan == null ? null : Plan.Select(t => t.Clone() as ActiveEstimatedTask).ToList();
            result.Wrappers    = Wrappers == null ? null : Wrappers.Select(w => w.Clone() as TaskScheduler.NodeAvailabilityTime).ToArray();
            result.Estimations = Estimations;
            return(result);
        }
コード例 #2
0
        internal override void Reorder(UrgentPlan plan)
        {
            /*//for (var i = 0; i < plan.Estimations.Count; i++)
             * //{
             * //    plan.Estimations[i] = plan.Estimations[i].OrderByDescending(t => PrimaryComparisonLambda()(t));
             * //}
             * var busyWrappers = plan.Wrappers.Where(w => w.GetAvailabilityTime(plan.IgnoreNonUrgentTasks) > TaskScheduler.E);
             * var freeWrappers = plan.Wrappers.Except(busyWrappers);
             * for (var i = 0; i < plan.Estimations.Count; i++)
             * {
             *  if (plan.Estimations[i].Count() > 1)
             *  {
             *      plan.Estimations[i] = plan.Estimations[i].OrderBy(e => PrimaryComparisonLambda()(e, plan.wf)).ToList();
             *      //var estimationsOnFreeNodes = plan.Estimations[i].Where(e => e.Estimation.Destination.NodeNames.All(n => freeWrappers.Any(fw => fw.ResourceName == e.Estimation.Destination.ResourceName && fw.NodeName == n))).OrderByDescending(e => PrimaryComparisonLambda()(e, plan.wf));
             *      //var otherEstimations = plan.Estimations[i].Except(estimationsOnFreeNodes).OrderByDescending(e => PrimaryComparisonLambda()(e, plan.wf));
             *      //plan.Estimations[i] = new List<ActiveEstimatedTask>();
             *      //((List<ActiveEstimatedTask>)plan.Estimations[i]).AddRange(estimationsOnFreeNodes);
             *      //((List<ActiveEstimatedTask>)plan.Estimations[i]).AddRange(otherEstimations);
             *  }
             * }*/

            var roots        = plan.wf.Tasks.Where(t => !t.IsScheduled && t.IsReady).ToArray();
            var busyWrappers = plan.Wrappers.Where(w => w.GetAvailabilityTime(plan.IgnoreNonUrgentTasks) > TaskScheduler.E);
            var freeWrappers = plan.Wrappers.Except(busyWrappers);
            var idxs         = new Dictionary <ulong, int>();
            var currentEsts  = new List <IEnumerable <ActiveEstimatedTask> >();

            for (var i = 0; i < plan.Estimations.Count; i++)
            {
                if (plan.Estimations[i].Count() > 1)
                {
                    var first = plan.Estimations[i].First();
                    if (roots.Any(r => r.Id == first.Id))
                    {
                        idxs[first.Id] = i;
                        currentEsts.Add(plan.Estimations[i]);
                    }
                }
            }
            foreach (var es in currentEsts)
            {
                var id = es.First().Id;
                plan.Estimations[idxs[id]] = es.OrderByDescending(e => PrimaryComparisonLambda()(e, plan.wf)).ToList();
            }
        }
コード例 #3
0
        internal virtual UrgentPlan GeneratePlan(EstimatedUrgentWorkflow workflow, UrgentPlan plan)
        {
            var result = plan ?? CreateEmptyPlan(workflow);

            while (workflow.Tasks.Any(t => !t.IsScheduled && t.IsReady))
            {
                Reorder(result);
                ChooseTask(workflow, result);
            }
            result.NodesTimings           = result.Wrappers.ToList();
            result.EstimatedExecutionTime = result.Plan.Any() ? result.Plan.Max(t => t.Estimation.LaunchTime + t.Estimation.Result.Time) : 0;
            Debug.Assert(workflow.Tasks.All(t => t.IsScheduled));
            foreach (var t in workflow.ActiveTasks.Where(t => !t.IsUrgent && t.State == TaskScheduler.TaskState.LAUNCHED))
            {
                if (result.Plan.Any(p => p.IsUrgent && p.State == TaskScheduler.TaskState.LAUNCHED && p.Estimation.Destination.IsLike(t.Estimation.Destination)))
                {
                    result.Plan.Add(new ActiveEstimatedTask(t)
                    {
                        State = TaskScheduler.TaskState.ABORTED
                    });
                }
            }
            return(result);
        }
コード例 #4
0
ファイル: Estimated.cs プロジェクト: kbochenina/Kraken
        internal virtual void Reorder(UrgentPlan plan)
        {
            var roots = plan.wf.Tasks.Where(t => !t.IsScheduled && t.IsReady).ToArray();
            var busyWrappers = plan.Wrappers.Where(w => w.GetAvailabilityTime(plan.IgnoreNonUrgentTasks) > TaskScheduler.E);
            var freeWrappers = plan.Wrappers.Except(busyWrappers);
            var idxs = new Dictionary<ulong, int>();
            var currentEsts = new List<IEnumerable<ActiveEstimatedTask>>();
            for (var i = 0; i < plan.Estimations.Count; i++)
            {
                if (plan.Estimations[i].Count() > 1)
                {
                    var first = plan.Estimations[i].First();
                    if (roots.Any(r => r.Id == first.Id))
                    {
                        idxs[first.Id] = i;
                        currentEsts.Add(plan.Estimations[i]);
                    }
                }
            }
            foreach (var es in currentEsts)
            {
                var id = es.First().Id;
                plan.Estimations[idxs[id]] = es.OrderBy(e => PrimaryComparisonLambda()(e, plan.wf)).ToList();
            }
            /*for (var i = 0; i < plan.Estimations.Count; i++)
            {
                if (plan.Estimations[i].Count() > 1)
                {
                    //plan.Estimations[i] = plan.Estimations[i].OrderBy(e => PrimaryComparisonLambda()(e, plan.wf)).ToList();

                    //var estimationsOnFreeNodes = plan.Estimations[i].Where(e => e.Estimation.Destination.NodeNames.All(n => freeWrappers.Any(fw => fw.ResourceName == e.Estimation.Destination.ResourceName && fw.NodeName == n))).OrderBy(e => PrimaryComparisonLambda()(e, plan.wf));
                    //var otherEstimations = plan.Estimations[i].Except(estimationsOnFreeNodes).OrderBy(e => PrimaryComparisonLambda()(e, plan.wf));
                    //plan.Estimations[i] = new List<ActiveEstimatedTask>();
                    //((List<ActiveEstimatedTask>)plan.Estimations[i]).AddRange(estimationsOnFreeNodes);
                    //((List<ActiveEstimatedTask>)plan.Estimations[i]).AddRange(otherEstimations);
                }
            }*/
        }
コード例 #5
0
ファイル: Estimated.cs プロジェクト: kbochenina/Kraken
 internal virtual UrgentPlan GeneratePlan(EstimatedUrgentWorkflow workflow, UrgentPlan plan)
 {
     var result = plan ?? CreateEmptyPlan(workflow);
     while (workflow.Tasks.Any(t => !t.IsScheduled && t.IsReady))
     {
         Reorder(result);
         ChooseTask(workflow, result);
     }
     result.NodesTimings = result.Wrappers.ToList();
     result.EstimatedExecutionTime = result.Plan.Any() ? result.Plan.Max(t => t.Estimation.LaunchTime + t.Estimation.Result.Time) : 0;
     Debug.Assert(workflow.Tasks.All(t => t.IsScheduled));
     foreach (var t in workflow.ActiveTasks.Where(t => !t.IsUrgent && t.State == TaskScheduler.TaskState.LAUNCHED))
     {
         if (result.Plan.Any(p => p.IsUrgent && p.State == TaskScheduler.TaskState.LAUNCHED && p.Estimation.Destination.IsLike(t.Estimation.Destination)))
         {
             result.Plan.Add(new ActiveEstimatedTask(t)
             {
                 State = TaskScheduler.TaskState.ABORTED
             });
         }
     }
     return result;
 }
コード例 #6
0
ファイル: Estimated.cs プロジェクト: kbochenina/Kraken
 internal virtual ActiveEstimatedTask ExtractTask(IEnumerable<ActiveEstimatedTask> sequence, UrgentPlan plan)
 {
     return sequence.First();//new ActiveEstimatedTask(sequence.First());
 }
コード例 #7
0
ファイル: Estimated.cs プロジェクト: kbochenina/Kraken
        internal virtual ActiveEstimatedTask ChooseTask(EstimatedUrgentWorkflow workflow, UrgentPlan plan)
        {
            var seq = ChooseSequence(workflow, plan);
            var prevInstance = ExtractTask(seq, plan);
            var parent = workflow.Tasks.Single(t => t.Id == prevInstance.Id);
            var depsWaitingTime = parent.RequiresDependencies.Count == 0 ? 0 : parent.RequiresDependencies.Max(d => d.ScheduledInstance.Estimation.LaunchTime + d.ScheduledInstance.Estimation.Result.Time);
            prevInstance.Estimation.LaunchTime = Math.Max(depsWaitingTime, GetNodesAvailabilityTimeForUrgentTask(prevInstance, workflow));
            prevInstance.State = prevInstance.Estimation.LaunchTime > TaskScheduler.E || prevInstance.Estimation.NodesTimings.Any(w => w.GetAvailabilityTime(plan.IgnoreNonUrgentTasks) > TaskScheduler.E) ? TaskScheduler.TaskState.SCHEDULED : TaskScheduler.TaskState.LAUNCHED;
            var clonedInstance = new ActiveEstimatedTask(prevInstance) { IsUrgent = true };
            foreach (var node in prevInstance.Estimation.NodesTimings)
            {
                node.AssignTask(clonedInstance);
            }

            plan.Plan.Add(clonedInstance);
            parent.ScheduledInstance = clonedInstance;
            return clonedInstance;
        }
コード例 #8
0
ファイル: Estimated.cs プロジェクト: kbochenina/Kraken
 internal virtual IEnumerable<ActiveEstimatedTask> ChooseSequence(EstimatedUrgentWorkflow workflow, UrgentPlan plan)
 {
     var rootIds = workflow.Tasks.Where(t => !t.IsScheduled && t.IsReady).Select(r => r.Id);
     var effectiveEstimations = plan.Estimations.Where(e => rootIds.Contains(e.First().Id)).ToList();
     var seq = effectiveEstimations.OrderBy(t => SecondaryComparisonLambda()(workflow, t)).First();
     plan.Estimations.Remove(seq);
     return seq;
 }
コード例 #9
0
ファイル: Estimated.cs プロジェクト: kbochenina/Kraken
 internal override ActiveEstimatedTask ExtractTask(IEnumerable<ActiveEstimatedTask> sequence, UrgentPlan plan)
 {
     return sequence.Skip((plan as TunablePlan)[sequence.First().Id]).First();//new ActiveEstimatedTask(sequence.Skip((plan as TunablePlan)[sequence.First().Id]).First());
 }
コード例 #10
0
ファイル: Estimated.cs プロジェクト: kbochenina/Kraken
 public override object Clone()
 {
     var result = new UrgentPlan();
     result.EstimatedExecutionTime = EstimatedExecutionTime;
     result.NodesTimings = NodesTimings == null ? null : NodesTimings.Select(nt => nt.Clone() as TaskScheduler.NodeAvailabilityTime).ToList();
     result.Plan = Plan == null ? null : Plan.Select(t => t.Clone() as ActiveEstimatedTask).ToList();
     result.Wrappers = Wrappers == null ? null : Wrappers.Select(w => w.Clone() as TaskScheduler.NodeAvailabilityTime).ToArray();
     result.Estimations = Estimations;
     return result;
 }
コード例 #11
0
 internal override ActiveEstimatedTask ExtractTask(IEnumerable <ActiveEstimatedTask> sequence, UrgentPlan plan)
 {
     return(sequence.Skip((plan as TunablePlan)[sequence.First().Id]).First());//new ActiveEstimatedTask(sequence.Skip((plan as TunablePlan)[sequence.First().Id]).First());
 }
コード例 #12
0
        public override UrgentPlan MakePlan(EstimatedUrgentWorkflow workflow)
        {
            var        plan   = MakeInitialPlan(workflow) as TunablePlan;
            UrgentPlan subopt = null;

            do
            {
                if (!plan.AtFirst(DoRoots))
                {
                    plan.Reset();
                    GeneratePlan(workflow, plan);
                }

                var shouldUpdate = false;
                var shouldMove   = false;
                var trigger      = false;

                if (subopt == null)
                {
                    trigger      = true;
                    shouldUpdate = true;
                    shouldMove   = true;
                }

                if (!trigger && workflow.MinExecutionTime < TaskScheduler.E) //ASAP
                {
                    trigger = true;
                }

                if (!trigger && workflow.MinExecutionTime >= TaskScheduler.E)                       //should we count MinExTime at all?
                {
                    if (workflow.MinExecutionTime - plan.EstimatedExecutionTime >= TaskScheduler.E) //the time grows, and as long as current time is beyond the lower bound,
                                                                                                    //we choose to increase it
                    {
                        trigger      = true;
                        shouldUpdate = true;
                        shouldMove   = true;
                    }
                }

                if (!trigger && workflow.MaxExecutionTime >= TaskScheduler.E)                       //the time grows, and if the MaxExTime == 0 then we can safely stop without
                                                                                                    //further increasing it
                {
                    if (workflow.MaxExecutionTime - plan.EstimatedExecutionTime >= TaskScheduler.E) //is it within bounds?
                    {
                        trigger = true;
                        if (!plan.HasAbortedTasks || subopt.HasAbortedTasks) //if current plan is the same or better in terms of terminating tasks
                        {
                            shouldUpdate = true;
                        }
                        shouldMove = true;
                    }
                }

                if (shouldUpdate)
                {
                    subopt = plan.Clone() as UrgentPlan;
                }
                if (!shouldMove)
                {
                    break;
                }
            }while (plan.TrueForward(DoRoots));

            return(subopt);
        }
コード例 #13
0
 internal virtual ActiveEstimatedTask ExtractTask(IEnumerable <ActiveEstimatedTask> sequence, UrgentPlan plan)
 {
     return(sequence.First());//new ActiveEstimatedTask(sequence.First());
 }
コード例 #14
0
        internal virtual ActiveEstimatedTask ChooseTask(EstimatedUrgentWorkflow workflow, UrgentPlan plan)
        {
            var seq             = ChooseSequence(workflow, plan);
            var prevInstance    = ExtractTask(seq, plan);
            var parent          = workflow.Tasks.Single(t => t.Id == prevInstance.Id);
            var depsWaitingTime = parent.RequiresDependencies.Count == 0 ? 0 : parent.RequiresDependencies.Max(d => d.ScheduledInstance.Estimation.LaunchTime + d.ScheduledInstance.Estimation.Result.Time);

            prevInstance.Estimation.LaunchTime = Math.Max(depsWaitingTime, GetNodesAvailabilityTimeForUrgentTask(prevInstance, workflow));
            prevInstance.State = prevInstance.Estimation.LaunchTime > TaskScheduler.E || prevInstance.Estimation.NodesTimings.Any(w => w.GetAvailabilityTime(plan.IgnoreNonUrgentTasks) > TaskScheduler.E) ? TaskScheduler.TaskState.SCHEDULED : TaskScheduler.TaskState.LAUNCHED;
            var clonedInstance = new ActiveEstimatedTask(prevInstance)
            {
                IsUrgent = true
            };

            foreach (var node in prevInstance.Estimation.NodesTimings)
            {
                node.AssignTask(clonedInstance);
            }

            plan.Plan.Add(clonedInstance);
            parent.ScheduledInstance = clonedInstance;
            return(clonedInstance);
        }
コード例 #15
0
        internal virtual IEnumerable <ActiveEstimatedTask> ChooseSequence(EstimatedUrgentWorkflow workflow, UrgentPlan plan)
        {
            var rootIds = workflow.Tasks.Where(t => !t.IsScheduled && t.IsReady).Select(r => r.Id);
            var effectiveEstimations = plan.Estimations.Where(e => rootIds.Contains(e.First().Id)).ToList();
            var seq = effectiveEstimations.OrderBy(t => SecondaryComparisonLambda()(workflow, t)).First();

            plan.Estimations.Remove(seq);
            return(seq);
        }
コード例 #16
0
        public override UrgentPlan MakePlan(EstimatedUrgentWorkflow workflow)
        {
            var        plan   = MakeInitialPlan(workflow) as TunablePlan;
            UrgentPlan subopt = null;

            do
            {
                //the following is just to avoid single meaningless execution of that block
                if (!plan.AtFirst(DoRoots))
                {
                    plan.Reset();
                    GeneratePlan(workflow, plan);
                }

                var shouldUpdate = false;
                var shouldMove   = false;
                var trigger      = false;

                if (subopt == null)
                {
                    shouldUpdate = true;
                    shouldMove   = true;
                    trigger      = true;
                }

                if (!trigger && workflow.MinExecutionTime < TaskScheduler.E) //ASAP
                {
                    return(new GreedyHeuristics().MakePlan(workflow));
                }

                if (!trigger && workflow.MaxExecutionTime >= TaskScheduler.E && workflow.MaxExecutionTime - plan.EstimatedExecutionTime < TaskScheduler.E) //current time is above the higher bound
                {
                    trigger      = true;
                    shouldUpdate = true;
                    shouldMove   = true;
                }

                if (!trigger && workflow.MinExecutionTime >= TaskScheduler.E)                       //should we count MinExTime at all?
                {
                    if (plan.EstimatedExecutionTime - workflow.MinExecutionTime >= TaskScheduler.E) //is current plan above the lower bound?
                    {
                        if (!plan.HasAbortedTasks || subopt.HasAbortedTasks)                        //if current plan is the same or better in terms of terminating tasks
                        {
                            shouldUpdate = true;
                        }
                        shouldMove = true;
                    }
                }

                if (shouldUpdate)
                {
                    subopt = plan.Clone() as UrgentPlan;
                }
                if (!shouldMove)
                {
                    break;
                }
            }while (plan.TrueForward(DoRoots));

            return(subopt);
        }