# Accessing cost data in UnitCommitment.jl

**URL:** <https://discourse.julialang.org/t/accessing-cost-data-in-unitcommitment-jl/103510>\
**Category:** Optimization (Mathematical)\
**Created:** [September 4, 2023, 2:05pm UTC](https://discourse.julialang.org/t/accessing-cost-data-in-unitcommitment-jl/103510 "2023-09-04T14:05:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skelly5](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@skelly5](https://discourse.julialang.org/u/skelly5)\
**Post date:** [September 4, 2023, 2:05pm UTC](https://discourse.julialang.org/t/accessing-cost-data-in-unitcommitment-jl/103510/1 "2023-09-04T14:05:11Z")

</div>

I’m trying to access data for generator cost in the UnitCommitment.jl. I was wondering, in matpower/case2383wp/2017-02-01, why do some of the generators (such as generators 12 and 39) have an empty cost\_segments, while other generators’ cost\_segments have a length of 4?

Below is the error that is thrown by my code followed by a minimal working example.

ERROR: BoundsError: attempt to access 0-element Vector{UnitCommitment.CostSegment} at index [1]  
Stacktrace:  
[1] getindex(A::Vector{UnitCommitment.CostSegment}, i1::Int64)  
@ Base .\array.jl:805  
[2] top-level scope  
@ c:\Users\Guest\MWE.jl:8

# Minimal working example:

using CSV, DataFrames  
using UnitCommitment

instance = UnitCommitment.read\_benchmark(“matpower/case2383wp/2017-02-01”,)  
cost = Dict()  
for g in 1:length(instance.units)  
unit = instance.units[g]  
cost[g] = unit.cost\_segments[1].cost[1]  
end

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [September 4, 2023, 7:10pm UTC](https://discourse.julialang.org/t/accessing-cost-data-in-unitcommitment-jl/103510/2 "2023-09-04T19:10:27Z")

</div>

Hi there, welcome to the forum.

I dont know the answer but @axavier is the person who can help.

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [September 5, 2023, 2:52am UTC](https://discourse.julialang.org/t/accessing-cost-data-in-unitcommitment-jl/103510/3 "2023-09-05T02:52:09Z")

</div>

This may be because some generators have time-dependent costs, while others do not.

See this part of the documentation:  
[https://anl-ceeesa.github.io/UnitCommitment.jl/0.3/format/#Production-costs-and-limits](https://anl-ceeesa.github.io/UnitCommitment.jl/0.3/format/#Production-costs-and-limits)

---

<div class="post-metadata">

**Author:** ![g001234](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/g001234/32/2956_2.png) [@g001234](https://discourse.julialang.org/u/g001234)\
**Post date:** [October 15, 2023, 11:35pm UTC](https://discourse.julialang.org/t/accessing-cost-data-in-unitcommitment-jl/103510/4 "2023-10-15T23:35:11Z")

</div>

The issue is resolved here: [Accessing cost data in UnitCommitment.jl · Issue #46 · ANL-CEEESA/UnitCommitment.jl · GitHub](https://github.com/ANL-CEEESA/UnitCommitment.jl/issues/46#issuecomment-1763512759).
