switch_model/solve.py
def warm_start_mip(instance):
    """
    This function loads the results from a previous run into the Pyomo variables.
    This allows Gurobi's Mixed Integer Programming algorithm to "warm start" (start closer to the solution).
    Warm starting only works in Gurobi if the initial values don't violate any constraints
    (i.e. valid but not optimal solution).
    """
    warm_start_dir = os.path.join(instance.options.warm_start_mip, "outputs")
    if not os.path.isdir(warm_start_dir):
        warnings.warn(
            f"Path {warm_start_dir} does not exist and cannot be used to warm start solver. Warm start skipped.")
        return

    # Loop through every variable in our model
    for variable in instance.component_objects(Var):
        scaled = isinstance(variable, _ScaledVariable)
        varname = variable.unscaled_name if scaled else variable.name
        scaling = variable.scaling_factor if scaled else 1

        filepath = os.path.join(warm_start_dir, varname + ".csv")
        if not os.path.exists(filepath):
            warnings.warn(f"Skipping warm start for set {varname} since {filepath} does not exist.")
            continue
        df = pd.read_csv(filepath, index_col=list(range(variable._index.dimen)))
        for index, val in df.iterrows():
            try:
                variable[index] = val[0] * scaling
            except (KeyError, ValueError):
                # If the index isn't valid that's ok, just don't warm start that variable
                pass

    This function loads the results from a previous run into the Pyomo variables.
    This allows Gurobi's Mixed Integer Programming algorithm to "warm start" (start closer to the solution).
    Warm starting only works in Gurobi if the initial values don't violate any constraints
    (i.e. valid but not optimal solution).
    
This function loads the results from a previous run into the Pyomo variables.
This allows Gurobi's Mixed Integer Programming algorithm to "warm start" (start closer to the solution).
Warm starting only works in Gurobi if the initial values don't violate any constraints
.
This function loads the results from a previous run into the Pyomo variables . This allows Gurobi ' s Mixed Integer Programming algorithm to " warm start " ( start closer to the solution ) . Warm starting only works in Gurobi if the initial values don ' t violate any constraints .
def warm_start_mip(instance):
    warm_start_dir = os.path.join(instance.options.warm_start_mip, "outputs")
    if not os.path.isdir(warm_start_dir):
        warnings.warn(
            f"Path {warm_start_dir} does not exist and cannot be used to warm start solver. Warm start skipped.")
        return
    for variable in instance.component_objects(Var):
        scaled = isinstance(variable, _ScaledVariable)
        varname = variable.unscaled_name if scaled else variable.name
        scaling = variable.scaling_factor if scaled else 1
        filepath = os.path.join(warm_start_dir, varname + ".csv")
        if not os.path.exists(filepath):
            warnings.warn(f"Skipping warm start for set {varname} since {filepath} does not exist.")
            continue
        df = pd.read_csv(filepath, index_col=list(range(variable._index.dimen)))
        for index, val in df.iterrows():
            try:
                variable[index] = val[0] * scaling
            except (KeyError, ValueError):
                pass
def warm_start_mip ( instance ) : warm_start_dir = os . path . join ( instance . options . warm_start_mip , "outputs" ) if not os . path . isdir ( warm_start_dir ) : warnings . warn ( f"Path {warm_start_dir} does not exist and cannot be used to warm start solver. Warm start skipped." ) return for variable in instance . component_objects ( Var ) : scaled = isinstance ( variable , _ScaledVariable ) varname = variable . unscaled_name if scaled else variable . name scaling = variable . scaling_factor if scaled else 1 filepath = os . path . join ( warm_start_dir , varname + ".csv" ) if not os . path . exists ( filepath ) : warnings . warn ( f"Skipping warm start for set {varname} since {filepath} does not exist." ) continue df = pd . read_csv ( filepath , index_col = list ( range ( variable . _index . dimen ) ) ) for index , val in df . iterrows ( ) : try : variable [ index ] = val [ 0 ] * scaling except ( KeyError , ValueError ) : pass
This function loads the results from a previous run into the Pyomo variables.
This function loads the results from a previous run into the Pyomo variables .
"""
    This function loads the results from a previous run into the Pyomo variables.
    This allows Gurobi's Mixed Integer Programming algorithm to "warm start" (start closer to the solution).
    Warm starting only works in Gurobi if the initial values don't violate any constraints
    (i.e. valid but not optimal solution).
    """ # Loop through every variable in our model # If the index isn't valid that's ok, just don't warm start that variable
instance