0

I am solving an MINLP using Pyomo, which takes a vector of integer inputs(the link capacities of a graph) and returns the packet loss in the network.What the edge_enum dictionary does is, it enumerates all edges of the graph.e.g.,

{0: (0, 4), 
1: (1, 4), 
2: (1, 5), ...
a=0
for e in G.edges():
    edge_enum[a]=e  
    a+=1

model=ConcreteModel
key_list=list(edge_enum.keys())
edge_list=list(edge_enum.values())
model.A=Set(initialize=edge_list)
lb={}
for j in edge_list:
    lb[j]=pmf_maxima(j,lamd,q)
ub={}
for j in edge_list:
    ub[j]=pmf_length(j,lamd,q)
def fb(model,i):
    return (lb[i],ub[i])
model.vars=Var(model.A,domain=PositiveIntegers,bounds=fb)
print(model.vars[edge_enum[0]].value)

My query is ,how can I access each element of the variable vector 'vars' ,because thats my input capacity vector. I need to access each of them to define my objective function.

1
  • Can someone please help me out ASAP? I need to define this Integer Programming model and need to see whether it actually works with Pyomo,or else I need to try something else. Commented Mar 25, 2020 at 17:49

1 Answer 1

0

There is a lot of stuff I don't understand in your code as it is just a section of it you copied here, but from what I seem to see, you are trying to print the value of 'vars' for element with index value '0'. However, 'vars' is a variable to be determined AFTER you solve the model, so does not have a value yet. It just has lower and upper bounds which you defined by 'lb' and 'ub'. So, solve the model first before printing out the values.

However, if you just want to use the value of 'vars' in the objective function, just write out the equation with 'vars' in there. When the model is being solved, pyomo and the selected solver will handle that.

Does that help?

Sign up to request clarification or add additional context in comments.

2 Comments

My objective function is a summation of a function of v for all v in model.vars. So, to define my objective function , I will need to add up each f(model.vars[i]) for i in model.A . How to do that?
You just do it that way: model.objective = Objective(expr=sum(model.vars[i] for i in model.A, sense='minimise'/'maximise', doc='')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.