Solving a concrete model example

718 views
Skip to first unread message

omowunmiayo

unread,
Apr 16, 2018, 11:34:54 AM4/16/18
to Pyomo Forum
Please I need help with running the attached pyomo file. I am new to using pyomo. I tried using it to run  a simple Electricity Transmission expansion problem using the concrete model and got the following errors which I am not sure of how to solve.

ERROR: Constructing component 'f' from data=None failed:
        KeyError: "Error accessing indexed component: Index '0' is not valid for array component 'li_f_inv'"

Please what do you think needs corrections?

Thank you
Transmission Investment planning problem.py

Watson, Jean-Paul

unread,
Apr 16, 2018, 11:43:28 AM4/16/18
to pyomo...@googlegroups.com

The issue is that the variable “li_f_invz” is indexed by both model.E and model.LI. So at a minimum, you need to supply a tuple when indexing elements of li_f_inv.

 

jpw

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
pyomo-forum...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

omowunmiayo

unread,
Apr 16, 2018, 12:26:41 PM4/16/18
to Pyomo Forum
Hi JPW,

Thanks for your prompt response. I think that was what I specified (within the bounds) as in:

def fl_inv(model, i, l):
    return (0, model.li_max_f)
model.li_f_inv = Var(model.E, model.LI, bounds = fl_inv)


where model_li_max_f was specified earlier in the code.

or can you give me an example please?

Thank you.

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Watson, Jean-Paul

unread,
Apr 16, 2018, 12:33:43 PM4/16/18
to pyomo...@googlegroups.com

Your issue has nothing to do with li_max_f, to be clear.

 

At least one issue comes into play when you define fl_rule. Here, you are indexing the variable li_f_inv by the index “l”. But “l” is an element of the set model.E. And you need to index li_f_inv with a tuple, e.g., li_f_inv[j,l].  

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--

You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

omowunmiayo

unread,
Apr 16, 2018, 12:59:55 PM4/16/18
to Pyomo Forum
Thank you. I tried what you suggested and it replaced with tuples where necessary. as in:

def fl_rule(model, j, l):
    total_f = (model.li_f_inv[j, l] + model.li_f[l])
    return (- total_f[j], total_f[j])
model.f = Var(model.LI, model.E, initialize = 0, bounds = fl_rule)

I also corrected it in the objective function. I got the following error message:

ERROR: Constructing component 'f' from data=None failed:
        KeyError: "Error accessing indexed component: Index '('L3', 0)' is not valid for array component 'li_f_inv'"

could it be in assigning the string values to set.LI?

Looking forward to your response. Apologies for the stress.

Thank you

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Watson, Jean-Paul

unread,
Apr 16, 2018, 6:03:31 PM4/16/18
to pyomo...@googlegroups.com

You can add a line after constructing a component, e.g., as follows:

 

print(list(iterkeys(model.li_f_inv)))

 

You’ll see that the valid indices for li_f_inv are: [(0, 'L2'), (0, 'L1'), (0, 'L3'), (1, 'L2'), (1, 'L1'), (1, 'L3'), (2, 'L2'), (2, 'L1'), (2, 'L3'), (3, 'L2'), (3, 'L1'), (3, 'L3')]

 

In this case, you have an ordering issue between model.LI and model.E.

 

The above fragment will help diagnose model index issues in general.

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

omowunmiayo

unread,
Apr 17, 2018, 5:01:56 AM4/17/18
to Pyomo Forum
Dear JPW,

Thanks for your response. I tried that but didn't get the indices. instead got the error:

NameError: name 'iterkeys' is not defined

Not sure what to do next. Thanks

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Watson, Jean-Paul

unread,
Apr 17, 2018, 1:48:20 PM4/17/18
to pyomo...@googlegroups.com

I was using Python 3.X – you’ll need to Google the equivalent for Python 2.7.

omowunmiayo

unread,
Apr 18, 2018, 12:32:29 PM4/18/18
to Pyomo Forum
Dear JPW,

Thank you for your last response. I was able to get around that problem. But moving ahead I got the following error messages when I tried running the updated codes attached.

ERROR: Rule failed when generating expression for constraint line_equation with index ('L2', 0):
        TypeError: Cannot convert object of type 'generator' (value = <generator object line_equation.<locals>.<genexpr> at 0x000001B6F840E360>) to a numeric value.
ERROR: Constructing component 'line_equation' from data=None failed:
        TypeError: Cannot convert object of type 'generator' (value = <generator object line_equation.<locals>.<genexpr> at 0x000001B6F840E360>) to a numeric value.

what do you suggest might be a good solution please? Looking forward to your response. Thanks for your help so far.

Kind Regards

Olayinka Ayo

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Transmission Investment planning problem.py

omowunmiayo

unread,
Apr 19, 2018, 11:27:33 AM4/19/18
to Pyomo Forum
Hi JPW,

I am having an Index error message on the following attached concrete model. I am unable to trace the error. Please can you help?

The error message is as follows:

ERROR: Rule failed when generating expression for constraint SystemBalance with index (0, 'N3'):
        IndexError: invalid index
ERROR: Constructing component 'SystemBalance' from data=None failed:
        IndexError: invalid index

Looking forward to your response. Thank you
Transmission Investment planning problem.py

Jiberu Ba

unread,
Jul 26, 2022, 4:50:23 AM7/26/22
to Pyomo Forum
Dear JPW and Watson

Thank you very much for this helpful information about transmission expansion planning. 
I need your support because I new using Pyomo for transmission expansion planning problem. Can you share with some optimization of TEP model? 
Best wishes
Jiberu

Jean-Paul Watson

unread,
Jul 27, 2022, 8:47:05 AM7/27/22
to pyomo...@googlegroups.com
Hi Jiberu,

We unfortunately don't have any publicly available TEP models in Pyomo.

Jean-Paul

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages