I have a simple graph with few nodes and these nodes have attributes such as "type" and "demand".
def mygraph():
G = nx.Graph()
G.add_nodes_from([("N1", {"type":"parent","demand": 10}),
("N2"{"type":"parent","demand": 12}),
("N3", {"type":"parent","demand": 25}),
("S1", {"type":"server","demand": 12}),
("S2,{"type":"server","demand": 20})])
I am passing this graph to another function in pyomo library. The dummy pyomo function is as follows:
def mymodel():
g=mygraph()
**VARIABLES**
model.const1 = Constraint(my constraint1)
model.const2 = Constraint(my constraint2)
model.obj1 = Objective(my objective)
status = SolverFactory('glpk')
results = status.solve(model)
assert_optimal_termination(results)
model.display()
mymodel()
I am trying to:
In graph function mygraph():, I need to find the total number of nodes in the graph G with attribute type==parent.
In pyomo function mymodel():, I need to create the number new of VARIABLES equal to the number of nodes with attribute type==parent. So in the case above, my program must create 3 new variables, since 3 nodes have attribute type==parent in my graph function. The values of these newly created variables will be accessed from the demand attribute of the same node thus, it should be something like this;
new_var1=demand of node1 (i.e., node1_demand=10 in this case)
new_var2=demand of node2 (i.e., node2_demand=12)
new_var3=demand of node3 (i.e., node2_demand=25)