stochastic: honor modularity: true on the first-stage design - #33
Closed
dmeoli wants to merge 1 commit into
Closed
Conversation
The deterministic branch (`base_model.jl:152-163`) already gates design integrality on the per-asset `modularity` flag: continuous when `modularity: true`, integer when `modularity: false`. The stochastic branch (`cooperativeStoch.jl:55`, `nonCooperativeStoch.jl:55`) instead declared `x_us` with a blanket `, Int` flag, so the design was always integer regardless of the YAML setting -- diverging from `base_model.jl`. This patch aligns the two branches: the integrality constraint is now applied per-asset, only when `modularity` is not explicitly `true`. For back-compat, when the field is absent the design stays integer (current behavior); models that opt in with `modularity: true` get a continuous design (matching `base_model.jl`). Motivation: SMS++ TSSB / LagrangianDualSolver_UC harnesses (in `UCBlock/ tools/csv2netCDF/`) compare EC.jl against an LP relaxation of the same EC instance. Without this fix the comparison required a workaround that dumped the LP file, stripped its `Generals` block, and re-solved in a fresh Gurobi environment; with this fix the comparison can rely on `objective_value(model.model)` directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The deterministic branch (
src/base_model.jl:152-163) gates first-stage design integrality on the per-assetmodularityflag:modularity: true→ design is continuous (andx_us = n_us * nom_capacity)modularity: false→set_integer(n_us)is calledThe stochastic branch (
src/stochastic/cooperativeStoch.jl:55andsrc/stochastic/nonCooperativeStoch.jl:55) instead declaredx_uswith a blanket, Intflag, so the design was always integer regardless of the YAML setting — diverging from the deterministic semantics.This patch aligns the two branches: the integrality constraint is now applied per-asset, only when
modularityis not explicitlytrue.modularity: trueget a continuous design (matchingbase_model.jl).Motivation
We are validating an SMS++ port of the same energy-community model (https://gitlab.com/smspp). The SMS++ side (
UCBlock/IntermittentUnitBlock/BatteryUnitBlock) treats the design capacity as a continuous variable, so to compare objective values against EC.jl we need an LP relaxation on this side too. Without this patch the only workable comparison required dumping the LP file, stripping itsGeneralsblock, and re-solving in a fresh Gurobi environment — an awkward workaround for what should be a YAML-driven knob.After this patch, EC.jl
objective_value(model.model)matches the SMS++ LP relaxation to ~1e-11 relative on all stochastic test instances we exercise (CO / CO+TUB / NA / NC / NC+TUB).Test plan
Pkg.test("EnergyCommunity")on thestochasticbranch with no YAML change → behavior unchanged (x_usstays integer becausemodularityfield is absent on the shipped example YAMLs)modularity: trueadded to every asset →x_usbecomes continuous,objective_valueis the LP relaxation, noGeneralsblock in the dumped LPmodularity: true, othersfalseor absent) → only themodularity: trueones become continuous🤖 Generated with Claude Code