-
Notifications
You must be signed in to change notification settings - Fork 5
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
Piecewise Cost Representation in Matrix Export #36
Comments
@msdogan I'm assuming you want to wait on a response to implement this change? |
@jrmerz yes. We discussed this before, but I will bring this up again in the next hobbes meeting. |
PROBLEM: WHAT HEC-PRM IS DOING: example: Shasta hydropower storage curve example: Coachella ag penalty curve example: Banks pumping plant operating cost curve DISCUSSION:
WHAT WE SHOULD DO: I don't know how matrix exporting script works but adding a 'if statement' might solve the issue. If curves don't cross axis lines, then extend. And, for operating cost curves, extend it to very large number (max ub) on the right hand side. Any comments? @jdherman @josue-medellin @mimijenkins1 @qjhart |
Mustafa's suggestions for extending the penalty/cost curves to intersect However, for a downward sloping penalty that does not intersect the x-axis Either way, I would tend to agree with extending the negative cost slope On Tue, 13 Sep 2016 10:29:50 -0700, Mustafa Dogan
Marion W. Jenkins, PhD |
Couple of thoughts:
I think our goal in general is to make sure the full operating range of these reservoirs/pumps/canals/whatever all have costs assigned to them. Anything outside of that range shouldn't matter. |
@mimijenkins1 all red lines are coming from HEC-PRM output DSS file. For hydropower penalty, our case is Fig 8 (c) is HEC-PRM Manual. Looks like the curve is extrapolated to y-axis but not x-axis. Below is paired data (from output DSS) of the same plot above. @jdherman we don't have any flags for penalty data. As you wrote, it is based on +/- whether it is operating cost or demand penalty. For your third point, yes there is a storage capacity and it makes it a little complicating. Maybe that's why HEC-PRM didn't extend it. Then, if there is a capacity (upper bound), we should extend until upper bound? I think current code cuts the cost curve at the physical upper bound (capacity) value if it extends more than capacity when creating piecewise pieces. Am I right @jrmerz ? Maybe if we can extend before the code that reads and cuts, the script can take care of it. |
Think we need to bring in @qjhart for this. The upper bound is either set to the current cost |
@jrmerz all good questions. Should have been clearer about these.
|
For the 2. question, we would want to do this extension only for links/nodes with piecewise cost. Most links/nodes don't have piecewise cost, so for them k=0, c=0 or constant c. I can think of two solutions: If we have piecewise representation (k>0) and c = 0, then we might have a problem. |
@msdogan I don't think we will have the "piecewise representation (k>0) and c = 0" representation, because as Mimi said, a mixed linear-integer program will not be able to solve that. i.e. can't have the same slope on multiple pieces of the piecewise representation. |
piecewise_processing_first_pass.txt So I have implemented a first pass at this. I'm still trying to figure out how I will verify things are being done correctly. For now I am just adding console log to modifications made by the new peicewise logic. I still need to review some of the code here, but take a glance a let me know how things look. This is for one Month, 1999-12-1. |
Oops. Ignore that last file. Found issue. New file coming... |
Always find the issue after you post... the first pass was not looking at the bounds correctly. Here is the updated output. |
@jrmerz this is great, but if possible can we get actual results (extension) from your script? We can look at examples for each case and plot them to see how they are looking. |
Sure, let me know if you would like a different format. In the file, the costs array (in JSON format) is dumped after changes are made. Note, I realized the last file did not reflect your most resent calvin-network-data pull request. This current file does. |
@msdogan I have added the new version of the code. Couple notes, I have branched this code, so to test from the repository (ignore first step if you have already cloned repo). git clone https://github.com/ucd-cws/calvin-network-tools
cd calvin-network-tools
git checkout extrapolated-cost
node bin/cnf.bin.js matrix --verbose --format=csv --start=1999-12 --stop=2000-02 --ts=. --to=network --max-ub=1000000 Let me know if you have any issues. |
@jrmerz the code above is giving me an error
|
Oops. missed a step. So steps should be git clone https://github.com/ucd-cws/calvin-network-tools
cd calvin-network-tools
git checkout extrapolated-cost
npm install
node bin/cnf.bin.js matrix --verbose --format=csv --start=1999-12 --stop=2000-02 --ts=. --to=network --max-ub=1000000 |
thanks @jrmerz it looks good in the first glance. I will take a look at cost curves for each case and let you know with my findings. |
Here are comparison of S09I05PD, S09I05 and pyvin. Notes:
Findings:
Examples for each "if" case:
example: D5.1999-12-31 D73.1999-12-31
example: C44.1999-12-31 C88.1999-12-31
example: HU207.1999-12-31 CVPM08S.1999-12-31
SR_NML.1999-12-31 D670.1999-12-31
PMP_Banks.1999-12-31 D800.1999-12-31
PROBLEM
|
@jrmerz could you please let me know if there is any link falling into "should never happen!" category? Thanks |
@msdogan The following links are in the 'should never happen' category:
|
okay, well. Sometimes it can happen :) Those are outliars. Here what metada says for penalty on C309-PMP_Old_R "CCWD has three sources of water, all of which have monthly varying water quality. The penalty set is to reflect the salinity damage of each source (based on TDS above the 250 mg/l at 50 cents/ mg/l TDS) plus the fixed treatement and local distrubtion and conveyance costs ($299/af). REVISED 12-27-2002 MJ - removed $299 from the paired data cost, so it reflects only salinity damage; aslo recomputed see revised file on Roselyn in folder "G03G07"" I compared your extension to HEC-PRM, and it complies with that. So, we are good. You can remove the warning for this case :) Only thing is that UB should be max_UB without adding a new link, because there is no physical upper bound. So, in the example below, there are two links with the same cost. In this case, the solver wouldn't know which link to use.
|
k, pushed to npm @ calvin-network-tools@1.0.48 |
Closing the issue. The solution from pyvin is infeasible but we are going to tackle with that in a separate issue. |
Ok, latest code pushed to npm calvin-network-tools@1.0.49 |
@jrmerz @jdherman reopening this issue. I think it is related to piecewise cost representation for the first piece. I run a one-year model between Oct-2002 and Sep-2003 in debug mode and it was feasible. I created another dataset for Oct-1998 and Sep-2003 but pyomo gave an error because for some months lb > ub. Below is the list, it is happening for
|
the list above was only when lb > ub.
|
the In our CALVIN/pyvin system this becomes an issue for reservoirs releases where there is hydropower. In piecewise cost, there is maximum capacity that represents turbine capacity, at which cost is zero. However, we do not put a upper bound on reservoir releases. The reason may be that turbine is not only release, there is also spilling, which I don't think possible to represent in linear programming, at least we don't represent right now. When slope is positive, there is no issue, our extension complies with (e) and (f).
First suggestion is what HEC-PRM is doing even if we add a piece with zero cost. Since other pieces will have negative cost, it will use those first before using arc with zero cost. We have to make sure to put physical upper bound to prevent flooding or dumping water (zero cost) for necessary links, which is why we are adding target deliveries as upper bounds for ag and urban. @jdherman @mimijenkins1 @josue-medellin Please let us know what you are thinking and then we can proceed. Thanks. |
Thanks for summarizing @msdogan . If I'm understanding right, it sounds like this problem is specific to reservoirs (SR_*), because reservoirs have an upper bound in the dataset that does NOT reflect the physical release capacity, only the turbine capacity. Our logic before did not account for this. So when we enforce this upper bound, the reservoir can't release enough water to meet mass balance constraints. If this is the case, then the only modification in the matrix export script is to not enforce My guess is this also is causing the @jrmerz does this make sense? This would be:
|
@jdherman this is a issue for links where there is a downward sloping cost (negative) but there is no physical upper bound. Reservoir release is one example. And it makes sense not to put a physical upper bound because you can release through turbines or spill with a zero benefit. And usually spilling capacities are big. As you said, when we enforce turbine capacity for reservoir releases (from piecewise curve), it does not release enough water. |
Ok -- I'm fine with making it general. But we still have the problem of identifying where this is happening, because we have to somehow separate out the links for which the upper bound value in the dataset is not representative of the real-world upper bound. How to do that? It must be based on a specific type of nodes/links. |
Could this be a declarative flag on the data? So Any link/node can declaratively specify 'representative' v 'real-world' upper bound? And then code would look like:
This would assume real world by default. So the flag would be representative = true. |
Something like this, yea. Our problem in this case is that the "upper bound" in the data for reservoirs actually represents the turbine capacity, not the flow capacity constraint. So it is representative of something, just not what we want it to be. @msdogan can you think of other types of links where this might be happening? Or is it only reservoir release links? |
I can't think of any other types of links but @jrmerz could you do a formal check for this case: piecewise cost, slope negative and no physical upper bound? |
Here is the current list meeting the above conditions: PWP_Mojave-SR_SLW, SR_NML-D670, SR_LL_ENR-SR_DNP, SR_HTH-C44, SR_DNP-D662, SR_MCR-D642, D541-Surp_Delta, SR_SHA-D5, SR_ORO-C23, SR_ENG-C28, SR_BUL-C27, D5-D73, SR_TAB-C25, SR_FOL-D9, D9-D85, C23-C25, SR_CLE-D94, PWP_AAC-C151 |
Current thought:
|
Copying this from Mustafa's email just so we have a record of it: Okay, while checking the network, I found another bug in big "if statement" logic. https://cloud.githubusercontent.com/assets/1936620/18797140/505be90c-8181-11e6-84f6-d0ef0ae7e0eb.JPG For left-hand side extension for slope negative and physical lb does not exist case, our statement says: enforce lb=0 for k=0 case. But does not say anything for the ub. Before the extension, ub on the k=0 case (sorry I forgot start from 0 index in the sketch below) is b - a. After extension it should be b, but it is still b - a in network matrix because we forgot to add this in the if statement. Sorry Justin, but could you update your code again to include that. Hopefully this would be the last modification for cost extension. |
Logic updated. But the cost of slope negative, Physical Lower Bound does not exist, we only modify lb if lb wasn't already equal to 0. Currently, no nodes/links meet this condition. In fact no nodes/links have slope negative and an undefined Physical Lower Bound. |
Just saw another example might be related to piecewise cost representation issue: Infeasibility is for reservior node SR_MCR in the final month. Here is all inflows to this node: The outflow of this node is: There is about 37.1309 difference between inflow and outflow. |
I found the bug, the upper bound on the first piece (k=0) of SR_MCR storage link should be 242.287 not 126.214554.
We probably missed this in the big |
@jrmerz I am closing this issue. It is getting too large and hard to follow. We will open a new one if we get any problem with piecewise cost representation in the future. |
agreed. |
@jrmerz @qjhart the piecewise cost representation seems to have some bugs in it. We have one extra link in the beginning (when k = 0), and it is constrained. Below, there is a link with piecewise cost
HU507 to AGG_COACH
. There are two months: July and August. I wonder why it constrains first pieces (k=0) with zero cost. This is true for all links with piecewise representation.Aha, I think I got the reason. For
HU507 to AGG_COACH
for July, our penalty data starts from18.49
. Below this number there is nothing. Because of that, your code constrains it. Below are figures from penalty data DSS.I think the decision was to extend the beginning and ending penalties. As far as I know, HEC-PRM does that automatically. Am I right @qjhart @mimijenkins1?
The text was updated successfully, but these errors were encountered: