Error retrieving component on[unknown,0]: The component has not been constructed.

523 views
Skip to first unread message

Yufei Su

unread,
Jun 14, 2017, 9:03:29 AM6/14/17
to Pyomo Forum
Hi All:

I am new to pyomo so this may be a silly question to ask. I am trying to build a 4-zone UC/ED model with many generators in each zone. So I set the model up in the following way:

model.Zone1Generators = Set()

model.Zone2Generators = Set()


model.Zone3Generators = Set()


model.Zone4Generators = Set()

   
model.Generators = model.Zone1Generators | model.Zone2Generators | model.Zone3Generators | model.Zone4Generators

When I run the model, I got the following error message:
ERROR: Rule failed when generating expression for constraint IC0Constraint:
ValueError: Error retrieving component on[unknown,0]: The component has not been constructed.

The constraint corresponding to the error is one of my initial condition constrain and looks like this:
def initial_status(Generators): 
    return model.on[Generators,0] == model.ini_on[Generators]
model.IC0Constraint = Constraint(rule=initial_status)

I have been struggling with this for days. Any help would be very appreciated.

Yufei

Siirola, John D

unread,
Jun 14, 2017, 10:41:25 AM6/14/17
to pyomo...@googlegroups.com

You are creating a scalar constraint where you mean to create an indexed constraint.  The first argument to all rules is the block that owns the component (in this case, the model).

 

Please see the documentation for more information: https://software.sandia.gov/downloads/pub/pyomo/PyomoOnlineDocs.html#_constraints

 

john

--
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.

Yufei Su

unread,
Jun 14, 2017, 12:54:16 PM6/14/17
to Pyomo Forum
John,thank you so much for your reply. I changed the constraint to the following:
def initial_status(model,j): 
    return model.on[j,0] == model.ini_on[j]
model.IC0Constraint = Constraint(rule=initial_status)

and
def initial_status(model,Generators): 
    return model.on[Generators,0] == model.ini_on[Generators]
model.IC0Constraint = Constraint(rule=initial_status)

Both give me a new error message :
ERROR: Rule failed when generating expression for constraint IC0Constraint:
TypeError: initial_status() takes exactly 2 arguments (1 given)

if I just do this:
def initial_status(model): 
    return model.on[j,0] == model.ini_on[j]
model.IC0Constraint = Constraint(rule=initial_status)

it returns error: ERROR: Rule failed when generating expression for constraint IC0Constraint:
NameError: global name 'j' is not defined

I am a little confused about this. Is my way of setting this constraint wrong?

Siirola, John D

unread,
Jun 14, 2017, 2:32:53 PM6/14/17
to pyomo...@googlegroups.com

You are only changing your rule but still declaring a scalar constraint.  You also need to declare an indexed constraint (by passing the index as an argument to the constraint constructor).  Please look at the numerous examples or the documentation linked below for examples of using indexed constraints.

Yufei Su

unread,
Jun 14, 2017, 4:34:49 PM6/14/17
to Pyomo Forum
Got it! Thank you so much!
Reply all
Reply to author
Forward
0 new messages