diff --git a/tutorial/transport/dantzig_model_linopy.py b/tutorial/transport/dantzig_model_linopy.py index 4bc15ddd..0a55effe 100644 --- a/tutorial/transport/dantzig_model_linopy.py +++ b/tutorial/transport/dantzig_model_linopy.py @@ -14,6 +14,7 @@ def create_parameter( def create_dantzig_model(run: Run) -> linopy.Model: + """Creates new linopy.Model for Dantzig's problem based on ixmp4.Run.""" m = linopy.Model() i = pd.Index(run.optimization.indexsets.get("i").elements, name="Canning Plants") j = pd.Index(run.optimization.indexsets.get("j").elements, name="Markets") @@ -60,6 +61,7 @@ def create_dantzig_model(run: Run) -> linopy.Model: def read_dantzig_solution(model: linopy.Model, run: Run) -> None: + """Reads the Dantzig solution from linopy.Model to ixmp4.Run.""" # Handle objective # TODO adding fake marginals here until Variables don't require this column anymore # Can't add units if this column was not declared above. Better stored as Scalar @@ -87,7 +89,7 @@ def read_dantzig_solution(model: linopy.Model, run: Run) -> None: # The following don't seem to be typed correctly by linopy # Add supply data supply_data = { - "i": ["seattle", "san-diego"], + "i": run.optimization.indexsets.get("i").elements, "levels": model.constraints["Observe supply limit at plant i"].data.rhs, # type: ignore "marginals": model.constraints["Observe supply limit at plant i"].data.dual, # type: ignore } @@ -95,7 +97,7 @@ def read_dantzig_solution(model: linopy.Model, run: Run) -> None: # Add demand data demand_data = { - "j": ["new-york", "chicago", "topeka"], + "j": run.optimization.indexsets.get("j").elements, "levels": model.constraints["Satisfy demand at market j"].data.rhs, # type: ignore "marginals": model.constraints["Satisfy demand at market j"].data.dual, # type: ignore } diff --git a/tutorial/transport/linopy_transport.ipynb b/tutorial/transport/linopy_transport.ipynb index 17ace268..37e6483d 100644 --- a/tutorial/transport/linopy_transport.ipynb +++ b/tutorial/transport/linopy_transport.ipynb @@ -244,7 +244,7 @@ "a.add(data=a_data)\n", "\n", "# Demand at market j in cases\n", - "b = run.optimization.parameters.create(\"b\", constrained_to_indexsets=\"j\")\n", + "b = run.optimization.parameters.create(\"b\", constrained_to_indexsets=[\"j\"])\n", "# ... or a pd.DataFrame\n", "b_data = pd.DataFrame(\n", " [\n", @@ -349,7 +349,7 @@ "source": [ "### Defining `Variable`s and `Equation`s in the scenario\n", "\n", - "The levels and marginals of these variables and equations will be imported to the scenario when reading the model solution." + "The levels and marginals of these `Variable`s and `Equation`s will be imported to the scenario when reading the model solution." ] }, { @@ -387,7 +387,7 @@ "\n", "In this tutorial, we solve the tutorial using the ``highs`` solver in linopy. \n", "\n", - "The ``create_dantzig_model()`` function is a convenience shortcut for setting up a linopy model correctly for the datzig scenario. Please see ``linopy_model.py`` for details.\n", + "The ``create_dantzig_model()`` function is a convenience shortcut for setting up a linopy model correctly for the dantzig scenario. Please see ``linopy_model.py`` for details.\n", "\n", "The solution data are stored with the model object automatically. ``store_dantzig_solution()`` then stores them in the ixmp4 objects." ] @@ -403,10 +403,10 @@ " read_dantzig_solution,\n", ")\n", "\n", - "m = create_dantzig_model(run=run)\n", - "m.solve(\"highs\")\n", + "linopy_model = create_dantzig_model(run=run)\n", + "linopy_model.solve(\"highs\")\n", "\n", - "read_dantzig_solution(model=m, run=run)" + "read_dantzig_solution(model=linopy_model, run=run)" ] }, { @@ -433,7 +433,7 @@ "outputs": [], "source": [ "# Display the quantities transported from canning plants to demand locations\n", - "x.data" + "pd.DataFrame(x.data)" ] }, {