diff --git a/optimierung_pymoo.ipynb b/optimierung_pymoo.ipynb index 1ba4db98f3ce313d081b0c41eb8c9499058a697c..6907b174e62d97307d21b9994a4023fe9db1f99f 100644 --- a/optimierung_pymoo.ipynb +++ b/optimierung_pymoo.ipynb @@ -216,13 +216,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "#defining abstract modell for given Network\n", "import pyomo.environ as pyo\n", - "from pyomo.dataportal import DataPortal\n", "import numpy as np\n", "from sklearn.linear_model import LinearRegression\n", "\n", @@ -235,17 +234,17 @@ "modell.valves = pyo.Set()\n", "\n", "modell.Q_valve=pyo.Param(modell.valves)\n", + "modell.Q = pyo.Param(modell.nodes)\n", "\n", "#Optimierungsvariable\n", "modell.n = pyo.Var(modell.pumps,bounds=(750/3600,1))\n", - "modell.Q = pyo.Var(modell.nodes,bounds=(0.,10.))\n", + "\n", "\n", "#expressions for constraints:\n", "def PumpFlow(modell,pump):\n", " return pyo.summation(np.array([modell.Q[pump]**2, modell.n[pump]*modell.Q[pump], modell.n[pump]**2]),LR_H.coef_,index=[0,1,2])\n", "def Pump_delivery_req(modell,pump):\n", - " return PumpFlow(modell,pump) ==pyo.summation(modell.Q,index=graph.successors(pump))\n", - "\n", + " return PumpFlow(modell,pump) ==modell.Q[pump]\n", "def valve_req_rule(modell,valve):\n", " return modell.Q[valve]>=modell.Q_valve[valve]\n", "\n", @@ -255,13 +254,11 @@ " return modell.Q[node]==pyo.summation(modell.Q,index=graph.predecessors(node))\n", "\n", "#Objective\n", - "def PumpPower(modell):\n", - " return sum(np.dot(\n", - " np.array(\n", - " [modell.Q[i]**3,(modell.Q[i]**2)*modell.n[i],modell.Q[i]*modell.n[i]**2,modell.n[i]**3]\n", - " ),LR_P.coef_\n", - " ) for i in modell.pumps)\n", - "modell.Power_Objective = pyo.Objective(rule=PumpPower,sense=pyo.minimize)" + "def PumpPower(modell,pump):\n", + " return pyo.summation(\n", + " np.array([modell.Q[pump]**3, (modell.Q[pump]**2)*modell.n[pump], modell.Q[pump]*modell.n[pump]**2, modell.n[pump]**3, 1.]),\n", + " LR_P.coef_, index=[0,1,2,3,4])\n", + "modell.Power_Objective = pyo.Objective(modell.pumps,rule=PumpPower,sense=pyo.minimize)" ] }, { @@ -277,117 +274,50 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "SCIP version 9.2.1 [precision: 8 byte] [memory: block] [mode: optimized] [LP solver: Soplex 7.1.3] [GitHash: 0d2d3c7c2d]\n", - "Copyright (c) 2002-2025 Zuse Institute Berlin (ZIB)\n", - "\n", - "External libraries: \n", - " Soplex 7.1.3 Linear Programming Solver developed at Zuse Institute Berlin (soplex.zib.de) [GitHash: 60fd96f2]\n", - " CppAD 20180000.0 Algorithmic Differentiation of C++ algorithms developed by B. Bell (github.com/coin-or/CppAD)\n", - " TinyCThread 1.2 small portable implementation of the C11 threads API (tinycthread.github.io)\n", - " MPIR 3.0.0 Multiple Precision Integers and Rationals Library developed by W. Hart (mpir.org)\n", - " ZIMPL 3.6.2 Zuse Institute Mathematical Programming Language developed by T. Koch (zimpl.zib.de)\n", - " AMPL/MP 690e9e7 AMPL .nl file reader library (github.com/ampl/mp)\n", - " PaPILO 2.4.1 parallel presolve for integer and linear optimization (github.com/scipopt/papilo) (built with TBB) [GitHash: 11974394]\n", - " Nauty 2.8.8 Computing Graph Automorphism Groups by Brendan D. McKay (users.cecs.anu.edu.au/~bdm/nauty)\n", - " sassy 1.1 Symmetry preprocessor by Markus Anders (github.com/markusa4/sassy)\n", - " Ipopt 3.14.16 Interior Point Optimizer developed by A. Waechter et.al. (github.com/coin-or/Ipopt)\n", - "\n", - "user parameter file <scip.set> not found - using default parameters\n", - "read problem <C:\\Users\\Victor\\AppData\\Local\\Temp\\tmpfcunk5gi.pyomo.nl>\n", - "============\n", - "\n", - "original problem has 8 variables (0 bin, 0 int, 0 impl, 8 cont) and 6 constraints\n", - "\n", - "solve problem\n", - "=============\n", - "\n", - "presolving:\n", - "(round 1, fast) 0 del vars, 3 del conss, 0 add conss, 11 chg bounds, 0 chg sides, 0 chg coeffs, 0 upgd conss, 0 impls, 0 clqs\n", - " (0.0s) symmetry computation started: requiring (bin +, int +, cont +), (fixed: bin -, int -, cont -)\n", - " (0.0s) symmetry computation finished: 1 generators found (max: 1500, log10 of symmetry group size: 0.0) (symcode time: 0.00)\n", - "dynamic symmetry handling statistics:\n", - " orbitopal reduction: no components\n", - " orbital reduction: no components\n", - " lexicographic reduction: no permutations\n", - "handled 1 out of 1 symmetry components\n", - "(round 2, exhaustive) 0 del vars, 3 del conss, 1 add conss, 11 chg bounds, 0 chg sides, 0 chg coeffs, 0 upgd conss, 0 impls, 0 clqs\n", - "presolving (3 rounds: 3 fast, 2 medium, 2 exhaustive):\n", - " 0 deleted vars, 3 deleted constraints, 0 added constraints, 11 tightened bounds, 0 added holes, 0 changed sides, 0 changed coefficients\n", - " 0 implications, 0 cliques\n", - "presolved problem has 8 variables (0 bin, 0 int, 0 impl, 8 cont) and 4 constraints\n", - " 1 constraints of type <linear>\n", - " 3 constraints of type <nonlinear>\n", - "Presolving Time: 0.00\n", - "\n", - " time | node | left |LP iter|LP it/n|mem/heur|mdpt |vars |cons |rows |cuts |sepa|confs|strbr| dualbound | primalbound | gap | compl. \n", - " 0.0s| 1 | 0 | 22 | - | 914k | 0 | 25 | 4 | 36 | 0 | 0 | 0 | 0 |-3.474607e+01 | -- | Inf | unknown\n", - "L 0.0s| 1 | 0 | 22 | - | subnlp| 0 | 25 | 4 | 36 | 0 | 0 | 0 | 0 |-3.474607e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 22 | - | 914k | 0 | 25 | 4 | 36 | 0 | 0 | 0 | 0 |-3.474607e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 22 | - | 914k | 0 | 25 | 4 | 36 | 0 | 0 | 0 | 0 |-3.474607e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 26 | - | 920k | 0 | 25 | 4 | 39 | 3 | 1 | 0 | 0 |-1.963132e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 26 | - | 920k | 0 | 25 | 4 | 39 | 3 | 1 | 0 | 0 |-1.963132e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 30 | - | 935k | 0 | 25 | 4 | 42 | 6 | 2 | 0 | 0 |-1.885311e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 33 | - | 939k | 0 | 25 | 4 | 45 | 9 | 3 | 0 | 0 |-1.766937e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 33 | - | 939k | 0 | 25 | 4 | 45 | 9 | 3 | 0 | 0 |-1.766937e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 36 | - | 939k | 0 | 25 | 4 | 47 | 11 | 4 | 0 | 0 |-1.728948e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 37 | - | 941k | 0 | 25 | 4 | 48 | 12 | 5 | 0 | 0 |-1.712829e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 38 | - | 941k | 0 | 25 | 4 | 49 | 13 | 6 | 0 | 0 |-1.701866e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 39 | - | 943k | 0 | 25 | 4 | 50 | 14 | 7 | 0 | 0 |-1.701746e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 41 | - | 951k | 0 | 25 | 4 | 52 | 16 | 8 | 0 | 0 |-1.695801e+01 | 1.151406e+01 | Inf | unknown\n", - " 0.0s| 1 | 0 | 332 | - | 957k | 0 | 25 | 4 | 52 | 16 | 9 | 0 | 0 | 1.150982e+01 | 1.151406e+01 | 0.04%| unknown\n", - " time | node | left |LP iter|LP it/n|mem/heur|mdpt |vars |cons |rows |cuts |sepa|confs|strbr| dualbound | primalbound | gap | compl. \n", - " 0.0s| 1 | 0 | 334 | - | 957k | 0 | 25 | 4 | 54 | 18 | 10 | 0 | 0 | 1.150982e+01 | 1.151406e+01 | 0.04%| unknown\n", - " 0.0s| 1 | 0 | 346 | - | 957k | 0 | 25 | 4 | 37 | 20 | 11 | 0 | 0 | 1.151405e+01 | 1.151406e+01 | 0.00%| unknown\n", - " 0.0s| 1 | 0 | 346 | - | 957k | 0 | 25 | 4 | 20 | 20 | 11 | 0 | 0 | 1.151405e+01 | 1.151406e+01 | 0.00%| unknown\n", - " 0.0s| 1 | 0 | 347 | - | 957k | 0 | 25 | 4 | 21 | 21 | 12 | 0 | 0 | 1.151406e+01 | 1.151406e+01 | 0.00%| unknown\n", - "L 0.0s| 1 | 0 | 347 | - | subnlp| 0 | 25 | 4 | 21 | 21 | 13 | 0 | 0 | 1.151406e+01 | 1.151406e+01 | 0.00%| unknown\n", - " 0.0s| 1 | 0 | 347 | - | 958k | 0 | 25 | 4 | 21 | 21 | 13 | 0 | 0 | 1.151406e+01 | 1.151406e+01 | 0.00%| unknown\n", - "* 0.0s| 1 | 0 | 347 | - | LP | 0 | 25 | 4 | 21 | 21 | 14 | 0 | 0 | 1.151406e+01 | 1.151406e+01 | 0.00%| unknown\n", - "\n", - "SCIP Status : problem is solved [optimal solution found]\n", - "Solving Time (sec) : 0.00\n", - "Solving Nodes : 1\n", - "Primal Bound : +1.15140564709997e+01 (3 solutions)\n", - "Dual Bound : +1.15140564709997e+01\n", - "Gap : 0.00 %\n", - "\n", - "Problem: \n", - "- Lower bound: -inf\n", - " Upper bound: inf\n", - " Number of objectives: 1\n", - " Number of constraints: 0\n", - " Number of variables: 7\n", - " Sense: unknown\n", - "Solver: \n", - "- Status: ok\n", - " Message: optimal solution found\n", - " Termination condition: optimal\n", - " Id: 0\n", - " Error rc: 0\n", - " Time: 0.3383963108062744\n", - "Solution: \n", - "- number of solutions: 0\n", - " number of solutions displayed: 0\n", - "\n", - "n : Size=2, Index=pumps\n", - " Key : Lower : Value : Upper : Fixed : Stale : Domain\n", - " pump1 : 0.20833333333333334 : 0.34519801810114614 : 1 : False : False : Reals\n", - " pump2 : 0.20833333333333334 : 0.4881837415314729 : 1 : False : False : Reals\n", - "Q : Size=6, Index=nodes\n", - " Key : Lower : Value : Upper : Fixed : Stale : Domain\n", - " pump1 : 0.0 : 0.0 : 10.0 : False : False : Reals\n", - " pump2 : 0.0 : 0.0 : 10.0 : False : False : Reals\n", - " source : 0.0 : None : 10.0 : False : True : Reals\n", - " valveA : 0.0 : 1.0 : 10.0 : False : False : Reals\n", - " valveB : 0.0 : 1.0 : 10.0 : False : False : Reals\n", - " valveC : 0.0 : 1.0 : 10.0 : False : False : Reals\n" + "{None: {'nodes': ['source', 'pump1', 'pump2', 'valveA', 'valveB', 'valveC'], 'pumps': ['pump1', 'pump2'], 'valves': ['valveA', 'valveB', 'valveC'], 'Q': [12.0, 12.0, 8.0, 4.0, 4.0, 4.0]}}\n", + "WARNING: Failed to create solver with name 'scipampl': Failed to set\n", + "executable for solver asl. File with name=C:\\Program Files\\SCIPOptSuite\n", + "9.2.1\\bin\\scip.exe either does not exist or it is not executable. To skip this\n", + "validation, call set_executable with validate=False.\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\Steinmann\\AppData\\Roaming\\Python\\Python312\\site-packages\\pyomo\\opt\\base\\solvers.py\", line 162, in __call__\n", + " opt = self._cls[_implicit_solvers[mode]](**kwds)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"C:\\Users\\Steinmann\\AppData\\Roaming\\Python\\Python312\\site-packages\\pyomo\\solvers\\plugins\\solvers\\ASL.py\", line 46, in __init__\n", + " SystemCallSolver.__init__(self, **kwds)\n", + " File \"C:\\Users\\Steinmann\\AppData\\Roaming\\Python\\Python312\\site-packages\\pyomo\\opt\\solver\\shellcmd.py\", line 66, in __init__\n", + " self.set_executable(name=executable, validate=validate)\n", + " File \"C:\\Users\\Steinmann\\AppData\\Roaming\\Python\\Python312\\site-packages\\pyomo\\opt\\solver\\shellcmd.py\", line 115, in set_executable\n", + " raise ValueError(\n", + "ValueError: Failed to set executable for solver asl. File with name=C:\\Program Files\\SCIPOptSuite 9.2.1\\bin\\scip.exe either does not exist or it is not executable. To skip this validation, call set_executable with validate=False.\n", + "ERROR: Rule failed when initializing variable for Var Q with index None:\n", + "AssertionError:\n", + "ERROR: Constructing component 'Q' from data=[12.0, 12.0, 8.0, 4.0, 4.0, 4.0]\n", + "failed:\n", + " AssertionError:\n" + ] + }, + { + "ename": "AssertionError", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mAssertionError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[21], line 14\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[38;5;28mprint\u001b[39m(TestData)\n\u001b[0;32m 13\u001b[0m opt \u001b[38;5;241m=\u001b[39m pyo\u001b[38;5;241m.\u001b[39mSolverFactory(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mscipampl\u001b[39m\u001b[38;5;124m'\u001b[39m, executable\u001b[38;5;241m=\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mC:\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mProgram Files\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mSCIPOptSuite 9.2.1\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mbin\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mscip.exe\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m---> 14\u001b[0m instance \u001b[38;5;241m=\u001b[39m \u001b[43mmodell\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcreate_instance\u001b[49m\u001b[43m(\u001b[49m\u001b[43mTestData\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 15\u001b[0m instance\u001b[38;5;241m.\u001b[39mFlow_constraint\u001b[38;5;241m=\u001b[39mpyo\u001b[38;5;241m.\u001b[39mConstraint(instance\u001b[38;5;241m.\u001b[39mvalves,rule\u001b[38;5;241m=\u001b[39mvalve_req_rule)\n\u001b[0;32m 16\u001b[0m instance\u001b[38;5;241m.\u001b[39mpump_Flow_constraint\u001b[38;5;241m=\u001b[39mpyo\u001b[38;5;241m.\u001b[39mConstraint(instance\u001b[38;5;241m.\u001b[39mpumps,rule\u001b[38;5;241m=\u001b[39mPump_delivery_req)\n", + "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python312\\site-packages\\pyomo\\core\\base\\PyomoModel.py:734\u001b[0m, in \u001b[0;36mModel.create_instance\u001b[1;34m(self, filename, data, name, namespace, namespaces, profile_memory, report_timing, **kwds)\u001b[0m\n\u001b[0;32m 731\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m _namespaces:\n\u001b[0;32m 732\u001b[0m _namespaces\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[1;32m--> 734\u001b[0m \u001b[43minstance\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespaces\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_namespaces\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprofile_memory\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mprofile_memory\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 736\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[0;32m 737\u001b[0m \u001b[38;5;66;03m# Indicate that the model is concrete/constructed\u001b[39;00m\n\u001b[0;32m 738\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[0;32m 739\u001b[0m instance\u001b[38;5;241m.\u001b[39m_constructed \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n", + "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python312\\site-packages\\pyomo\\core\\base\\PyomoModel.py:771\u001b[0m, in \u001b[0;36mModel.load\u001b[1;34m(self, arg, namespaces, profile_memory)\u001b[0m\n\u001b[0;32m 769\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCannot load model model data from with object of type \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 770\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(msg \u001b[38;5;241m%\u001b[39m \u001b[38;5;28mstr\u001b[39m(\u001b[38;5;28mtype\u001b[39m(arg)))\n\u001b[1;32m--> 771\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_load_model_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespaces\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprofile_memory\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mprofile_memory\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python312\\site-packages\\pyomo\\core\\base\\PyomoModel.py:823\u001b[0m, in \u001b[0;36mModel._load_model_data\u001b[1;34m(self, modeldata, namespaces, **kwds)\u001b[0m\n\u001b[0;32m 820\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m component\u001b[38;5;241m.\u001b[39mctype \u001b[38;5;129;01mis\u001b[39;00m Model:\n\u001b[0;32m 821\u001b[0m \u001b[38;5;28;01mcontinue\u001b[39;00m\n\u001b[1;32m--> 823\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_initialize_component\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 824\u001b[0m \u001b[43m \u001b[49m\u001b[43mmodeldata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespaces\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcomponent_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprofile_memory\u001b[49m\n\u001b[0;32m 825\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 827\u001b[0m \u001b[38;5;66;03m# Note: As is, connectors are expanded when using command-line pyomo but not calling model.create(...) in a Python script.\u001b[39;00m\n\u001b[0;32m 828\u001b[0m \u001b[38;5;66;03m# John says this has to do with extension points which are called from commandline but not when writing scripts.\u001b[39;00m\n\u001b[0;32m 829\u001b[0m \u001b[38;5;66;03m# Uncommenting the next two lines switches this (command-line fails because it tries to expand connectors twice)\u001b[39;00m\n\u001b[0;32m 830\u001b[0m \u001b[38;5;66;03m# connector_expander = ConnectorExpander()\u001b[39;00m\n\u001b[0;32m 831\u001b[0m \u001b[38;5;66;03m# connector_expander.apply(instance=self)\u001b[39;00m\n\u001b[0;32m 833\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m profile_memory \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m2\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m pympler_available:\n", + "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python312\\site-packages\\pyomo\\core\\base\\PyomoModel.py:871\u001b[0m, in \u001b[0;36mModel._initialize_component\u001b[1;34m(self, modeldata, namespaces, component_name, profile_memory)\u001b[0m\n\u001b[0;32m 863\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\n\u001b[0;32m 864\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mConstructing \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m on \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m from data=\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 865\u001b[0m declaration\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 868\u001b[0m \u001b[38;5;28mstr\u001b[39m(data),\n\u001b[0;32m 869\u001b[0m )\n\u001b[0;32m 870\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 871\u001b[0m \u001b[43mdeclaration\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconstruct\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 872\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m:\n\u001b[0;32m 873\u001b[0m err \u001b[38;5;241m=\u001b[39m sys\u001b[38;5;241m.\u001b[39mexc_info()[\u001b[38;5;241m1\u001b[39m]\n", + "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python312\\site-packages\\pyomo\\core\\base\\var.py:735\u001b[0m, in \u001b[0;36mVar.construct\u001b[1;34m(self, data)\u001b[0m\n\u001b[0;32m 732\u001b[0m index \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 733\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m 734\u001b[0m \u001b[38;5;66;03m# We do not (currently) accept data for constructing Variables\u001b[39;00m\n\u001b[1;32m--> 735\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m data \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 737\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mindex_set()\u001b[38;5;241m.\u001b[39misfinite() \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_dense:\n\u001b[0;32m 738\u001b[0m \u001b[38;5;66;03m# Note: if the index is not finite, then we cannot\u001b[39;00m\n\u001b[0;32m 739\u001b[0m \u001b[38;5;66;03m# iterate over it. This used to be fatal; now we\u001b[39;00m\n\u001b[0;32m 740\u001b[0m \u001b[38;5;66;03m# just warn\u001b[39;00m\n\u001b[0;32m 741\u001b[0m logger\u001b[38;5;241m.\u001b[39mwarning(\n\u001b[0;32m 742\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mVar \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m indexed by a non-finite set, but declared \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 743\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwith \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdense=True\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m. Reverting to \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdense=False\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m as \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 746\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdense=False\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mname,)\n\u001b[0;32m 747\u001b[0m )\n", + "\u001b[1;31mAssertionError\u001b[0m: " ] } ], @@ -400,14 +330,13 @@ " 'nodes':[key for key in graph.nodes.keys()],\n", " 'pumps':[key for key in graph.nodes.keys() if 'pump' in key],\n", " 'valves':[key for key in graph.nodes.keys() if 'valve' in key],\n", - " 'Q_valve':{'valveA':1.,'valveB':1.,'valveC':1.},\n", - " \n", + " 'Q':[graph.nodes[key]['flow']for key in graph.nodes.keys()]\n", " }\n", "}\n", - "\n", + "print(TestData)\n", "opt = pyo.SolverFactory('scipampl', executable=r'C:\\Program Files\\SCIPOptSuite 9.2.1\\bin\\scip.exe')\n", "instance = modell.create_instance(TestData)\n", - "instance.Flow_constraint=pyo.Constraint(instance.valves,rule=valve_req_rule)\n", + "#instance.Flow_constraint=pyo.Constraint(instance.valves,rule=valve_req_rule)\n", "instance.pump_Flow_constraint=pyo.Constraint(instance.pumps,rule=Pump_delivery_req)\n", "#instance.flow_constraint=pyo.Constraint(instance.nodes,rule=continuity_inflow)\n", "#instance.flow_constraint=pyo.Constraint(instance.nodes,rule=continuity_outflow)\n",