Binary Dictionary Comprehension

I'm trying to follow the description in "Ocean Programs for Beginners", 2.2 "Building a Quadratic Model"

The document shows this dictionary comprehension:

x = {n: Binary(n) for n in G.nodes}

However, the doc doesn't show how the G.Nodes is constructed.

After a lot of poking around I eventually discovered the way to build G.nodes appears to be:

import networkx as nx
import dimod

G = nx.Graph()
G.add_node("1")
G.add_node("2")
G.add_node("3")
G.add_node("4")
G.add_node("5")

G.add_edge("2", "1")
G.add_edge("3", "1")
G.add_edge("4", "2")
G.add_edge("4", "3")
G.add_edge("5", "3")
G.add_edge("5", "4")

Then the doc shows:

x = {n: Binary(n) for n in G.nodes}

I can't find the function Binary() in any of the Ocean documentation.

Perhaps the function has been changed since the document was written and the document is out-of-date?

Thanks for any help.

Ed
 



0

Comments

1 comment
  • Hi Ed,

    Thanks for using D-Wave Systems. 

    The expressiong "x = {n: Binary(n) for n in G.nodes}" is not a line of code, but an expression that creates a dictionary of symbolic binary variables for a mathematical optimization problem. The G.nodes set contains the mathematical variables in the problem, and for each variable n, a corresponding symbolic binary variable is created using the Binary(n) function. Symbolic binary variables are variables that take on either the value 0 or 1, and are commonly used to represent discrete choices or decisions in optimization problems. The creation of these symbolic binary variables is necessary for representing the optimization problem in a form that can be solved by a quantum computer.

    To get a better understanding on how to create and add symbolic binary variables for mathematical optimization problems, you can refer to the following articles:

    Best Regards,
    Tanjid

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post