Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 16, 2025

setResource() stored the w_pp_cutoff parameter but didn't apply it to the carrying capacity or initial resource abundance when resource_capacity was omitted. This caused validation errors when decreasing the cutoff, as resource abundance could exceed the new limit.

Changes

R/setResource.R

  • Store old w_pp_cutoff before updating parameters
  • When w_pp_cutoff changes without explicit resource_capacity or resource_level:
    • If decreasing: cut off both cc_pp and initial_n_pp at new cutoff
    • If increasing: error (cannot infer extended capacity values)
  • Updated parameter documentation

tests/testthat/test-setResource.R

  • Test decreasing cutoff without capacity (should succeed and apply cutoff)
  • Test increasing cutoff without capacity (should error)
  • Test changing cutoff with capacity (should respect provided values)

NEWS.md

  • Added bug fix entry

Example

params <- NS_params
old_cutoff <- resource_params(params)$w_pp_cutoff  # e.g., 10

# Previously: stored new cutoff but didn't apply it, causing errors
# Now: automatically cuts off cc_pp and initial_n_pp at new value
params <- setResource(params, w_pp_cutoff = 5)

# Still requires capacity when increasing
params <- setResource(params, w_pp_cutoff = 20)  # Error: provide resource_capacity
params <- setResource(params, w_pp_cutoff = 20, resource_capacity = 100)  # OK
Original prompt

This section details on the original issue you should resolve

<issue_title>Enable change of w_pp_cutoff parameter in an existing model</issue_title>
<issue_description>While setResource() has a w_pp_cutoff parameter, supplying this does not actually change the cutoff in the resource carrying capacity unless the carrying_capacity argument is also supplied. Furthermore, when one tries to set the cutoff to a smaller value, then one gets an error because that would lead to a carrying capacity that is not everywhere larger than the current resource abundance. setResource() should therefore also cut off the current resource abundance at the new w_pp_cutoff.</issue_description>

Comments on the Issue (you are @copilot in this section)

@gustavdelius I think that if `w_pp_cutoff` is provided to `setResource()` but `carrying_capacity` is not, and if the new cutoff is smaller than the previous cutoff, then the function should cut off both the initial resource abundance and the carrying capacity at the new cutoff. If the new cutoff is larger than the existing cutoff, then an error should be issued because there is no way to guess the appropriate value for the extra carrying capacity.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Enable change of w_pp_cutoff in existing model Fix w_pp_cutoff parameter not applying cutoff when resource_capacity omitted Nov 16, 2025
Copilot AI requested a review from gustavdelius November 16, 2025 13:07
@gustavdelius gustavdelius marked this pull request as ready for review November 16, 2025 14:12
@gustavdelius gustavdelius merged commit a4b20dc into master Nov 16, 2025
4 of 5 checks passed
@gustavdelius gustavdelius deleted the copilot/enable-w-pp-cutoff-parameter branch November 16, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable change of w_pp_cutoff parameter in an existing model

2 participants