Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
topupopt
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
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pmag
topupopt
Compare revisions
661a604b8f8446073f58c4f356cd1a8e60c01787 to 09cef5249fb12f915f75bde0b40c6085adeae2c6
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
pmag/topupopt
Select target project
No results found
09cef5249fb12f915f75bde0b40c6085adeae2c6
Select Git revision
Branches
master
Swap
Target
pmag/topupopt
Select target project
pmag/topupopt
1 result
661a604b8f8446073f58c4f356cd1a8e60c01787
Select Git revision
Branches
master
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
Fixed bug concerning the identification of nodes.
· 52c13800
Pedro L. Magalhães
authored
7 months ago
52c13800
Revised the method to reset node types.
· 09cef524
Pedro L. Magalhães
authored
7 months ago
09cef524
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/topupopt/problems/esipp/network.py
+9
-4
9 additions, 4 deletions
src/topupopt/problems/esipp/network.py
tests/test_dhn_utils.py
+0
-1
0 additions, 1 deletion
tests/test_dhn_utils.py
tests/test_esipp_network.py
+91
-0
91 additions, 0 deletions
tests/test_esipp_network.py
with
100 additions
and
5 deletions
src/topupopt/problems/esipp/network.py
View file @
09cef524
...
...
@@ -752,9 +752,12 @@ class Network(nx.MultiDiGraph):
elif
self
.
is_source_sink_node
(
node_key
):
# source/sink node
self
.
source_sink_nodes
.
remove
(
node_key
)
el
se
:
#
self.is_waypoint_node(node_key):
el
if
self
.
is_waypoint_node
(
node_key
):
# has to be a waypoint node
self
.
waypoint_nodes
.
remove
(
node_key
)
# No need to reset node but this could mean something is up
# else:
# raise ValueError('Unknown node type.')
# *************************************************************************
# *************************************************************************
...
...
@@ -866,13 +869,15 @@ class Network(nx.MultiDiGraph):
# change to an import node: it cannot have incoming arcs
for
_edge
in
_edges
:
if
_edge
[
1
]
==
node_key
:
#
outgo
ing arc, raise error
#
incom
ing arc, raise error
raise
ValueError
(
'
A node with
outgo
ing arcs cannot be an
'
'
ex
port node.
'
'
A node with
incom
ing arcs cannot be an
'
'
im
port node.
'
)
# else:
# raise ValueError('Unknown option.')
# everything seems to be okay: reset node data
self
.
_reset_node_type
(
node_key
)
else
:
# no data: waypoint node, clear node data
self
.
_reset_node_type
(
node_key
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_dhn_utils.py
View file @
09cef524
...
...
@@ -20,7 +20,6 @@ from topupheat.common.fluids import FluidDatabase # , Fluid
# *****************************************************************************
# *****************************************************************************
class
TestDistrictHeatingNetworkUtils
:
# *************************************************************************
# *************************************************************************
...
...
This diff is collapsed.
Click to expand it.
tests/test_esipp_network.py
View file @
09cef524
# imports
# standard
import
pytest
import
random
from
networkx
import
binomial_tree
,
MultiDiGraph
...
...
@@ -2321,6 +2322,96 @@ class TestNetwork:
# *************************************************************************
# *************************************************************************
def
test_add_nodes
(
self
):
# create network
net
=
Network
()
# add nodes
node_a
=
'
A
'
net
.
add_node
(
node_a
)
assert
net
.
is_waypoint_node
(
node_a
)
# source
node_b
=
'
B
'
net
.
add_node
(
node_b
,
**
{
net
.
KEY_NODE_BASE_FLOW
:
{(
0
,
0
):
-
1
}})
assert
net
.
is_source_sink_node
(
node_b
)
# sink
node_c
=
'
C
'
net
.
add_node
(
node_c
,
**
{
net
.
KEY_NODE_BASE_FLOW
:
{(
0
,
0
):
1
}})
assert
net
.
is_source_sink_node
(
node_c
)
# import node
node_d
=
'
D
'
net
.
add_node
(
node_d
,
**
{
net
.
KEY_NODE_PRICES
:
{(
0
,
0
):
ResourcePrice
(
prices
=
[
1
,
2
],
volumes
=
[
1
,
None
])},
net
.
KEY_NODE_TYPE
:
net
.
KEY_NODE_TYPE_IMP
})
assert
net
.
is_import_node
(
node_d
)
# export node
node_e
=
'
E
'
net
.
add_node
(
node_e
,
**
{
net
.
KEY_NODE_PRICES
:
{(
0
,
0
):
ResourcePrice
(
prices
=
[
2
,
3
],
volumes
=
[
4
,
None
])},
net
.
KEY_NODE_TYPE
:
net
.
KEY_NODE_TYPE_EXP
})
assert
net
.
is_export_node
(
node_e
)
# modify nodes
# from waypoint to source/sink
net
.
modify_node
(
node_a
,
**
{
net
.
KEY_NODE_BASE_FLOW
:
{(
0
,
0
):
-
2
}})
assert
not
net
.
is_waypoint_node
(
node_a
)
assert
net
.
is_source_sink_node
(
node_a
)
# from source/sink to waypoint
net
.
modify_node
(
node_a
)
assert
not
net
.
is_source_sink_node
(
node_a
)
assert
net
.
is_waypoint_node
(
node_a
)
# from waypoint to import node
net
.
modify_node
(
node_a
,
**
{
net
.
KEY_NODE_PRICES
:
{(
0
,
0
):
ResourcePrice
(
prices
=
[
5
,
3.5
],
volumes
=
[
2
,
4
])},
net
.
KEY_NODE_TYPE
:
net
.
KEY_NODE_TYPE_IMP
})
assert
not
net
.
is_waypoint_node
(
node_a
)
assert
net
.
is_import_node
(
node_a
)
# from import node to waypoint
net
.
modify_node
(
node_a
)
assert
not
net
.
is_import_node
(
node_a
)
assert
net
.
is_waypoint_node
(
node_a
)
# from waypoint node to export node
net
.
modify_node
(
node_a
,
**
{
net
.
KEY_NODE_PRICES
:
{(
0
,
0
):
ResourcePrice
(
prices
=
[
4
,
1
],
volumes
=
[
3
,
6
])},
net
.
KEY_NODE_TYPE
:
net
.
KEY_NODE_TYPE_EXP
})
assert
not
net
.
is_waypoint_node
(
node_a
)
assert
net
.
is_export_node
(
node_a
)
# from export node to sink/source
net
.
modify_node
(
node_a
,
**
{
net
.
KEY_NODE_BASE_FLOW
:
{(
0
,
0
):
-
1
}})
assert
not
net
.
is_export_node
(
node_a
)
assert
net
.
is_source_sink_node
(
node_a
)
# from sink/source node to import node
net
.
modify_node
(
node_a
,
**
{
net
.
KEY_NODE_PRICES
:
{(
0
,
0
):
ResourcePrice
(
prices
=
[
5
,
3.5
],
volumes
=
[
2
,
4
])},
net
.
KEY_NODE_TYPE
:
net
.
KEY_NODE_TYPE_IMP
})
assert
not
net
.
is_source_sink_node
(
node_a
)
assert
net
.
is_import_node
(
node_a
)
# from import node to export node
net
.
modify_node
(
node_a
,
**
{
net
.
KEY_NODE_PRICES
:
{(
0
,
0
):
ResourcePrice
(
prices
=
[
4
,
1
],
volumes
=
[
3
,
6
])},
net
.
KEY_NODE_TYPE
:
net
.
KEY_NODE_TYPE_EXP
})
assert
not
net
.
is_import_node
(
node_a
)
assert
net
.
is_export_node
(
node_a
)
# from export node to waypoint node
net
.
modify_node
(
node_a
)
assert
not
net
.
is_export_node
(
node_a
)
assert
net
.
is_waypoint_node
(
node_a
)
# *********************************************************************
# test modifying nodes with preexisting arcs
# add arcs
# add arc between two waypoint nodes
net
.
add_preexisting_directed_arc
(
node_key_a
=
node_a
,
node_key_b
=
node_b
,
efficiency
=
None
,
static_loss
=
None
,
capacity
=
3
,
capacity_is_instantaneous
=
False
)
# modify nodes
# try to change the start node to an export node
with
pytest
.
raises
(
ValueError
):
net
.
modify_node
(
node_a
,
**
{
net
.
KEY_NODE_PRICES
:
{(
0
,
0
):
ResourcePrice
(
prices
=
[
4
,
1
],
volumes
=
[
3
,
6
])},
net
.
KEY_NODE_TYPE
:
net
.
KEY_NODE_TYPE_EXP
})
# try to change the end node to an import node
with
pytest
.
raises
(
ValueError
):
net
.
modify_node
(
node_b
,
**
{
net
.
KEY_NODE_PRICES
:
{(
0
,
0
):
ResourcePrice
(
prices
=
[
4
,
1
],
volumes
=
[
3
,
6
])},
net
.
KEY_NODE_TYPE
:
net
.
KEY_NODE_TYPE_IMP
})
# *************************************************************************
# *************************************************************************
# *****************************************************************************
# *****************************************************************************
This diff is collapsed.
Click to expand it.