switch_model/utilities/__init__.py
def post_solve(instance, outputs_dir=None):
    """
    Call post-solve function (if present) in all modules used to compose this model.
    This function can be used to report or save results from the solved model.
    """
    if outputs_dir is None:
        outputs_dir = getattr(instance.options, "outputs_dir", "outputs")
    if not os.path.exists(outputs_dir):
        os.makedirs(outputs_dir)

    # TODO: implement a check to call post solve functions only if
    # solver termination condition is not 'infeasible' or 'unknown'
    # (the latter may occur when there are problems with licenses, etc)

    for module in instance.get_modules():
        if hasattr(module, 'post_solve'):
            # Try-catch is so that if one module fails on post-solve
            # the other modules still run
            try:
                module.post_solve(instance, outputs_dir)
            except Exception:
                # Print the error that would normally be thrown with the
                # full stack trace and an explanatory message
                print(f"ERROR: Module {module.__name__} threw an Exception while running post_solve(). "
                      f"Moving on to the next module.\n{traceback.format_exc()}")

    Call post-solve function (if present) in all modules used to compose this model.
    This function can be used to report or save results from the solved model.
    
Call post-solve function (if present) in all modules used to compose this model.
This function can be used to report or save results from the solved model.
Call post - solve function ( if present ) in all modules used to compose this model . This function can be used to report or save results from the solved model .
def post_solve(instance, outputs_dir=None):
    if outputs_dir is None:
        outputs_dir = getattr(instance.options, "outputs_dir", "outputs")
    if not os.path.exists(outputs_dir):
        os.makedirs(outputs_dir)
    for module in instance.get_modules():
        if hasattr(module, 'post_solve'):
            try:
                module.post_solve(instance, outputs_dir)
            except Exception:
                print(f"ERROR: Module {module.__name__} threw an Exception while running post_solve(). "
                      f"Moving on to the next module.\n{traceback.format_exc()}")
def post_solve ( instance , outputs_dir = None ) : if outputs_dir is None : outputs_dir = getattr ( instance . options , "outputs_dir" , "outputs" ) if not os . path . exists ( outputs_dir ) : os . makedirs ( outputs_dir ) for module in instance . get_modules ( ) : if hasattr ( module , 'post_solve' ) : try : module . post_solve ( instance , outputs_dir ) except Exception : print ( f"ERROR: Module {module.__name__} threw an Exception while running post_solve(). " f"Moving on to the next module.\n{traceback.format_exc()}" )
Call post-solve function (if present) in all modules used to compose this model.
Call post - solve function ( if present ) in all modules used to compose this model .
"""
    Call post-solve function (if present) in all modules used to compose this model.
    This function can be used to report or save results from the solved model.
    """ # TODO: implement a check to call post solve functions only if # solver termination condition is not 'infeasible' or 'unknown' # (the latter may occur when there are problems with licenses, etc) # Try-catch is so that if one module fails on post-solve # the other modules still run # Print the error that would normally be thrown with the # full stack trace and an explanatory message
instance
outputs_dir