'Replaces the given variables in the object.
Parameters
obj : Object
The object to replace variables in.
id_to_new_var : dict
A map of id to new variable.
Returns
Object
An object identical to obj, but with the given variables replaced.'

@staticmethod
def _replace_new_vars(obj, id_to_new_var):

    if (isinstance(obj, Variable) and (obj.id in id_to_new_var)):
        return id_to_new_var[obj.id]
    elif (len(obj.args) == 0):
        return obj
    elif isinstance(obj, PartialProblem):
        prob = obj.args[0]
        new_obj = PartialProblem._replace_new_vars(prob.objective, id_to_new_var)
        new_constr = []
        for constr in prob.constraints:
            new_constr.append(PartialProblem._replace_new_vars(constr, id_to_new_var))
        new_args = [Problem(new_obj, new_constr)]
        return obj.copy(new_args)
    else:
        new_args = []
        for arg in obj.args:
            new_args.append(PartialProblem._replace_new_vars(arg, id_to_new_var))
        return obj.copy(new_args)
