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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pmag
topupopt
Commits
52c13800
Commit
52c13800
authored
11 months ago
by
Pedro L. Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
Fixed bug concerning the identification of nodes.
parent
661a604b
Branches
Branches containing commit
No related tags found
1 merge request
!7
Added support for convex price functions using the delta formulation and...
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/topupopt/problems/esipp/network.py
+5
-3
5 additions, 3 deletions
src/topupopt/problems/esipp/network.py
tests/test_esipp_network.py
+91
-0
91 additions, 0 deletions
tests/test_esipp_network.py
with
96 additions
and
3 deletions
src/topupopt/problems/esipp/network.py
+
5
−
3
View file @
52c13800
...
...
@@ -866,13 +866,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_esipp_network.py
+
91
−
0
View file @
52c13800
# imports
# standard
import
pytest
import
random
from
networkx
import
binomial_tree
,
MultiDiGraph
...
...
@@ -2322,5 +2323,95 @@ 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.
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