From 16f21d29d26b74a349bc9fee43dcc3128013be22 Mon Sep 17 00:00:00 2001 From: "Joseph T. Iosue" Date: Wed, 31 Aug 2022 16:13:11 -0400 Subject: [PATCH] v1.2.5 (#42) * incremented version * Update test_subgraph.py * Update _subgraph.py * Update test_subgraph.py * Update README.rst * Update requirements-dev.txt --- README.rst | 2 +- qubovert/_version.py | 2 +- qubovert/utils/_subgraph.py | 4 ++++ tests/utils/test_subgraph.py | 8 ++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 9851651..b3ac79d 100644 --- a/README.rst +++ b/README.rst @@ -96,7 +96,7 @@ Create the boolean objective function to minimize # create the variables x = {i: boolean_var('x(%d)' % i) for i in range(N)} - # minimize \sum_{i=0}^{N-1} (1-2x_{i}) x_{i+1} + # minimize \sum_{i=0}^{N-2} (1-2x_{i}) x_{i+1} model = 0 for i in range(N-1): model += (1 - 2 * x[i]) * x[i+1] diff --git a/qubovert/_version.py b/qubovert/_version.py index a3ba853..72910b1 100644 --- a/qubovert/_version.py +++ b/qubovert/_version.py @@ -20,7 +20,7 @@ ) -__version__ = "1.2.4" +__version__ = "1.2.5" __author__ = "Joseph T. Iosue" __authoremail__ = "jtiosue@gmail.com" __license__ = "Apache Software License 2.0" diff --git a/qubovert/utils/_subgraph.py b/qubovert/utils/_subgraph.py index 4444923..e6040c6 100644 --- a/qubovert/utils/_subgraph.py +++ b/qubovert/utils/_subgraph.py @@ -90,6 +90,8 @@ def subgraph(G, nodes, connections=None): value += D.get(key, 0) if value: D[key] = value + else: + D.pop(key, 0) return D @@ -134,5 +136,7 @@ def subvalue(values, G): value += D.get(key, 0) if value: D[key] = value + else: + D.pop(key, 0) return D diff --git a/tests/utils/test_subgraph.py b/tests/utils/test_subgraph.py index 0d018f5..0c38dbc 100644 --- a/tests/utils/test_subgraph.py +++ b/tests/utils/test_subgraph.py @@ -44,6 +44,10 @@ def test_subgraph(): with assert_raises(ValueError): subgraph({0: 1, (0, 1): 1}, {}) + # from Issue #38 in GitHub + G = {(2,): 1, (2, 3): -1} + assert subgraph(G, {2}, {3: 1}) == {} + def test_subvalue(): @@ -65,3 +69,7 @@ def test_subvalue(): # edge case assert subvalue({}, G) == G assert subvalue({0: 0, 1: 0, 2: 0}, G) == {(): 2} + + # from Issue #38 in GitHub + G = {(2,): 1, (2, 3): -1} + assert subvalue({3: 1}, G) == {}