Esempio n. 1
0
 public TunablePlan(EstimatedUrgentWorkflow workflow)
     : base(workflow)
 {
     roots       = workflow.Tasks.OrderBy(t => t.DepthLevel).Select(t => t.Id).ToArray();
     leaves      = roots.Reverse().ToArray();
     baseValues  = Estimations.ToDictionary(e => e.First().Id, e => e.Count());
     optionsIdxs = baseValues.ToDictionary(p => p.Key, p => 0);
     maxIndex    = baseValues.Values.Max();
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public EstimatedUrgentWorkflow(EstimatedUrgentWorkflow other)
     : this((EstimatedWorkflow)other)
 {
     if (other == null)
     {
         return;
     }
     MinExecutionTime = other.MinExecutionTime;
     MaxExecutionTime = other.MaxExecutionTime;
 }
Esempio n. 4
0
        protected double FullTaskTime(ActiveEstimatedTask task, EstimatedUrgentWorkflow workflow)
        {
            var parent          = workflow.Tasks.Single(wt => wt.Id == task.Id);
            var depsWaitingTime = parent.RequiresDependencies.Count == 0
                                      ? 0
                                      : parent.RequiresDependencies.Max(
                d =>
                d.ScheduledInstance.Estimation.LaunchTime +
                d.ScheduledInstance.Estimation.Result.Time);
            var nodesWaitingTime = GetNodesAvailabilityTimeForUrgentTask(task, workflow); //t.First().Estimation.NodesTimings.Max(n => n.AvailabilityTime);
            var waitingTime      = Math.Max(depsWaitingTime, nodesWaitingTime);

            return(waitingTime + task.Estimation.Result.Time);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
 public TunablePlan(EstimatedUrgentWorkflow workflow)
     : base(workflow)
 {
     roots = workflow.Tasks.OrderBy(t => t.DepthLevel).Select(t => t.Id).ToArray();
     leaves = roots.Reverse().ToArray();
     baseValues = Estimations.ToDictionary(e => e.First().Id, e => e.Count());
     optionsIdxs = baseValues.ToDictionary(p => p.Key, p => 0);
     maxIndex = baseValues.Values.Max();
 }
Esempio n. 9
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;
 }
Esempio n. 10
0
 protected virtual double GetNodesAvailabilityTimeForUrgentTask(ActiveEstimatedTask task, EstimatedUrgentWorkflow workflow)
 {
     return task.Estimation.NodesTimings.Max(n =>
         {
             var lTask = n.LaunchedTask;
             var result = lTask != null && (lTask.IsUrgent || !task.IgnoreNonUrgent) ? lTask.Estimation.Result.Time : 0;
             var td = new LaunchDestination()
             {
                 ResourceName = n.ResourceName,
                 NodeNames = new[] { n.NodeName }
             };
             result += workflow.ActiveTasks.Where(t => t.IsUrgent && t.State == TaskScheduler.TaskState.SCHEDULED && t.IsOlderThan(task) && t.Estimation.Destination.IsLike(td)).Sum(t => t.Estimation.Result.Time);
             return result;
         }
     );
 }
Esempio n. 11
0
 public virtual UrgentPlan MakePlan(EstimatedUrgentWorkflow workflow)
 {
     return MakeInitialPlan(workflow);
 }
Esempio n. 12
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;
        }
Esempio n. 13
0
 public EstimatedUrgentWorkflow(EstimatedUrgentWorkflow other)
     : this((EstimatedWorkflow)other)
 {
     if (other == null)
     {
         return;
     }
     MinExecutionTime = other.MinExecutionTime;
     MaxExecutionTime = other.MaxExecutionTime;
 }
Esempio n. 14
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;
        }
Esempio n. 15
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;
        }
Esempio n. 16
0
 public UrgentPlan(EstimatedUrgentWorkflow workflow)
 {
     wf = workflow;
     Reset();
 }
Esempio n. 17
0
 internal virtual UrgentPlan CreateEmptyPlan(EstimatedUrgentWorkflow workflow)
 {
     return(new UrgentPlan(workflow));
 }
Esempio n. 18
0
 internal override UrgentPlan CreateEmptyPlan(EstimatedUrgentWorkflow workflow)
 {
     return new TunablePlan(workflow);
 }
Esempio n. 19
0
 public virtual UrgentPlan MakeInitialPlan(EstimatedUrgentWorkflow workflow)
 {
     workflow.UpdateDependencies();
     return(GeneratePlan(workflow, null));
 }
Esempio n. 20
0
 internal override UrgentPlan CreateEmptyPlan(EstimatedUrgentWorkflow workflow)
 {
     return new FreeFirstPlan(workflow);
 }
Esempio n. 21
0
 protected virtual double GetNodesAvailabilityTimeForUrgentTask(ActiveEstimatedTask task, EstimatedUrgentWorkflow workflow)
 {
     return(task.Estimation.NodesTimings.Max(n =>
     {
         var lTask = n.LaunchedTask;
         var result = lTask != null && (lTask.IsUrgent || !task.IgnoreNonUrgent) ? lTask.Estimation.Result.Time : 0;
         var td = new LaunchDestination()
         {
             ResourceName = n.ResourceName,
             NodeNames = new[] { n.NodeName }
         };
         result += workflow.ActiveTasks.Where(t => t.IsUrgent && t.State == TaskScheduler.TaskState.SCHEDULED && t.IsOlderThan(task) && t.Estimation.Destination.IsLike(td)).Sum(t => t.Estimation.Result.Time);
         return result;
     }
                                             ));
 }
Esempio n. 22
0
 public virtual UrgentPlan MakeInitialPlan(EstimatedUrgentWorkflow workflow)
 {
     workflow.UpdateDependencies();
     return GeneratePlan(workflow, null);
 }
Esempio n. 23
0
 public virtual UrgentPlan MakePlan(EstimatedUrgentWorkflow workflow)
 {
     return(MakeInitialPlan(workflow));
 }
Esempio n. 24
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;
 }
Esempio n. 25
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);
        }
Esempio n. 26
0
 internal virtual UrgentPlan CreateEmptyPlan(EstimatedUrgentWorkflow workflow)
 {
     return new UrgentPlan(workflow);
 }
Esempio n. 27
0
 internal override UrgentPlan CreateEmptyPlan(EstimatedUrgentWorkflow workflow)
 {
     return(new TunablePlan(workflow));
 }
Esempio n. 28
0
 protected double FullTaskTime(ActiveEstimatedTask task, EstimatedUrgentWorkflow workflow)
 {
     var parent = workflow.Tasks.Single(wt => wt.Id == task.Id);
     var depsWaitingTime = parent.RequiresDependencies.Count == 0
                               ? 0
                               : parent.RequiresDependencies.Max(
                                   d =>
                                   d.ScheduledInstance.Estimation.LaunchTime +
                                   d.ScheduledInstance.Estimation.Result.Time);
     var nodesWaitingTime = GetNodesAvailabilityTimeForUrgentTask(task, workflow); //t.First().Estimation.NodesTimings.Max(n => n.AvailabilityTime);
     var waitingTime = Math.Max(depsWaitingTime, nodesWaitingTime);
     return waitingTime + task.Estimation.Result.Time;
 }
Esempio n. 29
0
 public FreeFirstPlan(EstimatedUrgentWorkflow workflow)
     : base(workflow)
 {
 }
Esempio n. 30
0
 public UrgentPlan(EstimatedUrgentWorkflow workflow)
 {
     wf = workflow;
     Reset();
 }
Esempio n. 31
0
 public FreeFirstPlan(EstimatedUrgentWorkflow workflow)
     : base(workflow)
 {
 }