Beispiel #1
0
        /// <summary>Harvest the crop.</summary>
        public void RemoveBiomass(string biomassRemoveType, RemovalFractions removalData = null)
        {
            summary.WriteMessage(this, string.Format("Biomass removed from crop " + Name + " by " + biomassRemoveType.TrimEnd('e') + "ing"));

            // Invoke specific defoliation events.
            if (biomassRemoveType == "Harvest" && Harvesting != null)
            {
                Harvesting.Invoke(this, new EventArgs());
            }

            if (biomassRemoveType == "Prune" && Pruning != null)
            {
                Pruning.Invoke(this, new EventArgs());
            }

            if (biomassRemoveType == "LeafPluck" && LeafPlucking != null)
            {
                LeafPlucking.Invoke(this, new EventArgs());
            }

            if (biomassRemoveType == "Cut" && Cutting != null)
            {
                Cutting.Invoke(this, new EventArgs());
            }

            if (biomassRemoveType == "Graze" && Grazing != null)
            {
                Grazing.Invoke(this, new EventArgs());
            }

            // Set up the default BiomassRemovalData values
            foreach (IOrgan organ in Organs)
            {
                // Get the default removal fractions
                OrganBiomassRemovalType biomassRemoval = null;
                if (removalData != null)
                {
                    biomassRemoval = removalData.GetFractionsForOrgan(organ.Name);
                }
                organ.RemoveBiomass(biomassRemoveType, biomassRemoval);
            }

            // Reset the phenology if SetPhenologyStage specified.
            if (removalData != null && removalData.SetPhenologyStage != 0 && Phenology is Phenology phenology)
            {
                phenology.SetToStage(removalData.SetPhenologyStage);
            }

            // Reduce plant and stem population if thinning proportion specified
            if (removalData != null && removalData.SetThinningProportion != 0 && structure != null)
            {
                structure.DoThin(removalData.SetThinningProportion);
            }

            // Remove nodes from the main-stem
            if (removalData != null && removalData.NodesToRemove > 0)
            {
                structure.DoNodeRemoval(removalData.NodesToRemove);
            }
        }
Beispiel #2
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="node">TBD</param>
        /// <returns>TBD</returns>
        internal DataEnvelope AddSeen(Address node)
        {
            var changed = false;
            var newRemovedNodePruning = Pruning.Select(kvp =>
            {
                var newPruningState = kvp.Value.AddSeen(node);
                changed             = !ReferenceEquals(newPruningState, kvp.Value) || changed;
                return(new KeyValuePair <UniqueAddress, IPruningState>(kvp.Key, newPruningState));
            }).ToImmutableDictionary();

            return(changed ? new DataEnvelope(Data, newRemovedNodePruning) : this);
        }
Beispiel #3
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="from">TBD</param>
        /// <param name="pruningPerformed"></param>
        /// <exception cref="ArgumentException">TBD</exception>
        /// <returns>TBD</returns>
        internal DataEnvelope Prune(UniqueAddress from, PruningPerformed pruningPerformed)
        {
            if (Data is IRemovedNodePruning dataWithRemovedNodePruning)
            {
                if (!Pruning.TryGetValue(from, out var state))
                {
                    throw new ArgumentException($"Can't prune {@from} since it's not found in DataEnvelope");
                }

                if (state is PruningInitialized initialized)
                {
                    var prunedData = dataWithRemovedNodePruning.Prune(from, initialized.Owner);
                    return(new DataEnvelope(data: prunedData, pruning: Pruning.SetItem(from, pruningPerformed), deltaVersions: CleanedDeltaVersions(from)));
                }
            }
            return(this);
        }
Beispiel #4
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="from">TBD</param>
        /// <param name="pruningPerformed"></param>
        /// <exception cref="ArgumentException">TBD</exception>
        /// <returns>TBD</returns>
        internal DataEnvelope Prune(UniqueAddress from, PruningPerformed pruningPerformed)
        {
            var dataWithRemovedNodePruning = Data as IRemovedNodePruning;

            if (dataWithRemovedNodePruning != null)
            {
                IPruningState state;
                if (!Pruning.TryGetValue(from, out state))
                {
                    throw new ArgumentException($"Can't prune {@from} since it's not found in DataEnvelope");
                }

                var initialized = state as PruningInitialized;
                if (initialized != null)
                {
                    var prunedData = dataWithRemovedNodePruning.Prune(from, initialized.Owner);
                    return(new DataEnvelope(data: prunedData, pruning: Pruning.SetItem(from, pruningPerformed), deltaVersions: CleanedDeltaVersions(from)));
                }
            }
            return(this);
        }
Beispiel #5
0
        /// <summary>Harvest the crop.</summary>
        public void RemoveBiomass(string biomassRemoveType, RemovalFractions removalData = null)
        {
            // Invoke an event.
            if (biomassRemoveType == "Harvest" && Harvesting != null)
            {
                Harvesting.Invoke(this, new EventArgs());
            }
            Summary.WriteMessage(this, string.Format("Biomass removed from crop " + Name + " by " + biomassRemoveType.TrimEnd('e') + "ing"));

            // Set up the default BiomassRemovalData values
            foreach (IOrgan organ in Organs)
            {
                // Get the default removal fractions
                OrganBiomassRemovalType biomassRemoval = null;
                if (removalData != null)
                {
                    biomassRemoval = removalData.GetFractionsForOrgan(organ.Name);
                }
                organ.DoRemoveBiomass(biomassRemoveType, biomassRemoval);
            }

            // Reset the phenology if SetPhenologyStage specified.
            if (removalData != null && removalData.SetPhenologyStage != 0)
            {
                Phenology.ReSetToStage(removalData.SetPhenologyStage);
            }

            // Reduce plant and stem population if thinning proportion specified
            if (removalData != null && removalData.SetThinningProportion != 0)
            {
                Structure.doThin(removalData.SetThinningProportion);
            }

            // Pruning event (winter pruning, summer pruning is called as cut) reset the phenology if SetPhenologyStage specified.
            if (biomassRemoveType == "Prune" && Pruning != null)
            {
                Pruning.Invoke(this, new EventArgs());
            }
        }
Beispiel #6
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="removed">TBD</param>
 /// <param name="owner">TBD</param>
 /// <returns>TBD</returns>
 internal DataEnvelope InitRemovedNodePruning(UniqueAddress removed, UniqueAddress owner) =>
 new DataEnvelope(Data, Pruning.Add(removed, new PruningInitialized(owner, ImmutableHashSet <Address> .Empty)));
Beispiel #7
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <returns>TBD</returns>
 public override int GetHashCode()
 {
     unchecked
     {
         return(((Data != null ? Data.GetHashCode() : 0) * 397) ^ (Pruning != null ? Pruning.GetHashCode() : 0));
     }
 }