public SchedulingDataContainer(IEnumerable<Resource> res, IEnumerable<Job> jobs, IEnumerable<double[]> dependencies) { var resArr = res as Resource[] ?? res.ToArray(); resources = res.ToList(); var jobsArr = jobs as Job[] ?? jobs.ToArray(); var depArr = dependencies as double[][] ?? dependencies.ToArray(); //Add all jobs to hash map var jobsDict = jobsArr.ToDictionary(job => job.Number.ToString(CultureInfo.InvariantCulture)); //populate dependencies and preceding jobs for (int j = 0; j < jobsArr.Length;j++ ) { for (int r=0;r<resArr.Length;r++) { var dep = new JobResourceDependency(jobsArr[j], resArr[r], depArr[j][r]); jobsDict[jobsArr[j].Number.ToString(CultureInfo.InvariantCulture)].ResourceDependencies.Add(dep); } if (jobsArr[j].PrecedingJobNums.Count > 0) { foreach (var pjob in jobsArr[j].PrecedingJobNums) { jobsDict[jobsArr[j].Number.ToString(CultureInfo.InvariantCulture)] .PrecedingJobs.Add(jobsDict[pjob.ToString(CultureInfo.InvariantCulture)]); jobsDict[pjob.ToString(CultureInfo.InvariantCulture)]. DependantJobs.Add(jobsDict[jobsArr[j].Number.ToString(CultureInfo.InvariantCulture)]); } } } this.jobs = jobsDict; this.dependencies = depArr.ToList(); }
public void ShouldCalculateMaxIntensity1() { //Arrange var firstJob = new Job(1, 10, null, .1, 2); var resource1 = new Resource(1, 20); var dependency = new JobResourceDependency(firstJob, resource1, 7); firstJob.ResourceDependencies.Add(dependency); var planBuilder = new JobPlanBuilder(); //Act var maxIntensity = planBuilder.CalcMaxPossibleIntensity(firstJob, new[] {resource1}); //Assert True(maxIntensity.FloatEquals(2)); }