{ "cells": [ { "cell_type": "markdown", "id": "264ce4d9", "metadata": { "Collapsed": "false" }, "source": [ "# ASCII example" ] }, { "cell_type": "markdown", "id": "9909d725", "metadata": { "Collapsed": "false" }, "source": [ "The model setup for this example is available in the following formats:\n", "\n", "- ASCII\n", " - [](ascii_model.ascii)\n", " - [](ascii_data.ascii)\n", " - [](ascii_time.ascii)\n", " - [](ascii_commands.txt)\n", "\n", "This example models the exact same model found in the basic example and runs the same optimization. However, in this script the model is defined in ASCII files and optimized by running a command file. pyshop provides methods for reading models from ASCII files and executing commands in command files. ASCII files have historically been the main method for defining Shop models, and command files have been used for executing commands on such ASCII models. In pyshop it is possible to combine the older approach with the newer python-based one." ] }, { "cell_type": "markdown", "id": "71e18a44", "metadata": { "Collapsed": "false" }, "source": [ "## Imports and settings" ] }, { "cell_type": "markdown", "id": "4a13d19d", "metadata": { "Collapsed": "false" }, "source": [ "The first thing we do is to import the needed packages. You can import whichever packages you like, however we use the following ones for this example:\n", "\n", "- Pandas for structuring our data into dataframes\n", "- pyshop in order to create a SHOP session\n", "- Plotly backend for dynamic graph plotting" ] }, { "cell_type": "code", "execution_count": 1, "id": "d585c5ae", "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "import pandas as pd\n", "from pyshop import ShopSession\n", "pd.options.plotting.backend = \"plotly\"" ] }, { "cell_type": "markdown", "id": "d7910156", "metadata": { "Collapsed": "false" }, "source": [ "## Instancing SHOP" ] }, { "cell_type": "markdown", "id": "fdb33214", "metadata": { "Collapsed": "false" }, "source": [ "In order to have SHOP receive our inputs, run the model we create and give us results, we need to declare a running SHOP session, in this example to the instance 'shop'.\n", "\n", "You may create multiple SHOP sessions simultaneously if needed." ] }, { "cell_type": "code", "execution_count": 2, "id": "b0afa599", "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "# Creating a new SHOP session to the instance 'shop'\n", "shop = ShopSession()" ] }, { "cell_type": "markdown", "id": "fa0967db", "metadata": { "Collapsed": "false" }, "source": [ "We might also want to check the current versions of SHOP and its solvers." ] }, { "cell_type": "code", "execution_count": 3, "id": "4cf7156e", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "'16.7.2 Cplex 20.1.0 Gurobi 7.5 OSI/CBC 2.9 2025-04-11'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Writing out the current version of SHOP\n", "shop.shop_api.GetVersionString()" ] }, { "cell_type": "markdown", "id": "bce09c99", "metadata": { "Collapsed": "false" }, "source": [ "## Reading ASCII files as input data" ] }, { "cell_type": "markdown", "id": "a1abd5b0", "metadata": { "Collapsed": "false" }, "source": [ "We make use of the read_ascii_file function to save data from file into the shop instance we created in the previous cell.\n", "Note that it is important to import files in the correct order, meaning you cannot import something that relies on data that you have not imported from before.\n", "\n", "The example of importing files below show best practice by\n", "\n", "- First importing the data structure and indexing such as the time horizon and time period(s) of the model, and thus its data\n", "- Furthermore importing the model topology and parameters\n", "- Lastly populating the model with data and time series\n", "\n", "Also note that the file(s) must be present in the same working directory/folder as the script/notebook that you are executing, if not using (absolute) paths." ] }, { "cell_type": "markdown", "id": "82d6be12", "metadata": { "Collapsed": "false" }, "source": [ "### Reading and verifying time units" ] }, { "cell_type": "markdown", "id": "d7de5a0e", "metadata": { "Collapsed": "false" }, "source": [ "We start by importing the time period and time resolution from the file test_time.ascii." ] }, { "cell_type": "code", "execution_count": 4, "id": "4fb048f4", "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "# Importing the time period and time resolution\n", "shop.read_ascii_file('ascii_time.ascii')" ] }, { "cell_type": "markdown", "id": "e90b1703", "metadata": { "Collapsed": "false" }, "source": [ "We then verify which time data has been read into the shop instance." ] }, { "cell_type": "code", "execution_count": 5, "id": "497b018e", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "{'starttime': Timestamp('2018-02-27 00:00:00'),\n", " 'endtime': Timestamp('2018-02-28 00:00:00'),\n", " 'timeunit': 'hour',\n", " 'timeresolution': 2018-02-27 1.0\n", " Name: data, dtype: float64}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing time resolution data from the model instance\n", "shop.get_time_resolution()" ] }, { "cell_type": "markdown", "id": "6c1744c0", "metadata": { "Collapsed": "false" }, "source": [ "### Reading and verifying the topology and parameters" ] }, { "cell_type": "markdown", "id": "a79cf898", "metadata": { "Collapsed": "false" }, "source": [ "After the time structure has been correctly imported, we move on to importing the watercourse topology and its static parameters from the file test_model.ascii" ] }, { "cell_type": "code", "execution_count": 6, "id": "03a6c49a", "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "# Importing the model's topology and assosiated parameters\n", "shop.read_ascii_file('ascii_model.ascii')" ] }, { "cell_type": "markdown", "id": "2ca58733", "metadata": { "Collapsed": "false" }, "source": [ "We can then verify what has been read into the _shop_ instance by quering data using different get functions." ] }, { "cell_type": "markdown", "id": "61f724f5", "metadata": { "Collapsed": "false" }, "source": [ "### List reservoirs and reservoir parameters in current model" ] }, { "cell_type": "markdown", "id": "706ac741", "metadata": { "Collapsed": "false" }, "source": [ "In order to retrieve the current reservoir names in the model on the current _shop_ instance, we can use" ] }, { "cell_type": "code", "execution_count": 7, "id": "863e47db", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "['Reservoir1', 'Reservoir2']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the reservoirs in the current model\n", "shop.model.reservoir.get_object_names()" ] }, { "cell_type": "markdown", "id": "a04d6346", "metadata": { "Collapsed": "false" }, "source": [ "Once we have verified the names, we can make use of them for more detailed queries, such as volume/head relations (stage-storage curves)" ] }, { "cell_type": "code", "execution_count": 8, "id": "f5f1e05d", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "0.0 90.0\n", "12.0 100.0\n", "14.0 101.0\n", "Name: 0.0, dtype: float64" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the volume/head relation in Reservoir1\n", "shop.model.reservoir.Reservoir1.vol_head.get()" ] }, { "cell_type": "code", "execution_count": 9, "id": "6a45341a", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "0.0 40.0\n", "5.0 50.0\n", "6.0 51.0\n", "Name: 0.0, dtype: float64" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the volume/head relation in Reservoir2\n", "shop.model.reservoir.Reservoir2.vol_head.get()" ] }, { "cell_type": "markdown", "id": "985ce42d", "metadata": { "Collapsed": "false" }, "source": [ "The flow descriptions" ] }, { "cell_type": "code", "execution_count": 10, "id": "e6960105", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "100.0 0.0\n", "101.0 1000.0\n", "Name: 0.0, dtype: float64" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the overflow description in Reservoir1\n", "shop.model.reservoir.Reservoir1.flow_descr.get()" ] }, { "cell_type": "markdown", "id": "e20a4f83", "metadata": { "Collapsed": "false" }, "source": [ "Attributes like HRL and LRL, can just as easily be retrieved" ] }, { "cell_type": "code", "execution_count": 11, "id": "d84e0f7c", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "100.0" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the highest regulated level (HRL) in Reservoir1\n", "shop.model.reservoir.Reservoir1.hrl.get()" ] }, { "cell_type": "code", "execution_count": 12, "id": "dead5eef", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "90.0" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the lowest regulated level (LRL) in Reservoir1\n", "shop.model.reservoir.Reservoir1.lrl.get()" ] }, { "cell_type": "markdown", "id": "d8f6ab2a", "metadata": { "Collapsed": "false" }, "source": [ "### List plants and plant parameters in current model" ] }, { "cell_type": "markdown", "id": "f324c5c4", "metadata": { "Collapsed": "false" }, "source": [ "The same process is applicable for all other object types, such as plants. We can retrieve the current plant names" ] }, { "cell_type": "code", "execution_count": 13, "id": "5206a775", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "['Plant1', 'Plant2']" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the plants in the current model\n", "shop.model.plant.get_object_names()" ] }, { "cell_type": "markdown", "id": "17f970bc", "metadata": { "Collapsed": "false" }, "source": [ "And then verify what has been read into the model by querying attributes from the objects using the get functions" ] }, { "cell_type": "code", "execution_count": 14, "id": "1dce841c", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the number of generators on Plant1\n", "shop.model.plant.Plant1.num_gen.get()" ] }, { "cell_type": "code", "execution_count": 15, "id": "f2bb635d", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "[0.0001]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the penstock loss on Plant1\n", "shop.model.plant.Plant1.penstock_loss.get()" ] }, { "cell_type": "markdown", "id": "54d00166", "metadata": { "Collapsed": "false" }, "source": [ "### List generators and generator parameters in current model" ] }, { "cell_type": "markdown", "id": "4aefceac", "metadata": { "Collapsed": "false" }, "source": [ "And again, if we want to verify the generators and its parameters, we can do use the same approach as above" ] }, { "cell_type": "code", "execution_count": 16, "id": "bbe163d6", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "['Plant1_G1', 'Plant2_G1']" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the generators in the current model\n", "shop.model.generator.get_object_names()" ] }, { "cell_type": "code", "execution_count": 17, "id": "21adcf2c", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "[25.0 80.0\n", " 90.0 95.0\n", " 100.0 90.0\n", " Name: 90.0, dtype: float64,\n", " 25.0 82.0\n", " 90.0 98.0\n", " 100.0 92.0\n", " Name: 100.0, dtype: float64]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Listing the number of generators on Plant1\n", "shop.model.generator.Plant1_G1.turb_eff_curves.get()" ] }, { "cell_type": "markdown", "id": "ee2f74c8", "metadata": { "Collapsed": "false" }, "source": [ "Since the ascii file also included the connections between reservoirs, plants and generators, we can then verify if the topology is correctly set up, by graphing out the topology tree." ] }, { "cell_type": "code", "execution_count": 18, "id": "34c18943", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "%3\n", "\n", "\n", "\n", "reservoir_Reservoir1\n", "\n", "Reservoir1\n", "\n", "\n", "\n", "plant_Plant1\n", "\n", "Plant1\n", "\n", "\n", "\n", "reservoir_Reservoir1->plant_Plant1\n", "\n", "\n", "\n", "\n", "reservoir_Reservoir2\n", "\n", "Reservoir2\n", "\n", "\n", "\n", "plant_Plant1->reservoir_Reservoir2\n", "\n", "\n", "\n", "\n", "plant_Plant2\n", "\n", "Plant2\n", "\n", "\n", "\n", "reservoir_Reservoir2->plant_Plant2\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Print out the topology\n", "dot = shop.model.build_connection_tree()\n", "display(dot)" ] }, { "cell_type": "markdown", "id": "c4659b16", "metadata": { "Collapsed": "false" }, "source": [ "### Reading and verifying the input data" ] }, { "cell_type": "markdown", "id": "3d32cb74", "metadata": { "Collapsed": "false" }, "source": [ "After the topology and model structure has been set up correctly, we can populate additional data needed for SHOP to run, such as initial reservoir levels, endpoint descriptions (water values), market(s), inflow and other time dependent data, i.e. time series" ] }, { "cell_type": "code", "execution_count": 19, "id": "b0907343", "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "# Importing other input data to the model\n", "shop.read_ascii_file('ascii_data.ascii')" ] }, { "cell_type": "markdown", "id": "c34c74b9", "metadata": { "Collapsed": "false" }, "source": [ "### List initial input data and time series" ] }, { "cell_type": "markdown", "id": "0adfed9a", "metadata": { "Collapsed": "false" }, "source": [ "We can retrieve the newly imported static data out for inspection like before;" ] }, { "cell_type": "code", "execution_count": 20, "id": "d0b0609a", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Retrieve the start volume of Reservoir1\n", "shop.model.reservoir.Reservoir1.start_vol.get()" ] }, { "cell_type": "code", "execution_count": 21, "id": "e2202d4e", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "39.7" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Retrieve the endpoint description (water value) of Reservoir1\n", "\n", "shop.model.reservoir.Reservoir1.energy_value_input.get()" ] }, { "cell_type": "markdown", "id": "6ab45682", "metadata": { "Collapsed": "false" }, "source": [ "But now we are also introduced to time dependent data in time series" ] }, { "cell_type": "code", "execution_count": 22, "id": "bee104b7", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/plain": [ "2018-02-27 00:00:00 101.0\n", "2018-02-27 01:00:00 50.0\n", "2018-02-27 02:00:00 50.0\n", "2018-02-27 03:00:00 50.0\n", "2018-02-27 04:00:00 50.0\n", "2018-02-27 05:00:00 50.0\n", "2018-02-27 06:00:00 50.0\n", "2018-02-27 07:00:00 50.0\n", "2018-02-27 08:00:00 50.0\n", "2018-02-27 09:00:00 50.0\n", "2018-02-27 10:00:00 50.0\n", "2018-02-27 11:00:00 50.0\n", "2018-02-27 12:00:00 50.0\n", "2018-02-27 13:00:00 50.0\n", "2018-02-27 14:00:00 50.0\n", "2018-02-27 15:00:00 50.0\n", "2018-02-27 16:00:00 50.0\n", "2018-02-27 17:00:00 50.0\n", "2018-02-27 18:00:00 50.0\n", "2018-02-27 19:00:00 50.0\n", "2018-02-27 20:00:00 50.0\n", "2018-02-27 21:00:00 50.0\n", "2018-02-27 22:00:00 50.0\n", "2018-02-27 23:00:00 50.0\n", "Name: inflow, dtype: float64" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Retrieve the inflow to Reservoir1\n", "shop.model.reservoir.Reservoir1.inflow.get()" ] }, { "cell_type": "markdown", "id": "dfa6450c", "metadata": { "Collapsed": "false" }, "source": [ "Which in many cases also can be useful to plot" ] }, { "cell_type": "code", "execution_count": 23, "id": "fe26bf93", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "hovertemplate": "=inflow
time=%{x}
m3/s=%{y}", "legendgroup": "inflow", "line": { "color": "#636efa", "dash": "solid" }, "marker": { "symbol": "circle" }, "mode": "lines", "name": "inflow", "orientation": "v", "showlegend": true, "type": "scatter", "x": [ "2018-02-27T00:00:00", "2018-02-27T01:00:00", "2018-02-27T02:00:00", "2018-02-27T03:00:00", "2018-02-27T04:00:00", "2018-02-27T05:00:00", "2018-02-27T06:00:00", "2018-02-27T07:00:00", "2018-02-27T08:00:00", "2018-02-27T09:00:00", "2018-02-27T10:00:00", "2018-02-27T11:00:00", "2018-02-27T12:00:00", "2018-02-27T13:00:00", "2018-02-27T14:00:00", "2018-02-27T15:00:00", "2018-02-27T16:00:00", "2018-02-27T17:00:00", "2018-02-27T18:00:00", "2018-02-27T19:00:00", "2018-02-27T20:00:00", "2018-02-27T21:00:00", "2018-02-27T22:00:00", "2018-02-27T23:00:00" ], "xaxis": "x", "y": [ 101.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0 ], "yaxis": "y" } ], "layout": { "legend": { "title": { "text": "" }, "tracegroupgap": 0 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "sequentialminus": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Inflow to Reservoir 1" }, "xaxis": { "anchor": "y", "domain": [ 0.0, 1.0 ], "title": { "text": "time" } }, "yaxis": { "anchor": "x", "domain": [ 0.0, 1.0 ], "title": { "text": "m3/s" } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Plotting the inflow to Reservoir 1\n", "shop.model.reservoir.Reservoir1.inflow.get().plot(title=\"Inflow to Reservoir 1\", labels=dict(index=\"time\", value=\"m3/s\", variable=\"\"))" ] }, { "cell_type": "markdown", "id": "ba3c2abb", "metadata": { "Collapsed": "true" }, "source": [ "For a complete overview of all objects and attributes you can query data from, see the [SHOP reference manual](https://sintefshop.no/documentation/reference/)'s [attribute section](https://sintefshop.no/documentation/reference/attributes/), or use a Language Server Protocol (LSP) in your IDE (which is included in the [Lab](https://sintefshop.no/lab/)) as illustrated below for an even easier and dynamic workflow." ] }, { "cell_type": "markdown", "id": "a558f595", "metadata": { "Collapsed": "false" }, "source": [ "![lsp.png](lsp.png)" ] }, { "cell_type": "markdown", "id": "b7aa6c66", "metadata": { "Collapsed": "false" }, "source": [ "## Running SHOP optimizations and commands from file" ] }, { "cell_type": "markdown", "id": "ecd1805a", "metadata": { "Collapsed": "false" }, "source": [ "Once the model is fully imported and verified, we can then call for the optimizer. Since we now control all commands from a separate command file, this file needs to be inspected (and optinally altered and saved) before running the file in pyshop by using the _run_command_file_ command." ] }, { "cell_type": "code", "execution_count": 24, "id": "1f1d9c5e", "metadata": { "Collapsed": "false" }, "outputs": [], "source": [ "# Running the command file and executing SHOP based on the imported input\n", "shop.run_command_file('.', 'ascii_commands.txt')" ] }, { "cell_type": "markdown", "id": "7b8cda6e", "metadata": { "Collapsed": "false" }, "source": [ "In this example, we chose CPLEX as the solver, enabled universal MIP and ran three full and three incremental iterations before we wrote the results to files.\n", "\n", "For a full overview of the possible commands you can use when running SHOP, see the [SHOP reference manual](https://sintefshop.no/documentation/reference/)'s [command section](https://sintefshop.no/documentation/reference/commands/)." ] }, { "cell_type": "markdown", "id": "e540569b", "metadata": { "Collapsed": "false" }, "source": [ "## Plotting the results" ] }, { "cell_type": "markdown", "id": "f522142a", "metadata": { "Collapsed": "false" }, "source": [ "Finally, we can review the result from SHOP by plotting the graphs we want." ] }, { "cell_type": "code", "execution_count": 25, "id": "d64c0279", "metadata": { "Collapsed": "false" }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "hovertemplate": "=Reservoir1
Time=%{x}
Mm3=%{y}", "legendgroup": "Reservoir1", "line": { "color": "#636efa", "dash": "solid" }, "marker": { "symbol": "circle" }, "mode": "lines", "name": "Reservoir1", "orientation": "v", "showlegend": true, "type": "scatter", "x": [ "2018-02-27T00:00:00", "2018-02-27T01:00:00", "2018-02-27T02:00:00", "2018-02-27T03:00:00", "2018-02-27T04:00:00", "2018-02-27T05:00:00", "2018-02-27T06:00:00", "2018-02-27T07:00:00", "2018-02-27T08:00:00", "2018-02-27T09:00:00", "2018-02-27T10:00:00", "2018-02-27T11:00:00", "2018-02-27T12:00:00", "2018-02-27T13:00:00", "2018-02-27T14:00:00", "2018-02-27T15:00:00", "2018-02-27T16:00:00", "2018-02-27T17:00:00", "2018-02-27T18:00:00", "2018-02-27T19:00:00", "2018-02-27T20:00:00", "2018-02-27T21:00:00", "2018-02-27T22:00:00", "2018-02-27T23:00:00", "2018-02-28T00:00:00" ], "xaxis": "x", "y": [ 2.4, 2.5377282198374878, 2.493167081533055, 2.449280987192546, 2.406073440438254, 2.3635478771078384, 2.3217076641286885, 2.280556098425323, 2.2400964058616863, 2.160000000000001, 2.016000000000001, 1.872000000000001, 1.7280000000000009, 1.5840000000000007, 1.4400000000000006, 1.2960000000000005, 1.1520000000000004, 1.0080000000000002, 0.8640000000000001, 0.7200000000000001, 0.5760000000000001, 0.43200000000000005, 0.28800000000000003, 0.14400000000000002, 0.0 ], "yaxis": "y" }, { "hovertemplate": "=Reservoir2
Time=%{x}
Mm3=%{y}", "legendgroup": "Reservoir2", "line": { "color": "#EF553B", "dash": "solid" }, "marker": { "symbol": "circle" }, "mode": "lines", "name": "Reservoir2", "orientation": "v", "showlegend": true, "type": "scatter", "x": [ "2018-02-27T00:00:00", "2018-02-27T01:00:00", "2018-02-27T02:00:00", "2018-02-27T03:00:00", "2018-02-27T04:00:00", "2018-02-27T05:00:00", "2018-02-27T06:00:00", "2018-02-27T07:00:00", "2018-02-27T08:00:00", "2018-02-27T09:00:00", "2018-02-27T10:00:00", "2018-02-27T11:00:00", "2018-02-27T12:00:00", "2018-02-27T13:00:00", "2018-02-27T14:00:00", "2018-02-27T15:00:00", "2018-02-27T16:00:00", "2018-02-27T17:00:00", "2018-02-27T18:00:00", "2018-02-27T19:00:00", "2018-02-27T20:00:00", "2018-02-27T21:00:00", "2018-02-27T22:00:00", "2018-02-27T23:00:00", "2018-02-28T00:00:00" ], "xaxis": "x", "y": [ 1.5, 1.4018717801625122, 1.3024329184669448, 1.2023190128074541, 1.1015265595617458, 1.0000521228921613, 0.8978923358713111, 0.7950439015746769, 0.6915035941383134, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999, 0.627599999999999 ], "yaxis": "y" } ], "layout": { "legend": { "title": { "text": "" }, "tracegroupgap": 0 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "sequentialminus": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Reservoir trajectories" }, "xaxis": { "anchor": "y", "domain": [ 0.0, 1.0 ], "title": { "text": "Time" } }, "yaxis": { "anchor": "x", "domain": [ 0.0, 1.0 ], "title": { "text": "Mm3" } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Defining a plot dataframe to combine multiple time series in the same dataframe for plotting purposes (NB: they need to have the same time index)\n", "plot = pd.DataFrame()\n", "\n", "# Retrieving the reservoir trajectories adding them to the plot dataframe\n", "plot[\"Reservoir1\"]=shop.model.reservoir.Reservoir1.storage.get()\n", "plot[\"Reservoir2\"]=shop.model.reservoir.Reservoir2.storage.get()\n", "\n", "# Plotting the figure\n", "plot.plot(title=\"Reservoir trajectories\", labels=dict(index=\"Time\", value=\"Mm3\", variable=\"\"))" ] }, { "cell_type": "markdown", "id": "1d85e36d", "metadata": { "Collapsed": "false" }, "source": [ "## Files" ] }, { "cell_type": "markdown", "id": "b7ed1fde", "metadata": { "Collapsed": "false" }, "source": [ "(ascii_model.ascii)=\n", "\n", "### ascii_model.ascii" ] }, { "cell_type": "code", "execution_count": 26, "id": "2192648b", "metadata": { "Collapsed": "false", "tags": [ "remove-input" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "RESERVOIR attributes Reservoir1\n", "#ID;Water_course;Type;Maxvol;Lrl;Hrl;\n", "10000 0 0 12.00000 90.00000 100.00000 \n", "\n", "RESERVOIR vol_head Reservoir1\n", "#Id;Number;Reference;Pts;X_unit;Y_unit\n", "10000 0 0.000 9 MM3 METER\n", "# x_value; y_value;\n", " 0.00000 90.00000 \n", " 12.00000 100.00000 \n", " 14.00000 101.00000 \n", "\n", "RESERVOIR flow_descr Reservoir1\n", "#Id;Number;Reference;Pts;X_unit;Y_unit\n", "10000 0 0.000 2 METER M3/S\n", "# x_value; y_value;\n", " 100.00000 0.000 \n", " 101.00000 1000.000 \n", "\n", "PLANT attributes Plant1 \n", "#Id;Water_course;Type;Bid_area;Prod_area;Num_units;Num_pumps;\n", "10500 0 0 1 1 1 0 \n", "#Num_main_seg;Num_penstock;Time_delay;Prod_factor;Outlet_line;\n", " 1 1 0 0.000 40.000 \n", "#Main tunnell loss\n", "0.0002\n", "#penstock loss\n", "0.0001\n", "\n", "GENERATOR attributes Plant1 1 \n", "#Id Type Penstock Nom_prod Min_prod Max_prod Start_cost \n", "10600 0 1 100.0 25.0 100.0 500.000 \n", "\n", "GENERATOR gen_eff_curve Plant1 1 \n", "#Id;Number;Reference;Pts;X_unit;Y_unit\n", "10600 0 0.000 2 MW %\n", "# x_value; y_value;\n", " 0.0 95.0 \n", "100.0 98.0 \n", "\n", "GENERATOR turb_eff_curves Plant1 1\n", "#Id;Number;Reference;Pts;X_unit;Y_unit\n", "10600 0 90.000 3 M3/S %\n", "# x_value; y_value;\n", " 25.0 80.0\n", " 90.0 95.0\n", "100.0 90.0\n", "\n", "GENERATOR turb_eff_curves Plant1 1\n", "#Id;Number;Reference;Pts;X_unit;Y_unit\n", "10600 0 100.000 3 M3/S %\n", "# x_value; y_value;\n", " 25.0 82.0\n", " 90.0 98.0\n", "100.0 92.0\n", "\n", "RESERVOIR attributes Reservoir2\n", "#ID;Water_course;Type;Maxvol;Lrl;Hrl;\n", "10000 0 0 5.00000 40.00000 50.00000 \n", "\n", "RESERVOIR vol_head Reservoir2\n", "#Id;Number;Reference;Pts;X_unit;Y_unit\n", "10000 0 0.000 9 MM3 METER\n", "# x_value; y_value;\n", " 0.00000 40.00000 \n", " 5.00000 50.00000 \n", " 6.00000 51.00000 \n", "\n", "RESERVOIR flow_descr Reservoir2\n", "#Id;Number;Reference;Pts;X_unit;Y_unit\n", "10000 0 0.000 2 METER M3/S\n", "# x_value; y_value;\n", " 50.00000 0.000 \n", " 51.00000 1000.000 \n", "\n", "PLANT attributes Plant2 \n", "#Id;Water_course;Type;Bid_area;Prod_area;Num_units;Num_pumps;\n", "10500 0 0 1 1 1 0 \n", "#Num_main_seg;Num_penstock;Time_delay;Prod_factor;Outlet_line;\n", " 1 1 0 0.000 0.000 \n", "#Main tunnell loss\n", "0.0002\n", "#penstock loss\n", "0.0001\n", "\n", "GENERATOR attributes Plant2 1 \n", "#Id Type Penstock Nom_prod Min_prod Max_prod Start_cost \n", "10600 0 1 100.0 25.0 100.0 500.000 \n", "\n", "GENERATOR gen_eff_curve Plant2 1 \n", "#Id;Number;Reference;Pts;X_unit;Y_unit\n", "10600 0 0.000 2 MW %\n", "# x_value; y_value;\n", " 0.0 95.0 \n", "100.0 98.0 \n", "\n", "GENERATOR turb_eff_curves Plant2 1\n", "#Id;Number;Reference;Pts;X_unit;Y_unit\n", "10600 0 90.000 3 M3/S %\n", "# x_value; y_value;\n", " 25.0 80.0\n", " 90.0 95.0\n", "100.0 90.0\n", "\n", "GENERATOR turb_eff_curves Plant2 1\n", "#Id;Number;Reference;Pts;X_unit;Y_unit\n", "10600 0 100.000 3 M3/S %\n", "# x_value; y_value;\n", " 25.0 82.0\n", " 90.0 98.0\n", "100.0 92.0\n", "\n", "# From_type/To_type From_name To_name\n", "CONNECT RESERVOIR/PLANT Reservoir1 Plant1\n", "CONNECT PLANT/RESERVOIR Plant1 Reservoir2\n", "CONNECT RESERVOIR/PLANT Reservoir2 Plant2\n", "\n" ] } ], "source": [ "with open('ascii_model.ascii', 'r') as f:\n", " print(f.read())" ] }, { "cell_type": "markdown", "id": "ca795371", "metadata": { "Collapsed": "false" }, "source": [ "(ascii_data.ascii)=\n", "\n", "### ascii_data.ascii" ] }, { "cell_type": "code", "execution_count": 27, "id": "dc4ccb0f", "metadata": { "Collapsed": "false", "tags": [ "remove-input" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "STARTRES \t2 METER\n", "# Name\tStart reservoir(meters above sea level)\n", "Reservoir1\t92\n", "Reservoir2\t43\n", "\n", "RESERVOIR\tinflow\tReservoir1\n", "#\tId\tnumber\tstarttime\t\ttime_unit\tperiod\tdata_type\ty_unit\tnpts\n", "\t0\t0\t2018022700\tHOUR\t\t8760\t\t-1\tM3/S\t1\n", "#\ttime\t\ty\n", "2018022700\t101\n", "2018022701\t50\n", "\n", "RESERVOIR\tinflow\tReservoir2\n", "#\tId\tnumber\tstarttime\t\ttime_unit\tperiod\tdata_type\ty_unit\tnpts\n", "\t0\t0\t2018022700\tHOUR\t\t8760\t\t-1\tM3/S\t1\n", "#\ttime\t\ty\n", "2018022700\t0\n", "\n", "RESERVOIR endpoint_desc Reservoir1\n", "#\tNumber\tRef\tNpkt\tx_unit\ty_unit\n", "0\t1\t0\t1\tMm3\tKroner\n", "0\t39.7\n", "\n", "RESERVOIR endpoint_desc Reservoir2\n", "#\tNumber\tRef\tNpkt\tx_unit\ty_unit\n", "0\t1\t0\t1\tMm3\tKroner\n", "0\t38.6\n", "\n", "MULTI_MARKET\tprice_buy\t1\n", "#\tId\tnumber\tstarttime\t\ttime_unit\tperiod\tdata_type\ty_unit\tnpts\n", "\t0\t0\t2018022700\tHOUR\t\t8760\t\t-1\tM3/S\t1\n", "#\ttime\t\ty\n", "2018022700\t40.01\n", "\n", "MULTI_MARKET\tprice_sale\t1\n", "#\tId\tnumber\tstarttime\t\ttime_unit\tperiod\tdata_type\ty_unit\tnpts\n", "\t0\t0\t2018022700\tHOUR\t\t8760\t\t-1\tM3/S\t1\n", "#\ttime\t\ty\n", "2018022700\t39.99\n", "\n", "MULTI_MARKET\tmax_buy\t1\n", "#\tId\tnumber\tstarttime\t\ttime_unit\tperiod\tdata_type\ty_unit\tnpts\n", "\t0\t0\t2018022700\tHOUR\t\t8760\t\t-1\tM3/S\t1\n", "#\ttime\t\ty\n", "2018022700\t9999\n", "\n", "MULTI_MARKET\tmax_sale\t1\n", "#\tId\tnumber\tstarttime\t\ttime_unit\tperiod\tdata_type\ty_unit\tnpts\n", "\t0\t0\t2018022700\tHOUR\t\t8760\t\t-1\tM3/S\t1\n", "#\ttime\t\ty\n", "2018022700\t9999\n", "\n" ] } ], "source": [ "with open('ascii_data.ascii', 'r') as f:\n", " print(f.read())" ] }, { "cell_type": "markdown", "id": "f3ddd766", "metadata": { "Collapsed": "false" }, "source": [ "(ascii_time.ascii)=\n", "\n", "### ascii_time.ascii" ] }, { "cell_type": "code", "execution_count": 28, "id": "bfd81a00", "metadata": { "Collapsed": "false", "tags": [ "remove-input" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "OPTIMIZATION time\n", "#Start_time; End_time;\n", "20180227\t20180228\n", "\n", "# N_full_iterations Accuracy;\n", "OPTIMIZATION 100 -1\n", "#Id Number Start_Time Time_unit Period Data_type Y_unit Pts\n", "\t0\t0\t20180227\tHOUR\t525600\t0\tHOUR\t1\n", "# Time Time_resolution\n", "2018022700\t1.000\n", "\n" ] } ], "source": [ "with open('ascii_time.ascii', 'r') as f:\n", " print(f.read())" ] }, { "cell_type": "markdown", "id": "db59f811", "metadata": { "Collapsed": "false" }, "source": [ "(ascii_commands.txt)=\n", "\n", "### ascii_commands.txt" ] }, { "cell_type": "code", "execution_count": 29, "id": "a6261994", "metadata": { "Collapsed": "false", "tags": [ "remove-input" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "set solver /cplex\n", "\n", "set universal_mip /on\n", "\n", "start sim 3\n", "set code /inc\n", "start sim 3\n", "\n", "return simres res.txt\n", "return simres /gen res_gen.txt\n", "\n" ] } ], "source": [ "with open('ascii_commands.txt', 'r') as f:\n", " print(f.read())" ] } ], "metadata": { "jupytext": { "text_representation": { "extension": ".md", "format_name": "myst", "format_version": 0.13, "jupytext_version": "1.13.8" } }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.9" }, "source_map": [ 14, 18, 30, 34, 42, 50, 54, 60, 67, 71, 78, 82, 95, 99, 103, 110, 114, 121, 125, 129, 136, 140, 144, 148, 155, 159, 166, 173, 177, 184, 188, 195, 202, 206, 210, 217, 221, 228, 235, 239, 243, 250, 257, 261, 269, 273, 277, 284, 288, 292, 299, 307, 311, 318, 322, 328, 332, 336, 340, 344, 351, 357, 361, 365, 379, 383, 389, 397, 403, 411, 417, 425, 431 ] }, "nbformat": 4, "nbformat_minor": 5 }