Skip to content

Commit

Permalink
Merge pull request #14 from mvivienneliu/vl/fix-constructors
Browse files Browse the repository at this point in the history
fixing construct_techonologies, some constraints are broken
  • Loading branch information
jerrypotts authored Sep 23, 2024
2 parents ff8f962 + 390189c commit 88e72b5
Show file tree
Hide file tree
Showing 8 changed files with 423 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ PowerSystems = "4"
PowerSystemsInvestmentsPortfolios = "0.1"
PrettyTables = "2"
TimeSeries = "^0.24.2"
julia = "^1.6"
julia = "^1.6"
1 change: 1 addition & 0 deletions src/PowerSystemsInvestments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export FixedOperationModelCost
export VariableOMCost
export SupplyTotal
export DemandTotal
export EnergyBalance

#remove later, just for testing
export objective_function!
Expand Down
44 changes: 20 additions & 24 deletions src/technology_models/technologies/demand_tech.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ function get_default_time_series_names(
::Type{W},
::Type{X},
) where {
U <: PSIP.DemandRequirement,
V <: InvestmentTechnologyFormulation,
W <: OperationsTechnologyFormulation,
X <: FeasibilityTechnologyFormulation,
U<:PSIP.DemandRequirement,
V<:InvestmentTechnologyFormulation,
W<:OperationsTechnologyFormulation,
X<:FeasibilityTechnologyFormulation,
}
return Dict{Type{<:TimeSeriesParameter}, String}()
return Dict{Type{<:TimeSeriesParameter},String}()
end

function get_default_attributes(
Expand All @@ -18,12 +18,12 @@ function get_default_attributes(
::Type{W},
::Type{X},
) where {
U <: PSIP.DemandRequirement,
V <: InvestmentTechnologyFormulation,
W <: OperationsTechnologyFormulation,
X <: FeasibilityTechnologyFormulation,
U<:PSIP.DemandRequirement,
V<:InvestmentTechnologyFormulation,
W<:OperationsTechnologyFormulation,
X<:FeasibilityTechnologyFormulation,
}
return Dict{String, Any}()
return Dict{String,Any}()
end

################### Variables ####################
Expand All @@ -40,9 +40,9 @@ function add_to_expression!(
devices::U,
formulation::BasicDispatch,
) where {
T <: EnergyBalance,
U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}},
} where {D <: PSIP.DemandRequirement}
T<:EnergyBalance,
U<:Union{Vector{D},IS.FlattenIteratorWrapper{D}},
} where {D<:PSIP.DemandRequirement}
#@assert !isempty(devices)
time_steps = get_time_steps(container)
#binary = false
Expand All @@ -59,6 +59,7 @@ function add_to_expression!(

time_steps = get_time_steps(container)
expression = get_expression(container, T(), PSIP.Portfolio)
# expression = add_expression_container!(container, expression_type, D, time_steps)

#TODO: move to separate add_to_expression! function, could not figure out ExpressionKey

Expand All @@ -80,10 +81,7 @@ function add_to_expression!(

multiplier = -1.0
for (ix, t) in enumerate(time_steps_ix)
_add_to_jump_expression!(
expression["SingleRegion", t],
ts_data[ix] * multiplier,
)
_add_to_jump_expression!(expression["SingleRegion", t], ts_data[ix] * multiplier)
end
end
end
Expand Down Expand Up @@ -121,21 +119,19 @@ function add_constraints!(
#model,
#::NetworkModel{X},
) where {
T <: SupplyDemandBalance,
U <: PSIP.DemandRequirement{PSY.PowerLoad},
T<:SupplyDemandBalance,
U<:PSIP.DemandRequirement{PSY.PowerLoad},
#X <: PM.AbstractPowerModel,
}
# TODO: Remove technologies from the expression definition for these and add corresponding get_expression functions
time_steps = get_time_steps(container)

energy_balance = add_constraints_container!(container, T(), U, time_steps)

supply = get_expression(container, EnergyBalance(), U)
# demand = get_expression(container, DemandTotal(), U)
for t in time_steps
#TODO: Make this generic
supply = get_expression(container, SupplyTotal(), U)
demand = get_expression(container, DemandTotal(), U)

energy_balance[t] =
JuMP.@constraint(get_jump_model(container), supply - demand >= 0)
energy_balance[t] = JuMP.@constraint(get_jump_model(container), supply[t] >= 0)
end
end
74 changes: 37 additions & 37 deletions src/technology_models/technologies/supply_tech.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ function get_default_time_series_names(
::Type{W},
::Type{X},
) where {
U <: PSIP.SupplyTechnology,
V <: InvestmentTechnologyFormulation,
W <: OperationsTechnologyFormulation,
X <: FeasibilityTechnologyFormulation,
U<:PSIP.SupplyTechnology,
V<:InvestmentTechnologyFormulation,
W<:OperationsTechnologyFormulation,
X<:FeasibilityTechnologyFormulation,
}
return Dict{Type{<:TimeSeriesParameter}, String}()
return Dict{Type{<:TimeSeriesParameter},String}()
end

function get_default_attributes(
Expand All @@ -30,12 +30,12 @@ function get_default_attributes(
::Type{W},
::Type{X},
) where {
U <: PSIP.SupplyTechnology,
V <: InvestmentTechnologyFormulation,
W <: OperationsTechnologyFormulation,
X <: FeasibilityTechnologyFormulation,
U<:PSIP.SupplyTechnology,
V<:InvestmentTechnologyFormulation,
W<:OperationsTechnologyFormulation,
X<:FeasibilityTechnologyFormulation,
}
return Dict{String, Any}()
return Dict{String,Any}()
end

################### Variables ####################
Expand All @@ -48,9 +48,9 @@ function add_expression!(
devices::U,
formulation::AbstractTechnologyFormulation,
) where {
T <: CumulativeCapacity,
U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}},
} where {D <: PSIP.SupplyTechnology}
T<:CumulativeCapacity,
U<:Union{Vector{D},IS.FlattenIteratorWrapper{D}},
} where {D<:PSIP.SupplyTechnology}
#@assert !isempty(devices)
time_steps = get_time_steps_investments(container)
binary = false
Expand Down Expand Up @@ -90,9 +90,9 @@ function add_expression!(
devices::U,
formulation::AbstractTechnologyFormulation,
) where {
T <: VariableOMCost,
U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}},
} where {D <: PSIP.SupplyTechnology}
T<:VariableOMCost,
U<:Union{Vector{D},IS.FlattenIteratorWrapper{D}},
} where {D<:PSIP.SupplyTechnology}
@assert !isempty(devices)
time_steps = get_time_steps(container)
binary = false
Expand All @@ -116,17 +116,17 @@ function add_to_expression!(
devices::U,
formulation::BasicDispatch,
) where {
T <: EnergyBalance,
U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}},
} where {D <: PSIP.SupplyTechnology}
T<:EnergyBalance,
U<:Union{Vector{D},IS.FlattenIteratorWrapper{D}},
} where {D<:PSIP.SupplyTechnology}
#@assert !isempty(devices)
time_steps = get_time_steps(container)
#binary = false
#var = get_variable(container, ActivePowerVariable(), D)

variable = get_variable(container, ActivePowerVariable(), D)
expression = get_expression(container, T(), PSIP.Portfolio)

# expression = add_expression_container!(container, expression_type, D, time_steps)
for d in devices, t in time_steps
name = PSIP.get_name(d)
#bus_no = PNM.get_mapped_bus_number(radial_network_reduction, PSY.get_bus(d))
Expand All @@ -146,9 +146,9 @@ function add_expression!(
devices::U,
formulation::BasicDispatch,
) where {
T <: EnergyBalance,
U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}},
} where {D <: PSIP.SupplyTechnology}
T<:EnergyBalance,
U<:Union{Vector{D},IS.FlattenIteratorWrapper{D}},
} where {D<:PSIP.SupplyTechnology}
@assert !isempty(devices)
time_steps = get_time_steps(container)
#binary = false
Expand Down Expand Up @@ -180,10 +180,10 @@ function add_constraints!(
::V,
devices::U,
) where {
T <: ActivePowerLimitsConstraint,
U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}},
V <: ActivePowerVariable,
} where {D <: PSIP.SupplyTechnology{PSY.RenewableDispatch}}
T<:ActivePowerLimitsConstraint,
U<:Union{Vector{D},IS.FlattenIteratorWrapper{D}},
V<:ActivePowerVariable,
} where {D<:PSIP.SupplyTechnology{PSY.RenewableDispatch}}
time_steps = get_time_steps(container)
# Hard Code Mapping #
# TODO: Remove
Expand Down Expand Up @@ -232,10 +232,10 @@ function add_constraints!(
::V,
devices::U,
) where {
T <: ActivePowerLimitsConstraint,
U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}},
V <: ActivePowerVariable,
} where {D <: PSIP.SupplyTechnology{PSY.ThermalStandard}}
T<:ActivePowerLimitsConstraint,
U<:Union{Vector{D},IS.FlattenIteratorWrapper{D}},
V<:ActivePowerVariable,
} where {D<:PSIP.SupplyTechnology{PSY.ThermalStandard}}
time_steps = get_time_steps(container)
# Hard Code Mapping #
# TODO: Remove
Expand Down Expand Up @@ -282,11 +282,11 @@ function add_constraints!(
devices::U,
#::NetworkModel{X},
) where {
T <: MaximumCumulativeCapacity,
U <: Union{Vector{D}, IS.FlattenIteratorWrapper{D}},
V <: CumulativeCapacity,
T<:MaximumCumulativeCapacity,
U<:Union{Vector{D},IS.FlattenIteratorWrapper{D}},
V<:CumulativeCapacity,
#X <: PM.AbstractPowerModel,
} where {D <: PSIP.SupplyTechnology}
} where {D<:PSIP.SupplyTechnology}
time_steps = get_time_steps_investments(container)

device_names = PSIP.get_name.(devices)
Expand Down Expand Up @@ -314,7 +314,7 @@ function objective_function!(
devices::IS.FlattenIteratorWrapper{T},
#DeviceModel{T, U},
formulation::BasicDispatch, #Type{<:PM.AbstractPowerModel},
) where {T <: PSIP.SupplyTechnology}#, U <: ActivePowerVariable}
) where {T<:PSIP.SupplyTechnology}#, U <: ActivePowerVariable}
add_variable_cost!(container, ActivePowerVariable(), devices, formulation) #U()
#add_start_up_cost!(container, StartVariable(), devices, U())
#add_shut_down_cost!(container, StopVariable(), devices, U())
Expand All @@ -327,7 +327,7 @@ function objective_function!(
devices::IS.FlattenIteratorWrapper{T},
#DeviceModel{T, U},
formulation::ContinuousInvestment, #Type{<:PM.AbstractPowerModel},
) where {T <: PSIP.SupplyTechnology}#, U <: BuildCapacity}
) where {T<:PSIP.SupplyTechnology}#, U <: BuildCapacity}
add_capital_cost!(container, BuildCapacity(), devices, formulation) #U()
add_fixed_om_cost!(container, CumulativeCapacity(), devices, formulation)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function construct_technologies!(
add_to_expression!(container, EnergyBalance(), devices, C())

# DemandTotal
# add_expression!(container, DemandTotal(), devices, C())
# add_to_expression!(container, DemandTotal(), devices, C())

return
end
Expand Down Expand Up @@ -83,7 +83,6 @@ function construct_technologies!(
p::PSIP.Portfolio,
::ModelConstructStage,
model::OperationCostModel,
::ModelConstructStage,
technology_model::TechnologyModel{T, B, C, D},
# network_model::NetworkModel{<:PM.AbstractActivePowerModel},
) where {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function construct_technologies!(
# Add objective function from container to JuMP model
update_objective_function!(container)
# Capacity constraint
add_constraints!(container, MaximumCumulativeCapacity(), CumulativeCapacity(), devices)
# add_constraints!(container, MaximumCumulativeCapacity(), CumulativeCapacity(), devices)
# Dispatch constraint
add_constraints!(
container,
Expand Down
5 changes: 5 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
InfrastructureSystems = "2cd47ed4-ca9b-11e9-27f2-ab636a7671f1"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"
PowerSystemCaseBuilder = "f00506e0-b84f-492a-93c2-c0a9afc4364e"
PowerSystems = "bcd98974-b02a-5e2f-9ee0-a103f5c450dd"
PowerSystemsInvestments = "bed98974-b02a-5e2f-9ee0-a103f5c450dd"
PowerSystemsInvestmentsPortfolios = "bed98974-b02a-5e2f-9fe0-a103f8c450dd"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TimeSeries = "9e3dc215-6440-5c97-bce1-76c03772f85e"

[compat]
julia = "^1.6"
Loading

0 comments on commit 88e72b5

Please sign in to comment.