deactivating objective without knowing its name

19 views
Skip to first unread message

Marek Makowski

unread,
Sep 8, 2023, 4:25:16 AM9/8/23
to Pyomo Forum
I've found how to deactivating model objective (I need this use the model as a block with another model defining the objective) without knowing its name:

for component_name, component in m1.component_map().items():
    c_type = str(type(component))
    if str(type(component)) == "<class   'pyomo.core.base.objective.ScalarObjective'>":
       print(f'objective name: "{component_name}" deactivated.')
component.deactivate()

However, the above looks rather ugly. Maybe someone know alternative ways to do this?

Thanks,
Marek

Siirola, John

unread,
Sep 8, 2023, 8:58:10 AM9/8/23
to pyomo...@googlegroups.com

The easiest way is:

 

import pyomo.environ as pyo

 

for obj in m1.component_data_objects(pyo.Objective):

    print(f'objective name: "{obj}" deactivated.')

    obj.deactivate()

 

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/15514c1d-9997-496a-b291-b39e31cff5d6n%40googlegroups.com.

Marek Makowski

unread,
Sep 8, 2023, 9:08:16 AM9/8/23
to Pyomo Forum
Many thanks, John.
I wonder where I could find this (and similar) tip in the Pyomo doc?
Cheers,
Marek

Reply all
Reply to author
Forward
0 new messages