public boolItem this[int index] { get { if (SelectionList != null && SelectionList.Count > 0 && index < BlockSize && index >= 0) { boolItem item = new boolItem(index); item = (boolItem)this.SelectionList.Find( ((SampleItem)item).Equals); return item; } else { return null; } } }
//[XmlElementAttribute(ElementName = "insuranceCounter", // IsNullable = false, Type = typeof(Utility.SystematicCounter))] //public Utility.SystematicCounter InsuranceCounter //{ // get { return insuranceCounter; } // set // { // if (insuranceCounter == null && value != null) // { // insuranceCounter = value; // } // else if (value == null) // { // throw new System.ArgumentNullException("can't set insuranceCounter to null"); // } // else if (insuranceCounter != null) // { // throw new System.InvalidOperationException("can't reset insuranceCounter once it has been initialized"); // } // } //} //methods public override SampleItem NextItem() { this.Ready(true); boolItem item = null; if (base.Rand.Next(Frequency) == 0) { item = new boolItem(this.Count); } else { if (IsSelectingITrees && InsuranceCounter.Next()) { item = new boolItem(Count); item.IsInsuranceItem = true; } } base.Count++; return item; }
//Methods public void initBlock(IFrequencyBasedSelecter master) { if (this.SelectionList == null) { this.SelectionList = new List<SampleItem>(); } else { SelectionList.Clear(); } if (master == null) { throw new System.ArgumentNullException("master can't be null"); } calcBlockSize(master); boolItem nextSelection; //temp value IntInterval subBlock;//interval from the start to the end of the current subblock //select selection numbers for each subBlock for (int i = 0; i < this.NumSubBlocks; i++) { //calculate the range of the current subblock subBlock.Start = i * (master.Frequency * this.SubBlockHeight); subBlock.End = (i + 1) * (master.Frequency * this.SubBlockHeight); //get a random item in the range of the current subblock nextSelection = new boolItem(master.Rand.Next(subBlock.Start, subBlock.End)); if (master.IsSelectingITrees) { if (master.InsuranceCounter.Next()) { nextSelection.IsInsuranceItem = true; } else { nextSelection.IsSelected = true; } } else { nextSelection.IsSelected = true; } this.selectionList.Add(nextSelection); } //select remaining selection numbers for (int i = 0; i < this.NumSubBlocks; i++) { nextSelection = new boolItem(); //keep requesting new selection nubers untill you get one //that you dont already have do { nextSelection.Index = master.Rand.Next(0, this.NumSubBlocks * this.SubBlockHeight * master.Frequency); } while (this.selectionList.Contains(nextSelection)); if (master.IsSelectingITrees) { if (master.InsuranceCounter.Next()) { nextSelection.IsInsuranceItem = true; } else { nextSelection.IsSelected = true; } } else { nextSelection.IsSelected = true; } this.selectionList.Add(nextSelection); } if (master.IsSelectingITrees) { int i = 0; boolItem item = new boolItem(i); //loop though the intire block for (; i < BlockSize; i++) { //if nothing already exists at that block index if (!selectionList.Contains(item)) { //see if it might be an insurance item if (master.InsuranceCounter.Next()) { item.IsInsuranceItem = true; SelectionList.Add(item); item = new boolItem(); } } item.Index = i + 1; } } this.selectionList.Sort(); }
public override SampleItem NextItem() { boolItem newItem = null; if (CurrentIndex == _hitIndex) { newItem = new boolItem(); newItem.IsSelected = true; } else if (base.IsSelectingITrees && this.InsuranceCounter.Check() && CurrentIndex == _iHitIndex) { newItem = new boolItem(); newItem.IsInsuranceItem = true; } IncrementIndex(); this.Count++; return newItem; }