Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Learning Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Steinmann, Victor
Learning Python
Commits
3cdccb21
Commit
3cdccb21
authored
5 months ago
by
Steinmann
Browse files
Options
Downloads
Patches
Plain Diff
added expression for all pumps in graph.nodes
parent
ba6abf31
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
optimierung_pymoo.ipynb
+1
-0
1 addition, 0 deletions
optimierung_pymoo.ipynb
with
1 addition
and
0 deletions
optimierung_pymoo.ipynb
+
1
−
0
View file @
3cdccb21
...
@@ -226,6 +226,7 @@
...
@@ -226,6 +226,7 @@
"\n",
"\n",
"\n",
"\n",
"TestData={None:{'G':{None:graph},'LR':{None:LR_H}}}\n",
"TestData={None:{'G':{None:graph},'LR':{None:LR_H}}}\n",
"#[node for node in graph.nodes if 'pump' in node]\n",
"#Optimierungsgleichung\n",
"#Optimierungsgleichung\n",
"#instance=modell.create_instance(graph,LR_H)\n",
"#instance=modell.create_instance(graph,LR_H)\n",
"#instance.obj = pyo.Objective(expr=sum(PumpPower(modell.Q[i],modell.n[i],LR_P) for i in modell.pumps),sense=min)\n"
"#instance.obj = pyo.Objective(expr=sum(PumpPower(modell.Q[i],modell.n[i],LR_P) for i in modell.pumps),sense=min)\n"
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Formulieren der Optimierungsgleichung in pymoo
Formulieren der Optimierungsgleichung in pymoo
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Es gilt die Kontinuitätsgleichung:
Es gilt die Kontinuitätsgleichung:
$
\S
igma
\d
ot{V}_k(t) = O$
$
\S
igma
\d
ot{V}_k(t) = O$
und die aus der Topologie resultierende Inzidenzmatrix $A_i$
und die aus der Topologie resultierende Inzidenzmatrix $A_i$
sowie die aus dem Pumpenkennfeld folgende Beziehung:
sowie die aus dem Pumpenkennfeld folgende Beziehung:
$
\D
elta p=
\a
lpha_1 Q^2+
\a
lpha_2 Q n+
\a
lpha_3 n^2 : n
\i
n
\{
0
\}
\c
up [n_{
\m
athrm{min}},n_{
\m
athrm{max}}] $
$
\D
elta p=
\a
lpha_1 Q^2+
\a
lpha_2 Q n+
\a
lpha_3 n^2 : n
\i
n
\{
0
\}
\c
up [n_{
\m
athrm{min}},n_{
\m
athrm{max}}] $
$P=
\b
eta_1 Q^3+
\b
eta_2 Q^2 n+
\b
eta_3 Q n^2+
\b
eta_4n^3+
\b
eta_5$
$P=
\b
eta_1 Q^3+
\b
eta_2 Q^2 n+
\b
eta_3 Q n^2+
\b
eta_4n^3+
\b
eta_5$
und die beziehung für den Druckverlust an den Ventilen:
und die beziehung für den Druckverlust an den Ventilen:
$
\D
elta p_{
\m
athrm{loss}} = -
\f
rac{1}{2}
\v
arrho
\z
eta
\l
eft(
\f
rac{Q}{A}
\r
ight)^2 = -l Q^2 :l
\i
n [l_{
\m
athrm{min}}:
\i
nfty )$
$
\D
elta p_{
\m
athrm{loss}} = -
\f
rac{1}{2}
\v
arrho
\z
eta
\l
eft(
\f
rac{Q}{A}
\r
ight)^2 = -l Q^2 :l
\i
n [l_{
\m
athrm{min}}:
\i
nfty )$
nun soll für einen Gegebenen Volumenstrom $Q$ eine Optimale Drehzahl bestimmt werden, welche die Pumpenlesitung minimiert.
nun soll für einen Gegebenen Volumenstrom $Q$ eine Optimale Drehzahl bestimmt werden, welche die Pumpenlesitung minimiert.
$$
$$
\b
egin{align
*
}
\b
egin{align
*
}
\m
athrm{min}
\s
um_{p
\i
n
\m
athcal{P}} Po_{p}
\\
\m
athrm{min}
\s
um_{p
\i
n
\m
athcal{P}} Po_{p}
\\
Q_p = Q_{
\m
athrm{target}, i}
\\
Q_p = Q_{
\m
athrm{target}, i}
\\
Q_p
Q_p
, n
\e
psilon [n_{min},n_{max}]
\\
, n
\e
psilon [n_{min},n_{max}]
\\
\o
verrightarrow{n} = (1,n,n^2,n^3)^T
\\
\o
verrightarrow{n} = (1,n,n^2,n^3)^T
\\
min P = A
\o
verrightarrow{n}
\\
min P = A
\o
verrightarrow{n}
\\
-n
\l
eq n_{min}
\\
-n
\l
eq n_{min}
\\
n
\l
eq n_{max}
n
\l
eq n_{max}
\e
nd{align
*
}
\e
nd{align
*
}
$$
$$
Förderhöhe als constraint continuität fomulieren pro strang
Förderhöhe als constraint continuität fomulieren pro strang
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
!
pip
install
pyomo
!
pip
install
pyomo
```
```
%% Output
%% Output
Defaulting to user installation because normal site-packages is not writeable
Defaulting to user installation because normal site-packages is not writeable
Collecting pyomo
Collecting pyomo
Downloading Pyomo-6.8.2-py3-none-any.whl.metadata (8.0 kB)
Downloading Pyomo-6.8.2-py3-none-any.whl.metadata (8.0 kB)
Collecting ply (from pyomo)
Collecting ply (from pyomo)
Downloading ply-3.11-py2.py3-none-any.whl.metadata (844 bytes)
Downloading ply-3.11-py2.py3-none-any.whl.metadata (844 bytes)
Downloading Pyomo-6.8.2-py3-none-any.whl (3.7 MB)
Downloading Pyomo-6.8.2-py3-none-any.whl (3.7 MB)
---------------------------------------- 0.0/3.7 MB ? eta -:--:--
---------------------------------------- 0.0/3.7 MB ? eta -:--:--
---------------------------------------- 3.7/3.7 MB 73.6 MB/s eta 0:00:00
---------------------------------------- 3.7/3.7 MB 73.6 MB/s eta 0:00:00
Downloading ply-3.11-py2.py3-none-any.whl (49 kB)
Downloading ply-3.11-py2.py3-none-any.whl (49 kB)
Installing collected packages: ply, pyomo
Installing collected packages: ply, pyomo
Successfully installed ply-3.11 pyomo-6.8.2
Successfully installed ply-3.11 pyomo-6.8.2
WARNING: The script pyomo.exe is installed in 'C:\Users\steinmann\AppData\Roaming\Python\Python312\Scripts' which is not on PATH.
WARNING: The script pyomo.exe is installed in 'C:\Users\steinmann\AppData\Roaming\Python\Python312\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
[notice] A new release of pip is available: 24.2 -> 24.3.1
[notice] A new release of pip is available: 24.2 -> 24.3.1
[notice] To update, run: C:\Program Files\Python312\python.exe -m pip install --upgrade pip
[notice] To update, run: C:\Program Files\Python312\python.exe -m pip install --upgrade pip
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
#Pump-Powercurve and Pump-Hightcurve
#Pump-Powercurve and Pump-Hightcurve
import
regression_own
import
regression_own
(
LR_H
,
LR_P
)
=
regression_own
.
regress_pump
()
(
LR_H
,
LR_P
)
=
regression_own
.
regress_pump
()
print
(
LR_H
,
LR_P
)
print
(
LR_H
,
LR_P
)
```
```
%% Output
%% Output
R^20.9998289611292903
R^20.9998289611292903
R^20.9994449560888792
R^20.9994449560888792
LinearRegression(fit_intercept=False) LinearRegression()
LinearRegression(fit_intercept=False) LinearRegression()
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
#Graph constroctor
#Graph constroctor
import
multiDiGraph
as
gr
import
multiDiGraph
as
gr
nodes
=
[
'
source
'
,
'
pump1
'
,
'
pump2
'
,
'
valveA
'
,
'
valveB
'
,
'
valveC
'
]
nodes
=
[
'
source
'
,
'
pump1
'
,
'
pump2
'
,
'
valveA
'
,
'
valveB
'
,
'
valveC
'
]
graph
=
gr
.
construct_graph
(
'
source
'
,(
'
source
'
,
'
pump1
'
),(
'
pump1
'
,
'
valveC
'
),
graph
=
gr
.
construct_graph
(
'
source
'
,(
'
source
'
,
'
pump1
'
),(
'
pump1
'
,
'
valveC
'
),
(
'
pump1
'
,
'
pump2
'
),(
'
pump2
'
,
'
valveA
'
),(
'
pump2
'
,
'
valveB
'
),(
'
valveA
'
,
'
source
'
),(
'
valveB
'
,
'
source
'
),(
'
valveC
'
,
'
source
'
))
(
'
pump1
'
,
'
pump2
'
),(
'
pump2
'
,
'
valveA
'
),(
'
pump2
'
,
'
valveB
'
),(
'
valveA
'
,
'
source
'
),(
'
valveB
'
,
'
source
'
),(
'
valveC
'
,
'
source
'
))
```
```
%% Output
%% Output
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
networkx
as
nx
import
networkx
as
nx
Mtrx
=
nx
.
incidence_matrix
(
graph
,
nodes
)
Mtrx
=
nx
.
incidence_matrix
(
graph
,
nodes
)
print
(
Mtrx
)
print
(
Mtrx
)
```
```
%% Output
%% Output
<Compressed Sparse Column sparse array of dtype 'float64'
<Compressed Sparse Column sparse array of dtype 'float64'
with 16 stored elements and shape (6, 8)>
with 16 stored elements and shape (6, 8)>
Coords Values
Coords Values
(0, 0) 1.0
(0, 0) 1.0
(1, 0) 1.0
(1, 0) 1.0
(1, 1) 1.0
(1, 1) 1.0
(5, 1) 1.0
(5, 1) 1.0
(1, 2) 1.0
(1, 2) 1.0
(2, 2) 1.0
(2, 2) 1.0
(0, 3) 1.0
(0, 3) 1.0
(5, 3) 1.0
(5, 3) 1.0
(2, 4) 1.0
(2, 4) 1.0
(3, 4) 1.0
(3, 4) 1.0
(2, 5) 1.0
(2, 5) 1.0
(4, 5) 1.0
(4, 5) 1.0
(0, 6) 1.0
(0, 6) 1.0
(3, 6) 1.0
(3, 6) 1.0
(0, 7) 1.0
(0, 7) 1.0
(4, 7) 1.0
(4, 7) 1.0
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Durchfluss aus Incidenzmatrix beerechnen
Durchfluss aus Incidenzmatrix beerechnen
Zeilen = knoten
Zeilen = knoten
Spalten = kanten
Spalten = kanten
Summe pro knoten = 0
Summe pro knoten = 0
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
#defining abstract modell for given Network
#defining abstract modell for given Network
import
pyomo.environ
as
pyo
import
pyomo.environ
as
pyo
import
numpy
as
np
import
numpy
as
np
from
sklearn.linear_model
import
LinearRegression
from
sklearn.linear_model
import
LinearRegression
modell
=
pyo
.
AbstractModel
()
modell
=
pyo
.
AbstractModel
()
#notwendige Mengen zur Berechnung der Constraints
#notwendige Mengen zur Berechnung der Constraints
modell
.
nodes
=
pyo
.
Set
()
modell
.
nodes
=
pyo
.
Set
()
modell
.
pumps
=
pyo
.
Set
()
modell
.
pumps
=
pyo
.
Set
()
modell
.
valves
=
pyo
.
Set
()
modell
.
valves
=
pyo
.
Set
()
#Parameter zur berechnung
#Parameter zur berechnung
modell
.
Q
=
pyo
.
Param
(
modell
.
nodes
)
modell
.
Q
=
pyo
.
Param
(
modell
.
nodes
)
modell
.
n
=
pyo
.
Param
(
modell
.
pumps
)
modell
.
n
=
pyo
.
Param
(
modell
.
pumps
)
#Optimierungsvariable
#Optimierungsvariable
modell
.
P
=
pyo
.
Var
(
modell
.
pumps
)
modell
.
P
=
pyo
.
Var
(
modell
.
pumps
)
#constraints
#constraints
def
PumpPower
(
modell
):
def
PumpPower
(
modell
):
return
sum
(
np
.
dot
(
np
.
array
([
modell
.
Q
[
i
]
**
3
,(
modell
.
Q
[
i
]
**
2
)
*
modell
.
n
[
i
],
modell
.
Q
[
i
]
*
modell
.
n
[
i
]
**
2
,
modell
.
n
[
i
]
**
3
]),
LR_P
.
coef_
)
for
i
in
modell
.
pumps
)
return
sum
(
np
.
dot
(
np
.
array
([
modell
.
Q
[
i
]
**
3
,(
modell
.
Q
[
i
]
**
2
)
*
modell
.
n
[
i
],
modell
.
Q
[
i
]
*
modell
.
n
[
i
]
**
2
,
modell
.
n
[
i
]
**
3
]),
LR_P
.
coef_
)
for
i
in
modell
.
pumps
)
modell
.
Power_Constraint
=
pyo
.
Objective
(
rule
=
PumpPower
,
sense
=
min
)
modell
.
Power_Constraint
=
pyo
.
Objective
(
rule
=
PumpPower
,
sense
=
min
)
def
continuityRule
(
modell
,
node
):
def
continuityRule
(
modell
,
node
):
return
sum
(
modell
.
Q
[
i
]
for
i
in
graph
.
predecessors
(
node
))
==
sum
(
modell
.
Q
[
i
]
for
i
in
graph
.
successors
(
node
))
return
sum
(
modell
.
Q
[
i
]
for
i
in
graph
.
predecessors
(
node
))
==
sum
(
modell
.
Q
[
i
]
for
i
in
graph
.
successors
(
node
))
modell
.
pump_constraint
=
pyo
.
Objective
(
modell
.
nodes
,
rule
=
continuityRule
)
modell
.
pump_constraint
=
pyo
.
Objective
(
modell
.
nodes
,
rule
=
continuityRule
)
TestData
=
{
None
:{
'
G
'
:{
None
:
graph
},
'
LR
'
:{
None
:
LR_H
}}}
TestData
=
{
None
:{
'
G
'
:{
None
:
graph
},
'
LR
'
:{
None
:
LR_H
}}}
#[node for node in graph.nodes if 'pump' in node]
#Optimierungsgleichung
#Optimierungsgleichung
#instance=modell.create_instance(graph,LR_H)
#instance=modell.create_instance(graph,LR_H)
#instance.obj = pyo.Objective(expr=sum(PumpPower(modell.Q[i],modell.n[i],LR_P) for i in modell.pumps),sense=min)
#instance.obj = pyo.Objective(expr=sum(PumpPower(modell.Q[i],modell.n[i],LR_P) for i in modell.pumps),sense=min)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Frage: gibt es nur eine Lösung für Drehzahl?
Frage: gibt es nur eine Lösung für Drehzahl?
Bsp. Optimierung nach Dezentraler Pumpe um modell zu prüfen
Bsp. Optimierung nach Dezentraler Pumpe um modell zu prüfen
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment