Commit 6b98eb5b authored by Niina Helistö's avatar Niina Helistö
Browse files

Updating the template for linking invest and schedule models

parent bb665abf
* =============================================================================
* --- Save investments results in changes.inc file to be used in child setups -
* --- Save investments results in .inc files to be used in other models -------
* =============================================================================
* Output file streams
* Output file streams for static data
file f_changes /'output\changes.inc'/;
f_changes.lw = 26; // Field width of set label output, default in GAMS is 12, increase as needed
f_changes.pw = 500; // Number of characters that may be placed on a single row of the page, default in GAMS is 255, increase as needed
// Field width of set label output, default in GAMS is 12, increase as needed
f_changes.lw = 26;
// Number of characters that may be placed on a single row of the page, default
// in GAMS is 255, increase as needed
f_changes.pw = 500;
put f_changes
* Do not allow investments in the child setups
loop(unit,
put "p_unit('", unit.tl, "', 'maxUnitCount') = 0;"/;
);
* --- Update investment data in the subsequent models -------------------------
* Update the number of subunits in the child setups (rounded here to the nearest integer)
// Number of subunits
put "* Update the number of subunits in the subsequent models"/;
loop(unit${r_invest(unit)},
// subunits rounded to the nearest integer
tmp = round(r_invest(unit), 0)
put "p_unit('", unit.tl, "', 'unitCount') = p_unit('", unit.tl, "', 'unitCount') + ", tmp, ";"/;
put "p_unit('", unit.tl, "', 'unitCount') = p_unit('", unit.tl,
"', 'unitCount') + ", tmp, ";"/;
);
* Update capacity values in the child setups
// Unit capacities
put /;
put "* Update unit capacities in the subsequent models"/;
loop(gnu(grid, node, unit)${r_invest(unit)},
// subunits rounded to the nearest integer
tmp = round(r_invest(unit), 0) * p_gnu(grid, node, unit, 'unitSize');
put "p_gnu('", grid.tl, "', '", node.tl, "', '", unit.tl, "', 'capacity') = p_gnu('", grid.tl, "', '", node.tl, "', '", unit.tl, "', 'capacity') + ", tmp, ";"/;);
* Example updates for storage units (commented out at the moment, use names etc. that work in your case)
*p_gnBoundaryPropertiesForStates('battery_grid', 'battery_node', 'upwardLimit', 'useConstant') = 1;
*p_gnBoundaryPropertiesForStates('battery_grid', 'battery_node', 'upwardLimit', 'multiplier') = 1;
*p_gnBoundaryPropertiesForStates('battery_grid', 'battery_node', 'upwardLimit', 'constant')
* = p_gnu('battery_grid', 'battery_node', 'battery_charge', 'upperLimitCapacityRatio') * p_gnu('battery_grid', 'battery_node', 'battery_charge', 'capacity');
*p_gnu('battery_grid', 'battery_node', 'battery_charge', 'upperLimitCapacityRatio') = 0;
*uGroup('battery_charge', 'battery_online_group1') = yes;
*uGroup('battery_discharge', 'battery_online_group1') = yes;
*p_groupPolicy('battery_online_group1', 'constrainedOnlineTotalMax') = p_unit('battery_charge', 'unitCount');
*p_groupPolicy3D('battery_online_group1', 'constrainedOnlineMultiplier', 'battery_charge') = 1;
*p_groupPolicy3D('battery_online_group1', 'constrainedOnlineMultiplier', 'battery_discharge') = 1;
* Do not allow investments in the child setups (commented out at the moment)
*loop(gn2n_directional(grid, node, node_),
* put "p_gnn('", grid.tl, "', '", node.tl, "', '", node_.tl, "', 'transferCapMax') = 0;"/;
* put "p_gnn('", grid.tl, "', '", node_.tl, "', '", node.tl, "', 'transferCapMax') = 0;"/;
*);
* Update transmission capacity in the child setups
loop(gn2n_directional(grid, node, node_)${sum(t_invest, r_investTransfer(grid, node, node_, t_invest))},
tmp = sum(t_invest, r_investTransfer(grid, node, node_, t_invest));
put "p_gnn('", grid.tl, "', '", node.tl, "', '", node_.tl, "', 'transferCap') = p_gnn('", grid.tl, "', '", node.tl, "', '", node_.tl, "', 'transferCap') + ", tmp, ";"/;
put "p_gnn('", grid.tl, "', '", node_.tl, "', '", node.tl, "', 'transferCap') = p_gnn('", grid.tl, "', '", node_.tl, "', '", node.tl, "', 'transferCap') + ", tmp, ";"/;
if(gnu_output(grid, node, unit),
put "p_gnu_io('", grid.tl, "', '", node.tl, "', '", unit.tl,
"', 'output', 'capacity')"/;
put " = p_gnu_io('", grid.tl, "', '", node.tl, "', '", unit.tl,
"', 'output', 'capacity') + ", tmp, ";"/;
);
if(gnu_input(grid, node, unit),
put "p_gnu_io('", grid.tl, "', '", node.tl, "', '", unit.tl,
"', 'input', 'capacity')"/;
put " = p_gnu_io('", grid.tl, "', '", node.tl, "', '", unit.tl,
"', 'input', 'capacity') + ", tmp, ";"/;
);
);
// Storage limits
put /;
put "* Update storage investments in the subsequent models"/;
loop(gnu(grid, node, unit)
${r_invest(unit) and p_gnu(grid, node, unit, 'upperLimitCapacityRatio')},
// subunits rounded to the nearest integer
tmp = p_gnu(grid, node, unit, 'upperLimitCapacityRatio')
* round(r_invest(unit), 0) * p_gnu(grid, node, unit, 'unitSize');
put "p_gnBoundaryPropertiesForStates('", grid.tl, "', '", node.tl,
"', 'upwardLimit', 'constant')"/;
put " = p_gnBoundaryPropertiesForStates('",
grid.tl, "', '", node.tl, "', 'upwardLimit', 'constant') + ", tmp, ";"/;
);
* --- Update online group constraints in the subsequent models ----------------
// Limit the number of online units to the largest unitCount in the group
// Intended especially for limiting simultaneous charging and discharging
// The groups and uGroups for these constraints should be defined already in
// the investment model data - just without parameter values.
put /;
put "* Update online group constraints in the subsequent models"/;
set online_group(group) / /; // Note! Update this set manually
loop(online_group(group),
loop(uGroup(unit, group),
put "p_groupPolicyUnit('", group.tl,
"', 'constrainedOnlineMultiplier', '", unit.tl, "') = 1;"/;
);
put "p_groupPolicy('", group.tl, "', 'constrainedOnlineTotalMax')"/;
put " = smax(uGroup(unit, '", group.tl,
"'), p_unit(unit, 'unitCount'));"/;
);
* --- Do not allow investments in the subsequent models -----------------------
* This section can be omitted if the input data of the subsequent models
* already disables investments and enables constant upwardLimit for storage.
*$ontext
// Units
put /;
put "* Do not allow unit investments in the subsequent models"/;
loop(unit,
put "p_unit('", unit.tl, "', 'maxUnitCount') = 0;"/;
);
// Transfer links
put /;
put "* Do not allow transfer link investments in the subsequent models"/;
loop(gn2n_directional(grid, node, node_),
put "p_gnn('", grid.tl, "', '", node.tl, "', '", node_.tl,
"', 'transferCapInvLimit') = 0;"/;
put "p_gnn('", grid.tl, "', '", node_.tl, "', '", node.tl,
"', 'transferCapInvLimit') = 0;"/;
);
// Storage
put /;
put "* Do not allow storage investments in the subsequent models"/;
loop(gnu(grid, node, unit)$p_gnu(grid, node, unit, 'upperLimitCapacityRatio'),
if(gnu_output(grid, node, unit),
put "p_gnu_io('", grid.tl, "', '", node.tl, "', '", unit.tl,
"', 'output', 'upperLimitCapacityRatio') = 0;"/;
);
if(gnu_input(grid, node, unit),
put "p_gnu_io('", grid.tl, "', '", node.tl, "', '", unit.tl,
"', 'input', 'upperLimitCapacityRatio') = 0;"/;
);
put "p_gnBoundaryPropertiesForStates('", grid.tl, "', '", node.tl,
"', 'upwardLimit', 'useConstant') = 1;"/;
);
*$offtext
putclose;
* Output file streams for data to be read in the loop
file f_loop_changes /'output\loop_changes.inc'/;
// Field width of set label output, default in GAMS is 12, increase as needed
f_loop_changes.lw = 26;
// Number of characters that may be placed on a single row of the page, default
// in GAMS is 255, increase as needed
f_loop_changes.pw = 500;
put f_loop_changes
* --- Update investment data in the subsequent models -------------------------
// Transfer capacity
put "* Update transfer capacities in the subsequent models"/;
loop(gn2n_directional(grid, node, node_)
${sum(t_invest, r_investTransfer(grid, node, node_, t_invest))},
tmp = 0;
tmp_ = 0;
loop(t_invest(t),
tmp = p_gnn(grid, node, node_, 'transferCap') + tmp
+ r_investTransfer(grid, node, node_, t);
tmp_ = p_gnn(grid, node_, node, 'transferCap') + tmp_
+ r_investTransfer(grid, node, node_, t);
put "if(ord(tSolve) >= ", ord(t), " - 1,"/;
put " p_gnn('", grid.tl, "', '", node.tl, "', '", node_.tl,
"', 'transferCap')"/;
put " = ", tmp, ";"/;
put " p_gnn('", grid.tl, "', '", node_.tl, "', '", node.tl,
"', 'transferCap')"/;
put " = ", tmp_, ";"/;
put ");"/;
);
);
putclose;
......@@ -143,6 +143,12 @@ Option clear = ts_node_;
Option clear = ts_vomCost_;
Option clear = ts_startupCost_;
* =============================================================================
* --- Read changes or additions to the inputdata through loop_changes.inc file.
* =============================================================================
$ifthen exist '%input_dir%/loop_changes.inc'
$$include '%input_dir%/loop_changes.inc'
$endif
* =============================================================================
* --- Determine the forecast-intervals included in the current solve ----------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment