Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Market bid cost with pwl cost curve #1182

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions src/devices_models/devices/common/objective_function/market_bid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ function _add_variable_cost_to_objective!(
initial_time = get_initial_time(container)
incremental_cost_curves = PSY.get_incremental_offer_curves(cost_function)
decremental_cost_curves = PSY.get_decremental_offer_curves(cost_function)
if isnothing(decremental_cost_curves)
error("Component $(component_name) is not allowed to participate as a demand.")
end
# if isnothing(decremental_cost_curves)
# error("Component $(component_name) is not allowed to participate as a demand.")
# end
#=
variable_cost_forecast = PSY.get_variable_cost(
component,
Expand Down Expand Up @@ -583,3 +583,33 @@ function _add_service_bid_cost!(
end

function _add_service_bid_cost!(::OptimizationContainer, ::PSY.Component, ::PSY.Service) end

function _add_vom_cost_to_objective!(
container::OptimizationContainer,
::T,
component::PSY.Component,
op_cost::PSY.MarketBidCost,
::U,
) where {T <: VariableType, U <: AbstractDeviceFormulation}
incremental_cost_curves = PSY.get_incremental_offer_curves(op_cost)
decremental_cost_curves = PSY.get_decremental_offer_curves(op_cost)
power_units = PSY.get_power_units(incremental_cost_curves)
vom_cost = PSY.get_vom_cost(incremental_cost_curves)
multiplier = 1.0 # VOM Cost is always positive
cost_term = PSY.get_proportional_term(vom_cost)
iszero(cost_term) && return
base_power = get_base_power(container)
device_base_power = PSY.get_base_power(component)
cost_term_normalized = get_proportional_cost_per_system_unit(
cost_term,
power_units,
base_power,
device_base_power,
)
for t in get_time_steps(container)
exp =
_add_proportional_term!(container, T(), d, cost_term_normalized * multiplier, t)
add_to_expression!(container, ProductionCostExpression, exp, d, t)
end
return
end
107 changes: 107 additions & 0 deletions test/run_market_bid_cost.jl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is useful but it shouldn't be checked out into the repo. I'd like the original test to be fixed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted the file.

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Pkg
Pkg.activate("test")
Pkg.instantiate()

using Revise
using PowerSystems
using PowerSystemCaseBuilder
using PowerSimulations
using StorageSystemsSimulations
using HydroPowerSimulations
using Xpress
using Logging
# using PlotlyJS
using Dates
using JuMP
using InfrastructureSystems
using DataStructures
using TimeSeries
const PSY = PowerSystems
const PSI = PowerSimulations
const PSB = PowerSystemCaseBuilder
const PM = PSI.PowerModels

##################################
### Load Test Function Helpers ###
##################################

include("test_utils/solver_definitions.jl")
include("test_utils/operations_problem_templates.jl")

sys = PSB.build_system(PSITestSystems, "c_sys5_re")

show_components(sys, ThermalStandard, [:active_power])
show_components(sys, RenewableDispatch, [:active_power])

th_solitude = get_component(ThermalStandard, sys, "Solitude")
th_brighton = get_component(ThermalStandard, sys, "Brighton")
re_A = get_component(RenewableDispatch, sys, "WindBusA")
get_bus(th_solitude)

#### Add MarketBidCost

proposed_offer_curve = make_market_bid_curve(
[0.0, 100.0, 200.0, 300.0, 400.0, 500.0, 600.0],
[25.0, 25.5, 26.0, 27.0, 28.0, 30.0],
10.0
)

set_operation_cost!(
th_solitude,
MarketBidCost(;
no_load_cost=0.0,
start_up = (hot=3.0, warm=0.0, cold=0.0),
shut_down = 1.5,
incremental_offer_curves = proposed_offer_curve
)
)

#### PowerSimulations Stuff ###

template = ProblemTemplate(
NetworkModel(
CopperPlatePowerModel;
duals = [CopperPlateBalanceConstraint],
),
)
set_device_model!(template, ThermalStandard, ThermalBasicUnitCommitment)
#set_device_model!(template, ThermalStandard, ThermalDispatchNoMin)
set_device_model!(template, PowerLoad, StaticPowerLoad)
set_device_model!(template, RenewableDispatch, RenewableFullDispatch)

model = DecisionModel(
template,
sys;
name = "UC",
optimizer = optimizer_with_attributes(Xpress.Optimizer, "MIPRELSTOP" => 1e-3),
system_to_file = false,
store_variable_names = true,
calculate_conflict = true,
optimizer_solve_log_print = true,
)

build!(model; output_dir = mktempdir(; cleanup = true))

vars = model.internal.container.variables
cons = model.internal.container.constraints

power_balance =
cons[PowerSimulations.ConstraintKey{CopperPlateBalanceConstraint, System}("")]
lb_thermal = cons[PowerSimulations.ConstraintKey{
ActivePowerVariableLimitsConstraint,
ThermalStandard,
}(
"lb",
)]

solve!(model)

res = OptimizationProblemResults(model)

p_th = read_variable(res, "ActivePowerVariable__ThermalStandard")

param_re = read_parameter(res, "ActivePowerTimeSeriesParameter__RenewableDispatch")
p_re = read_variable(res, "ActivePowerVariable__RenewableDispatch")

# $/(per-unit MW) = $/(100 MW) = 0.01 $/MW
price = read_dual(res, "CopperPlateBalanceConstraint__System")