示例#1
0
        private void UpdateLandAllocatedList(CLEMModel activity, double amountChanged, bool added)
        {
            if (AllocatedActivitiesList == null)
            {
                AllocatedActivitiesList = new List <LandActivityAllocation>();
            }

            // find activity in list
            LandActivityAllocation allocation = AllocatedActivitiesList.Where(a => a.Activity.Name == activity.Name).FirstOrDefault();

            if (allocation != null)
            {
                // modify - remove if added by activity and add if removed or taken for the activity
                allocation.LandAllocated += amountChanged * (added?-1:1);
                if (allocation.LandAllocated < 0.00001)
                {
                    AllocatedActivitiesList.Remove(allocation);
                }
            }
            else
            {
                // if resource was removed by activity it is added to the activty
                if (!added && amountChanged > 0)
                {
                    AllocatedActivitiesList.Add(new LandActivityAllocation()
                    {
                        LandName      = this.Name,
                        Activity      = activity,
                        LandAllocated = amountChanged,
                        ActivityName  = (activity.Name == this.Name)?"Buildings":activity.Name
                    });
                }
            }
        }
示例#2
0
 private void OnCLEMStartOfTimeStep(object sender, EventArgs e)
 {
     foreach (LandType childModel in Apsim.Children(this, typeof(LandType)))
     {
         double total = 0;
         if (childModel.AllocatedActivitiesList != null)
         {
             foreach (LandActivityAllocation item in childModel.AllocatedActivitiesList)
             {
                 ReportedLandAllocation = item;
                 if (ChangeOccurred)
                 {
                     OnAllocationReported(new EventArgs());
                 }
             }
             total = childModel.AllocatedActivitiesList.Sum(a => a.LandAllocated);
         }
         if (ChangeOccurred && childModel.LandArea - total > 0)
         {
             ReportedLandAllocation = new LandActivityAllocation()
             {
                 ActivityName  = "Unallocated",
                 LandName      = childModel.Name,
                 LandAllocated = childModel.LandArea - total
             };
             OnAllocationReported(new EventArgs());
         }
     }
     ChangeOccurred = false;
 }
示例#3
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Land()
 {
     ReportedLandAllocation = new LandActivityAllocation();
     this.SetDefaults();
 }