private const int MaxIterationCount = 24 * 60 * 365 * 4; // 4 years of minutes protected IEnumerable <IScheduledJob> Solve( List <IShift> shifts, List <IWorker> workers, List <ITool> tools, IEnumerable <IZone> zones, IEnumerable <IJob> jobs, GreedyActivityStrategy strategy, ShiftManager shiftManager) { _shiftManager = shiftManager; _strategy = strategy; _jobPriorityFunction = new SlackTimeRemainingJobPriorityFunction(); if (shifts.Count > 0) { _shifts = shifts.ToArray(); SetupWorkers(shifts, workers); SetupTools(shifts, tools); } SetupZones(zones); SetupJobs(jobs); _timepoints = new Dictionary <int, List <InWorkEvent> >(); _inWorkEvents = new List <InWorkEvent>(); int iteration = InitializeNextIteration(_shifts[0]); while (_jobs.Any() && iteration < MaxIterationCount) { // check to see if we have any events expiring ProcessCompletingJobs(iteration); // check to see if we have any new jobs we can work on ProcessJobs(iteration); // increment iteration counter iteration++; } // we're done! return(BuildSchedule()); }
public ConstraintSolverResult ScheduleDataSet(ProjectDataSet dataSet, IConstraints constraints, GreedyActivityStrategy strategy) { var result = new ConstraintSolverResult(constraints); try { var cp = new CriticalPathHelper(); cp.OrderActivitySchedule(dataSet, result); foreach (var a in result.Schedule) { _scheduledJobs.GetOrAdd(a.ScheduledItem.UID, a); } SetupJobsAndResources(dataSet, constraints); var dataManager = new SolverDataManager(dataSet, result); var solver = new Solver(dataManager); //var results = solver.Solve( // _shifts.Values.ToList(), // _workers.Values.ToList(), // _tools.Values.ToList(), // _zones.Values, // _jobs.Values, // strategy, _shiftManager); //foreach (var job in results) //{ // var activity = _activitiesMap[job.Job.ID]; // var scheduledActivity = _scheduledJobs[activity.UID]; // var start = TimeFrame.FromMinutes(job.Start); // var end = TimeFrame.FromMinutes(job.End); // scheduledActivity.ScheduledStart = start; // scheduledActivity.ScheduledFinish = end; // //result.ActivitySchedule.AddOrUpdateItemSchedule(job.Start, scheduledActivity); // //result.State = SolverResultState.OptimalSolutionFound; //} //result.State = SolverResultState.OptimalSolutionFound; } catch (Exception ex) { throw new Exception("Yikes! Error in solver!", ex); } return(result); }
public async Task <ConstraintSolverResult> ScheduleDataSetAsync(ProjectDataSet dataSet, IConstraints constraints, GreedyActivityStrategy strategy) { return(await Task.Run(() => ScheduleDataSet(dataSet, constraints, strategy))); }
private const int MaxIterationCount = 24*60*365*4; // 4 years of minutes protected IEnumerable<IScheduledJob> Solve( List<IShift> shifts, List<IWorker> workers, List<ITool> tools, IEnumerable<IZone> zones, IEnumerable<IJob> jobs, GreedyActivityStrategy strategy, ShiftManager shiftManager) { _shiftManager = shiftManager; _strategy = strategy; _jobPriorityFunction = new SlackTimeRemainingJobPriorityFunction(); if (shifts.Count > 0) { _shifts = shifts.ToArray(); SetupWorkers(shifts, workers); SetupTools(shifts, tools); } SetupZones(zones); SetupJobs(jobs); _timepoints = new Dictionary<int, List<InWorkEvent>>(); _inWorkEvents = new List<InWorkEvent>(); int iteration = InitializeNextIteration(_shifts[0]); while (_jobs.Any() && iteration < MaxIterationCount) { // check to see if we have any events expiring ProcessCompletingJobs(iteration); // check to see if we have any new jobs we can work on ProcessJobs(iteration); // increment iteration counter iteration++; } // we're done! return BuildSchedule(); }
public ConstraintSolverResult ScheduleDataSet(ProjectDataSet dataSet, IConstraints constraints, GreedyActivityStrategy strategy) { var result = new ConstraintSolverResult(constraints); try { var cp = new CriticalPathHelper(); cp.OrderActivitySchedule(dataSet, result); foreach (var a in result.Schedule) { _scheduledJobs.GetOrAdd(a.ScheduledItem.UID, a); } SetupJobsAndResources(dataSet, constraints); var dataManager = new SolverDataManager(dataSet, result); var solver = new Solver(dataManager); //var results = solver.Solve( // _shifts.Values.ToList(), // _workers.Values.ToList(), // _tools.Values.ToList(), // _zones.Values, // _jobs.Values, // strategy, _shiftManager); //foreach (var job in results) //{ // var activity = _activitiesMap[job.Job.ID]; // var scheduledActivity = _scheduledJobs[activity.UID]; // var start = TimeFrame.FromMinutes(job.Start); // var end = TimeFrame.FromMinutes(job.End); // scheduledActivity.ScheduledStart = start; // scheduledActivity.ScheduledFinish = end; // //result.ActivitySchedule.AddOrUpdateItemSchedule(job.Start, scheduledActivity); // //result.State = SolverResultState.OptimalSolutionFound; //} //result.State = SolverResultState.OptimalSolutionFound; } catch (Exception ex) { throw new Exception("Yikes! Error in solver!", ex); } return result; }
public async Task<ConstraintSolverResult> ScheduleDataSetAsync(ProjectDataSet dataSet, IConstraints constraints, GreedyActivityStrategy strategy) { return await Task.Run(() => ScheduleDataSet(dataSet, constraints, strategy)); }