private void MakeBestMachineryCombos(List <TimelinessTimePeriod1> timelinessTimePeriods, int[] state, double[][] problemData) { List <TimelinessOpComp1> uniqueTimelinessOpComps = new List <TimelinessOpComp1>(); //best unique opcomp for (int t = 0; t < state.Length; ++t) { //feasible opcomp int w = state[t]; TimelinessOpComp1 newBestOC = this.WOpComps.ElementAtOrDefault(w); TimelinessOpComp1 newUniqueOC = this.TOpComps.ElementAtOrDefault(t); newUniqueOC.TimelinessOpComps = new List <TimelinessOpComp1>(); //match to parent uniqueOC newUniqueOC.TimelinessOpComps.Add(newBestOC); uniqueTimelinessOpComps.Add(newUniqueOC); } //build a stateful new collection of best ocs //refactor: they have to go with correct tp, so use a subroutine to add foreach (TimelinessTimePeriod1 tp in timelinessTimePeriods) { //add them to end of collection this.BestTimelinessTimePeriods.Add(tp); //make sure this is a byref that changes internal collection TimelinessTimePeriod1 newTP = this.BestTimelinessTimePeriods .ElementAtOrDefault(this.BestTimelinessTimePeriods.Count - 1); //start a new list newTP.TimelinessOpComps = new List <TimelinessOpComp1>(); foreach (TimelinessOpComp1 bestoc in uniqueTimelinessOpComps) { //add it to end of collection (each besttoc has one member of besttoc.tocs that is best) newTP.TimelinessOpComps.Add(bestoc); } } }
private TimelinessTimePeriod1 GetNewTimePeriod(TimelinessTimePeriod1 tp) { TimelinessTimePeriod1 newTP = new TimelinessTimePeriod1(tp); newTP.CopyCalculatorProperties(tp); newTP.CopyTotalBenefitsProperties(tp); newTP.CopyTotalCostsProperties(tp); return(newTP); }
private void MakeBestMachineryCombos(List <TimelinessTimePeriod1> timelinessTimePeriods) { //build a stateful new collection of best ocs //refactor: they have to go with correct tp, so use a subroutine to add foreach (TimelinessTimePeriod1 tp in timelinessTimePeriods) { //add new tps to end of collection TimelinessTimePeriod1 newTP = GetNewTimePeriod(tp); //start a new list (must now use InitTimePeriods to match opcomp to timeperiod) newTP.TimelinessOpComps = new List <TimelinessOpComp1>(); foreach (TimelinessOpComp1 bestoc in this.BestOpComps) { //add it to the correct timeperiod if (tp.TimelinessOpComps.FirstOrDefault(toc => toc.Id == bestoc.Id) != null) { //add it to end of collection (each besttoc has one member of besttoc.tocs that is best) newTP.TimelinessOpComps.Add(bestoc); } } //add the best opcomps to the stateful besttp collection this.BestTimelinessTimePeriods.Add(newTP); } }